Page 3 of 5 FirstFirst 12345 LastLast
Results 81 to 120 of 181

Thread: Sugestions or Comments about my Sound Tutorial

  1. #81
    New Member
    Join Date
    Sep 2008
    Posts
    14

    Re: Sugestions or Comments about my Sound Tutorial

    CVMichael,

    Looked in the Tute for anything on bit-depth reduction. Of course, found the 16 bit to 8 bit converter, but was wondering whether you'd be able to advise steps to fulfil the following requirement:

    'Allow user to reduce the bit depth of the sound from the bit depth of the loaded wav file, to whatever the user sets - in steps of 1 bit, and down to 1 bit'

    Looked around for some guidance on the 'net, and found this in the write-up for 'CMT Bitcrusher - a free VST plug-in for PC':

    'You can reduce the bit-depth all the way to 1-bit if you like. The bit-reduction is done by scaling and rounding the input signal to the target bit-depth in integers and then back to floats. For example in four bits, you have to multiply the input signal by eight (2^bits-1) to floats between [-8.0, 8.0]. The actual bit-reduction (or bitcrushing) is done when the floats are rounded to integers and scaled back to [-1.0, 1.0]. This process reduces the resolution of the floats and produces audible bitcrushing-effect'.

    So, would the idea be:
    1. Scale Wavedata() to between -1 and 1
    2. Multiply each sample by 2^(UserBits-1) where UserBits < BitsPerSample of Wavedata
    3. Round each sample to Integers
    4. Scale each sample back to between -1 and 1
    5. Convert back to Bytes and load back in Wavedata()

  2. #82

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    Re: Sugestions or Comments about my Sound Tutorial

    If I understood you right, the formula is:

    New_Sample = CLng(CSng(Sample) / (2 ^ (BitsPerSample - UserBits))) * (2 ^ (BitsPerSample - UserBits))

    Therefore the functions that you need are (I did not test the functions):
    vb Code:
    1. Public Function ConvertWaveBits8(Buffer() As Byte, UserBits As Integer) As Byte()
    2.     Dim K As Long
    3.     Dim RetBuff() As Byte
    4.     Dim New_Sample As Long
    5.     Dim Divisor As Single
    6.    
    7.     ReDim RetBuff(UBound(Buffer))
    8.     Divisor = 2 ^ (8 - UserBits)
    9.    
    10.     For K = 0 To UBound(Buffer)
    11.         New_Sample = CLng(CSng(Buffer(K)) / Divisor) * Divisor
    12.        
    13.         If New_Sample < 0 Then New_Sample = 0
    14.         If New_Sample > 255 Then New_Sample = 255
    15.        
    16.         RetBuff(K) = New_Sample
    17.     Next K
    18.    
    19.     ConvertWaveBits8 = RetBuff
    20. End Function
    21.  
    22. Public Function ConvertWaveBits16(Buffer() As Integer, UserBits As Integer) As Integer()
    23.     Dim K As Long
    24.     Dim RetBuff() As Integer
    25.     Dim Sample As Long
    26.     Dim New_Sample As Long
    27.     Dim Divisor As Single
    28.    
    29.     ReDim RetBuff(UBound(Buffer))
    30.     Divisor = 2 ^ (16 - UserBits)
    31.    
    32.     For K = 0 To UBound(Buffer)
    33.         Sample = Buffer(K) + 32768
    34.        
    35.         New_Sample = CLng(CSng(Sample) / Divisor) * Divisor
    36.        
    37.         If New_Sample < 0 Then New_Sample = 0
    38.         If New_Sample > 65535 Then New_Sample = 65535
    39.        
    40.         RetBuff(K) = New_Sample - 32768
    41.     Next K
    42.    
    43.     ConvertWaveBits8 = RetBuff
    44. End Function

    The only thing is when your input is 16 bits, and you convert to 7 bits (for example), what will the output be ? 16 bit wave file or 8 bit wave file ?

  3. #83
    Fanatic Member
    Join Date
    Mar 2008
    Posts
    790

    Re: Sugestions or Comments about my Sound Tutorial

    I am still investigating this directx thing with my vista computer. I am very anxious to work on your tutorial, as I believe I could learn a lot from it.

    Can you tell me please: in your tutorial, is there a way to control fade-in and fade-out times for a wav file?

    Would be great. Thanks.

  4. #84

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    Re: Sugestions or Comments about my Sound Tutorial

    There is no built in function for that, but you can do it through coding.

    There is an example in the tutorial that shows how to change the volume of the buffer, you can modify it for fading in/out.

    [Edit]
    Also, what kind of fade do you need ?
    For example, this is a link I found on the net about the types of fading:
    http://www.xowave.com/doc/window/fade.shtml
    Linear fading is the easiest to do...
    Last edited by CVMichael; Dec 22nd, 2008 at 01:54 PM.

  5. #85
    Fanatic Member
    Join Date
    Mar 2008
    Posts
    790

    Re: Sugestions or Comments about my Sound Tutorial

    I guess linear fading would be ok.

    I would just like to control how long it would take to reach a certain volume level.

    Say 100 milliseconds to get full on volume.

  6. #86

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    Re: Sugestions or Comments about my Sound Tutorial

    To give you a head start, I wrote this function for you.

    This is for a 16 bit buffer, and you have to calculate the start sample and end sample positions in the buffer.

    For example if you want to Fade Out the last 250 milliseconds, then you do it like this

    TotalSamples = SamplesPerSecond * (250 / 1000#)
    EndSample = UBound(Buffer)
    StartSample = EndSample - TotalSamples

    WaveFade16 Buffer, StartSample, EndSample

    And if you want to Fade In:

    TotalSamples = SamplesPerSecond * (250 / 1000#)
    StartSample = 0
    EndSample = TotalSamples

    WaveFade16 Buffer, StartSample, EndSample, False

    I did not test the function ! I just wrote it...
    vb Code:
    1. Public Function WaveFade16(Buffer() As Integer, StartSample As Long, EndSample As Long, Optional FadeOut As Boolean = True) As Integer()
    2.     Dim K As Long
    3.     Dim RetBuffer() As Integer
    4.     Dim TotalSamples As Long
    5.     Dim Vol As Single
    6.    
    7.     ReDim RetBuffer(UBound(Buffer))
    8.    
    9.     For K = LBound(Buffer) To StartSample - 1
    10.         RetBuffer(K) = Buffer(K)
    11.     Next K
    12.    
    13.     TotalSamples = EndSample - StartSample
    14.    
    15.     If FadeOut Then
    16.         For K = StartSample To EndSample
    17.             Vol = 1# - (CSng(K - StartSample) / TotalSamples)
    18.            
    19.             RetBuffer(K) = Buffer(K) * Vol
    20.         Next K
    21.     Else
    22.         For K = StartSample To EndSample
    23.             Vol = CSng(K - StartSample) / TotalSamples
    24.            
    25.             RetBuffer(K) = Buffer(K) * Vol
    26.         Next K
    27.     End If
    28.    
    29.     For K = EndSample + 1 To UBound(Buffer)
    30.         RetBuffer(K) = Buffer(K)
    31.     Next K
    32.    
    33.     WaveFade16 = RetBuffer
    34. End Function
    Last edited by CVMichael; Dec 22nd, 2008 at 03:53 PM.

  7. #87
    Fanatic Member
    Join Date
    Mar 2008
    Posts
    790

    Re: Sugestions or Comments about my Sound Tutorial

    Thank you!

  8. #88
    New Member
    Join Date
    Sep 2008
    Posts
    14

    Re: Sugestions or Comments about my Sound Tutorial

    Would like to do some downsampling. Here are some definitions I found for downsampling vs decimation:

    "Decimation" is the process of reducing the sampling rate. In practice, this usually implies lowpass-filtering a signal, then throwing away some of its samples. "Downsampling" is a more specific term which refers to just the process of throwing away samples, without the lowpass filtering operation. To implement downsampling (by a downsampling factor of "M") simply keep every Mth sample, and throw away the M-1 samples in between.

    Now, what does this 'throwing away' actually mean? I implemented a function where in an array of 16 bit samples, I make the amplitude of 'M-1 samples in between' equal 0. This then I load the result into Wavedata(), then load Wavedata() in the buffer and play it. The higher M goes, the harsher/lo-fi the sound.

    However, I notice in your ConvertWave16DivideSamplesBy2 function which halves the sampling frequency, you are creating an array with half the samples of the source array - every second sample of the source array is not included - correct? Is this what is actually meant by 'throwing away' samples rather than what I did? And before this 'half array' is loaded in the buffer, would some 'redimensioning' of the buffer parameters be required first eg .lSamplesPerSec? .lAvgBytesPerSec? BuffDesc.lBufferBytes? Could you advise which would need to change and how?

  9. #89

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    Re: Sugestions or Comments about my Sound Tutorial

    Yes, ConvertWave16DivideSamplesBy2 ignores every second sample.

    And Yes again, when you save the buffer to a wave file, you have to save with the new parameters, depending on what changes you made to it.

    If it's divisible by 2 then use ConvertWave16DivideSamplesBy2, otherwise use ConvertWave16ReSample

  10. #90
    Fanatic Member
    Join Date
    Mar 2008
    Posts
    790

    Re: Sugestions or Comments about my Sound Tutorial

    General question: can someone please provide the link for me to download the correct directx to use this tutorial?

    Also, since this is the BEST place to ask this question: is it possible for sound files to change their volume on their own when played back on windows media player?

    If a wav file is played throughout the day, randomly and always with the computer volume control at the same position, can the output of that wav file change/fluctuate to make it just slightly louder or softer?

    If yes, what would make it fluctuate: computer activity, processes, ...? How can one control it?

    Or is it guaranteed that if you program the wav volume at a given level and play it back at the same volume level, the output would not change?

  11. #91
    New Member
    Join Date
    Feb 2009
    Posts
    3

    Thumbs up Re: Sugestions or Comments about my Sound Tutorial

    CVMIchael

    Loved your tutorial...

    Although there is your code examples "which are great" and some code to find a frequency, even some FT code, I don't seem to be able to figure out how to put those together.

    The buffer that is read to create the scope visuals, what has to be done to it so that it can be passed to a FFT procedure? Most of the procedures ask for real, imaginary and and another number)sample rate?). I would like to be able to use FFT to find the amplitude of a particular frequency(range) in the buffer.

    Thanks again for posting the tutorial, it has helped me a lot so far.

    cheers!

  12. #92

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    Re: Sugestions or Comments about my Sound Tutorial

    To the FFT function, give only the real numbers, set all 0 to imaginary. The samples parameter is how many samples you pass to the function and it has to be the power of 2, for example 256, 512, 1024 samples, etc...

    See post #13, right in this thread for code on FFT by rm_03

  13. #93
    New Member
    Join Date
    Feb 2009
    Posts
    3

    Re: Sugestions or Comments about my Sound Tutorial

    Sorry Michael, I am probably being a little dumb... information on this subject is very scarce.

    Do I convert the buffer into an array and pass that?

    The imagenary data - I am assuming this is another array that I just fill with 0, does the FFT sub write results to that array. If so what gets written?

    Thanks in advance for your help.

  14. #94
    New Member
    Join Date
    Feb 2009
    Posts
    3

    Re: Sugestions or Comments about my Sound Tutorial

    Ok

    I have figured it out - my code doesn't work yet but when I pass my RealInput to an online FFT calculator web site the results are correct.

    One thing I have noticed with FFT is that it picks up harmonics - a peak of 1000Hz shows another peak at 2500, 4000 (for example) etc...

  15. #95
    New Member
    Join Date
    Apr 2009
    Posts
    3

    Re: Sugestions or Comments about my Sound Tutorial

    CV michael .... i happen to take a look into your sound tutorial and i was curious, (i dont know if this has been asked before but i'll ask anyway) is there
    a way i could, when before pressing record, start off with a clear/empty buffer everytime? or record to a specified length then save to wav ? or have a function within it where i press a button to start over. with the way the split buffer operates i end up playing back the sound and on the end of the playback i'm hearing the sound of a previous recording in the file and i don't want that. as i looked into the source code i found it difficult to sift through and adjust the source code to fit my need. so far i have a variation of the project built where i have the recordstart/recordstop & sound play & stop buttons on the frmMain with the frmDX_record hidden from view.
    Last edited by NvbLM; Apr 28th, 2009 at 01:36 AM. Reason: typos...

  16. #96
    New Member
    Join Date
    Apr 2009
    Posts
    3

    Re: Sugestions or Comments about my Sound Tutorial

    since my last post i've been able to figure some things out ... though i still need to understand how to (within a common dialogbox control) just rename temp.wav to cd0.filename. (the common dialogbox fielname) basically recreate/duplicate or copy the temp.wav but with a new name.

  17. #97
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,930

    Re: Sugestions or Comments about my Sound Tutorial

    To copy a file (including renaming) use the FileCopy statement, eg:
    Code:
    FileCopy "c:\folder\temp.wav", cd0.filename
    to rename an existing file (and/or move it to a new folder) use the Name statement, eg:
    Code:
    Name "c:\folder\temp.wav" As cd0.filename

  18. #98
    New Member
    Join Date
    Apr 2009
    Posts
    3

    Re: Sugestions or Comments about my Sound Tutorial

    thank you Si ... i tried the code & it works like a charm. thank you so much! and big thanks to CVmichael for the split buffer record/play tutorial,...
    its given me immense insight on more dx8 i can accomplish.

  19. #99
    New Member
    Join Date
    Sep 2008
    Posts
    14

    Re: Sugestions or Comments about my Sound Tutorial

    CVMichael

    In your tutorial, you say this:

    Set DSEnum = DX.GetDSEnum
    ' select the first sound device, and create the Direct Sound object
    Set DIS = DX.DirectSoundCreate(DSEnum.GetGuid(1))

    Would you be able to adivse please how to return a list of all sound devices on the system, and enable the user to choose one (ie not just default to the first sound device).

    I'm not up with my C++, but a seemingly relevant description of how to do this appears here:

    http://edn.embarcadero.com/article/20941

    Thanks in advance!

  20. #100

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    Re: Sugestions or Comments about my Sound Tutorial

    The DSEnum holds all the sound devices, just check the properties there.

    You should have a Count, and other properties, like the name, etc...

    In the example you gave, the Index is 1, therefore it's getting the first one...

  21. #101
    New Member
    Join Date
    Sep 2008
    Posts
    14

    Re: Sugestions or Comments about my Sound Tutorial

    OK CVMichael. So a mod to your 'minimum code to play a wav file' to allow user to pick a sound device to play the sound through, would look like this (command button and listbox on a form):

    vbcode Code:
    1. Option Explicit
    2. Dim DX As New DirectX8
    3. Dim DSEnum as DirectSoundEnum8
    4. Dim Dis as DirectSound8
    5. Dim DSSecBuffer As DirectSoundSecondaryBuffer8
    6. Dim BuffDesc as DSBUFFERDESC
    7.  
    8. Private Sub Command1_Click()
    9. Dim A as Integer
    10. Dim N as Integer
    11. A = DX.GetDSEnum.GetCount
    12. For N = 1 To A
    13. List1.AddItem DX.GetDSEnum.GetDescription(N)
    14. Next N
    15. End Sub
    16.  
    17. Private Sub List1_Click()
    18. Dim V As Integer
    19. V = List1.ListIndex + 1
    20. Set DSEnum = DX.GetDSEnum
    21. Set DIS = DX.DirectSoundCreate(DSEnum.GetGuid(V))
    22. DIS.SetCooperativeLevel Me.hwnd, DSSCL_NORMAL
    23. Set DSSecBuffer = DIS.CreateSoundBufferFromFile("C:\Windows\Media\tada.wav", BuffDesc)
    24. DSSecBuffer.Play DSBPLAY_DEFAULT
    25. End Sub

    Questions:

    -The list gets populated with 'Primary Sound Driver' and 'Realtek HD Audio output' on my system, but Windows Control Panel shows just 'Realtek HD Audio output'. Does the 'Primary Sound Driver' actually mean the 'Realtek HD Audio output' in this case (and so is a redundant entry - the appear to play identically when chosen?)

    -Once a wav file is loaded into the directsound routine, should the listbox be disabled and enabled only when no sound is yet loaded?

    -The sound device would be selected JUST for this app, and not globally across the system for all other apps, right?

    Regards,
    DocNash

  22. #102

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    Re: Sugestions or Comments about my Sound Tutorial

    The first device is the default one that you choose here (in your windows):
    Name:  SoundCard.JPG
Views: 662
Size:  38.0 KB

    Then it lists the actual devices. If you have only one, then it basically lists the same thing... I have 2 sound cards, and a voice modem, so for me I have 3 devices + the default one. So DSEnum gives a count of 4.

    I don't get your second question, it todally depends on what you want to do...

    Yes, the selection is only for that sound buffer, so technically, if you have 2 (or more) sound cards, you can play (or record) on both sound cards at the same time, from the same application.

  23. #103
    New Member
    Join Date
    Sep 2008
    Posts
    14

    Re: Sugestions or Comments about my Sound Tutorial

    Thanks CVMichael for your explanation!

    Re the second question, you're absolutely right that it depends on the application scenario, and I hadn't explained the context.

    I've built a drum machine application that can load wav files into 10 channels, allows the sounds in each channel to be heavily modified/processed or even synthesized from scratch (additive, subtractive or fm synthesis), and allows sequencing of the sounds thru a built-in X0X interface, and it can be synced to midi. I was wondering when should the 'audio setup' menu item be enabled/disabled?

    -Should it only be disabled when the application is actually playing at least one sound?

    -Or should it be enabled only when no sounds are loaded into any of the channels (which means when the application is first launched or when 'clear all' menu item is selected)?

    I've opted for the latter, as firstly I think in such an application it makes sense for the whole sequence to be sent to the one audio device or another, and secondly once a sound is loaded many things get set up (and the user can also configure many things) all of which would need to be erased/reversed if the user chooses another audio device when a sound is already loaded.

    I've noticed different applications behave differently when it comes to enablement/disablement of 'audio setup'. For example:

    -Audacity keeps 'audio setup' enabled even when the waveform is loaded and graphically displayed, but disables 'audio setup' whilst the waveform is playing

    -Anvil Studio (a free audio/midi sequencer) always keeps 'audio setup' enabled but as soon as you open the 'audio setup' panel, the sequence stops playing and the play cursor goes back to the start of the sequence

    Regards,
    DocNash

  24. #104

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    Re: Sugestions or Comments about my Sound Tutorial

    Well, you can also let the user change the sound device at any time, but apply the changes only next time the "Play" button is pressed...

    Since there is no standard way, I guess any way you choose is OK...

  25. #105
    New Member
    Join Date
    Sep 2008
    Posts
    14

    Re: Sugestions or Comments about my Sound Tutorial

    Hi. I have a question re. support for VB6 + DirectX8 applications in newer OS's.

    This discussion:

    <http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1223939&SiteID=1>

    is fascinating. From what I can tell, it took place in '07, so I don't know where this has landed over the past couple of years. But a summary is:

    -DX8VB.DLL is not included in Vista

    -But applications which rely on DX8VB.DLL will work fine if this DLL is copied from a XP installation and registered on a Vista PC (using regsvr32 dx8vb.dll)

    -But doing so breaches the Direct Redist package EULA

    -MS were aware of the issue, but clearly stated VB6 & DX8 are no longer supported so would not include DX8VB.DLL in Vista

    -So where does that leave us who are still developing applications in VB6 relying on DX8? Should we not include registration of DX8VB.DLL in our application installers and instead advise end users to obtain and register the DLL themselves if they get a certain error when trying to run the application?

    -Can the two DLLs (DX10 and DX8), happily co-exist on Vista such that applications relying on either are not disrupted?

    Thanks!
    DocNash

  26. #106
    Fanatic Member
    Join Date
    Mar 2008
    Posts
    790

    Re: Sugestions or Comments about my Sound Tutorial

    Not sure if this was voiced yet, but when adjusting the volume of a wav file from your code, how can one know what percentage adjustment corresponds to 1 db increments for any selected tone generated?

    To comment on the above: I am in the same position as you, DoctorNash, it seems, would love to hear comments.

  27. #107
    PowerPoster CDRIVE's Avatar
    Join Date
    Jul 2007
    Posts
    2,620

    Re: Sugestions or Comments about my Sound Tutorial

    Quote Originally Posted by chris.cavage View Post
    .... from your code, how can one know what percentage adjustment corresponds to 1 db increments for any selected tone generated?
    The most accurate and reliable way of determining that is by measurement. Hang a Voltmeter on the ext speaker jack and measure it. This and many other links will save you the trouble of doing the math.

    http://www.geocities.com/pa2ohh/jsdblin.htm
    <--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
    If topic has been resolved, please pull down the Thread Tools & mark it Resolved.


    Is VB consuming your life, and is that a bad thing??

  28. #108
    Fanatic Member
    Join Date
    Mar 2008
    Posts
    790

    Re: Sugestions or Comments about my Sound Tutorial

    After reading/searching around, I am putting together the following VB6 code to create a 250 ms, 1000 Hz tone.

    I can get it to work well. I have one command on the form, called Play.

    I am trying to incorporate your code from thread #86, but do not know what is the problem.

    I currently get this error:

    "Compile Error: Type Mismatch: Array or user-defined type expected" when I click play.

    I am trying to fade the tone in 250 ms.

    Here is my code:

    vb Code:
    1. Option Explicit
    2. '
    3. ' DirectSound access
    4. Dim DX As DirectX8
    5. Dim DS As DirectSound8
    6. Dim dsToneBuffer As DirectSoundSecondaryBuffer8
    7. Dim desc As DSBUFFERDESC
    8. '
    9. ' Global variables
    10. Const PI = 3.14159265358979
    11. Const SRATE = 44100             ' Sampling Rate
    12. Const DUR = 0.25                    ' Tone duration
    13. Const FREQ = 1000                ' Tone frequency
    14. Dim sbuf(0 To DUR * SRATE) As Integer
    15.  
    16. Private Sub Form_Load()
    17. '
    18. ' initialise DirectSound
    19. Set DX = New DirectX8
    20. Set DS = DX.DirectSoundCreate("")
    21. DS.SetCooperativeLevel Me.hWnd, DSSCL_NORMAL
    22.  
    23.  
    24. desc.lFlags = DSBCAPS_CTRLVOLUME
    25. '
    26. ' create a buffer
    27.  
    28. desc.fxFormat.nFormatTag = WAVE_FORMAT_PCM
    29. desc.fxFormat.nSize = 0
    30. desc.fxFormat.lExtra = 0
    31. desc.fxFormat.nChannels = 1
    32.  
    33. desc.fxFormat.lSamplesPerSec = SRATE
    34. desc.fxFormat.nBitsPerSample = 16
    35. desc.fxFormat.nBlockAlign = 2
    36. desc.fxFormat.lAvgBytesPerSec = 2 * SRATE
    37. desc.lFlags = 0
    38. desc.lBufferBytes = 2 * DUR * SRATE
    39.  
    40. Set dsToneBuffer = DS.CreateSoundBuffer(desc)
    41. '
    42.  
    43. ' create a tone
    44. Dim i
    45. For i = 0 To DUR * SRATE
    46.     sbuf(i) = 10000 * Sin(2 * PI * FREQ * i / SRATE)
    47. Next i
    48. '
    49. ' copy tone to buffer
    50. dsToneBuffer.WriteBuffer 0, 2 * DUR * SRATE, sbuf(0), DSBLOCK_DEFAULT
    51.  
    52.  
    53. '
    54. End Sub
    55.  
    56. Private Sub Play_Click()
    57. '
    58. ' play the tone
    59. 'dsToneBuffer.SetVolume 0
    60.  
    61. Dim TotalSamples As Long
    62. Dim StartSample As Long
    63. Dim EndSample As Long
    64.  
    65. TotalSamples = SRATE * (250 / 1000#)
    66. StartSample = 0
    67. EndSample = TotalSamples
    68.  
    69. WaveFade16 dsToneBuffer, StartSample, EndSample, False
    70.  
    71. dsToneBuffer.Play DSBPLAY_DEFAULT
    72.  
    73.  
    74. End Sub
    75.  
    76. Public Function WaveFade16(Buffer() As Integer, StartSample As Long, EndSample As Long, Optional FadeOut As Boolean = True) As Integer()
    77.  
    78. Dim K As Long
    79. Dim RetBuffer() As Integer
    80. Dim TotalSamples As Long
    81. Dim Vol As Single
    82. ReDim RetBuffer(UBound(Buffer))
    83.  
    84. For K = LBound(Buffer) To StartSample - 1
    85. RetBuffer(K) = Buffer(K)
    86. Next K
    87.  
    88. TotalSamples = EndSample - StartSample
    89.  
    90. If FadeOut Then
    91. For K = StartSample To EndSample
    92. Vol = 1# - (CSng(K - StartSample) / TotalSamples)
    93. RetBuffer(K) = Buffer(K) * Vol
    94. Next K
    95. Else
    96. For K = StartSample To EndSample
    97. Vol = CSng(K - StartSample) / TotalSamples
    98. RetBuffer(K) = Buffer(K) * Vol
    99. Next K
    100. End If
    101.  
    102. For K = EndSample + 1 To UBound(Buffer)
    103. RetBuffer(K) = Buffer(K)
    104. Next K
    105. WaveFade16 = RetBuffer
    106. End Function

  29. #109
    PowerPoster CDRIVE's Avatar
    Join Date
    Jul 2007
    Posts
    2,620

    Re: Sugestions or Comments about my Sound Tutorial

    Quote Originally Posted by chris.cavage View Post
    After reading/searching around, I am putting together the following VB6 code to create a 250 ms, 1000 Hz tone.
    Are you aware that you can do that with the Beep API?

    Code:
    Option Explicit
    Private Declare Function Beep Lib "kernel32" (ByVal dwFreq As Long, ByVal dwDuration As Long) As Long
    
    Private Sub Form_Click()
       Beep 1000, 250
    End Sub
    <--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
    If topic has been resolved, please pull down the Thread Tools & mark it Resolved.


    Is VB consuming your life, and is that a bad thing??

  30. #110
    Fanatic Member
    Join Date
    Mar 2008
    Posts
    790

    Re: Sugestions or Comments about my Sound Tutorial

    Yes, I did know that. Thanks for that suggestion though.

    I need to work on fade in/fade out with a given tone... along with changing the volume. All of this, I didn't think I could do with the Beep API, so I am working on Directx8.

    Thanks also for your previous link... I had a look at it. Once I get the basics down, I will resort to that.

  31. #111
    Addicted Member
    Join Date
    Feb 2009
    Posts
    145

    Re: Sugestions or Comments about my Sound Tutorial

    Firstly CVMichael, what a fantastic job you've done with that tutorial. Congratulations.

    I have quickly gone over the tutorial and the posts here, but have not quite found what i'm looking for as I guessed that if I'm going to get an answer, it'll be here!

    Before noticing this great thread, I posted this elsewhere on the forum, which explains what im looking for.

    http://www.vbforums.com/showthread.php?t=585646

    I would greatly appreaciate any help on the subject.

    Thanks in anticipation, and again, a really useful thread.

  32. #112
    Junior Member
    Join Date
    Dec 2009
    Location
    Netherlands, Europe
    Posts
    21

    Re: Sugestions or Comments about my Sound Tutorial

    I already posted this message somewhere but probably in the wrong place.
    ---------
    Loved the sound tutorial CVMichael I use DirectX8 (in post #3 of the tutorial) to play a wave file:
    Code:
    Set DSSecBuffer = DIS.CreateSoundBufferFromFile("C:\WINDOWS\Media\tada.wav", BuffDesc, WaveFormat)
    DSSecBuffer.Play DSBPLAY_DEFAULT
    Works just fine!
    I'd like the button to change color as soon as the wave file ends. How can I determin if the tada.wav has come to an end? Is there an easy way to find out?

    Thanks, Floyd

  33. #113

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    Re: Sugestions or Comments about my Sound Tutorial

    Hi Floyd,

    In post #4 in the sound tutorial http://www.vbforums.com/showpost.php...99&postcount=4
    You will find how to set events.

    See this:
    Code:
    ' create the event to signal the sound has stopped
    EndEvent = DX.CreateEvent(Me)
    EventsNotify(2).hEventNotify = EndEvent
    EventsNotify(2).lOffset = DSBPN_OFFSETSTOP
    Then in the next code, you can see how to "Implements DirectXEvent8" to get the events.

  34. #114
    Junior Member
    Join Date
    Feb 2010
    Posts
    24

    Re: Sugestions or Comments about my Sound Tutorial

    Thanks for this fantastic tutorial.

    I have a request.

    Using the recording code is there any way of recording each channel of the sterio independently. IE seperate wav files for each channel and starting and stopping at different times.

    I think the only way to do this is to record all the time into a buffer then seperating them out into two different arrays, but if this can be done on the card itself it would be much easier.

    Geoff.

  35. #115

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    Re: Sugestions or Comments about my Sound Tutorial

    You got it, you have to record all the time, split the stereo sound into 2 mono sounds (buffers).
    So basically when you click record on one of the channels, then you actually begin saving on that channel.

  36. #116
    Junior Member
    Join Date
    Feb 2010
    Posts
    24

    Re: Sugestions or Comments about my Sound Tutorial

    Thought as much, trouble is I have got myself a little confussed as to how to actually split the chanels.
    I think its in here somewhere:
    With WaveFmt
    .wFormatTag = 1 ' PCM
    .nChannels = 1
    .nSamplesPerSec = 8000
    .wBitsPerSample = 16
    .nBlockAlign = .wBitsPerSample * .nChannels / 8
    .nAvgBytesPerSec = .nBlockAlign * .nSamplesPerSec
    but I dont know how to select either right or left.

    Geoff.

  37. #117

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    Re: Sugestions or Comments about my Sound Tutorial


  38. #118
    Junior Member
    Join Date
    Feb 2010
    Posts
    24

    Re: Sugestions or Comments about my Sound Tutorial

    Yes I have looked at that thread already, but what I cant fathom is how to turn the two channels into seperate soundfiles.

    I don't know if im being a little thick here, but I cant work out which part of the programme the split refers to. Is it the buffer from the directsound or is it the finished file. I am not too good with binary files I think that is where I am loosing it.

    Geoff.
    Last edited by UKnod; Feb 18th, 2010 at 04:07 AM.

  39. #119
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Sugestions or Comments about my Sound Tutorial

    Wow... wonderful tutorial... Thanks for creating and sharing it....

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  40. #120
    Junior Member
    Join Date
    Feb 2010
    Posts
    24

    Re: Sugestions or Comments about my Sound Tutorial

    I have tried changing the sound card, but it only seems to work on playback, the recording card stays as the default primary card. Any ideas what I am doing wrong.

Page 3 of 5 FirstFirst 12345 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width