Page 5 of 5 FirstFirst ... 2345
Results 161 to 181 of 181

Thread: Sugestions or Comments about my Sound Tutorial

  1. #161
    Banned
    Join Date
    Mar 2009
    Posts
    764

    Re: Sugestions or Comments about my Sound Tutorial

    the following code gets the sound at 150 miliseconds intervals and it is still not good enough
    I'd totaly use MS speech reco but 3 minuses :
    when correcting spelling mistakes I can't use some letters (M, S)
    it uses win 7 perhapse it can be worked in xp ?
    it doesn't work with image capture from a webcam

    vb Code:
    1. [CODE]Imports System
    2. Imports System.Collections
    3. Imports System.ComponentModel
    4. Imports System.Drawing
    5. Imports System.Windows.Forms
    6. Imports Microsoft.DirectX.DirectSound
    7. Imports System.Threading
    8. Imports System.Collections.Specialized
    9. Public Class Sound_Card_Form
    10. Private Sub StartButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles FindButton.Click
    11. 'Dim MyVU As New VolumeMeter
    12. 'MyVU.Start()
    13. Start()
    14. End Sub
    15. Private Sub FindButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles FindButton.Click
    16. 'Dim MyVU As New VolumeMeter
    17. 'MyVU.FindDevices()
    18. FindDevices()
    19. End Sub
    20.  
    21. ' Public Class VolumeMeter
    22. 'Inherits System.Windows.Forms.UserControl
    23. 'Public Delegate Sub VolumeChangedEventHandler(ByVal vcea As VolumeChangedEventArgs)
    24. 'Public Event VolumeChanged As VolumeChangedEventHandler
    25. Private Const SAMPLES As Integer = 8
    26. Private Shared SAMPLE_FORMAT_ARRAY As Integer() = {SAMPLES, 2, 1}
    27. Public Shared audioDevices As CaptureDevicesCollection
    28. Private Shared m_deviceNames As StringCollection
    29. Private deviceName As String = "(none)"
    30. Private deviceIndex As Integer = -1
    31. Private buffer As Microsoft.DirectX.DirectSound.CaptureBuffer
    32. Private liveVolumeThread As System.Threading.Thread
    33. Private m_sampleDelay As Integer = 100
    34. Private m_frameDelay As Integer = 10
    35. Private m_autoStart As Boolean = True
    36. 'Private components As System.ComponentModel.Container = Nothing
    37. Public Sub FindDevices()
    38. Dim audioDevices As New CaptureDevicesCollection
    39. Dim x As Integer = 0
    40. While x < audioDevices.Count
    41. ComboBox1.Items.Add(audioDevices.Item(x).Description)
    42. x = x + 1
    43. End While
    44. ComboBox1.SelectedIndex = 0
    45. End Sub
    46. Public Sub Start()
    47. [Stop]()
    48. Dim audioDevices As New CaptureDevicesCollection
    49. deviceIndex = ComboBox1.SelectedIndex
    50. If deviceIndex <> -1 Then
    51. ' initialize the capture buffer and start the animation thread
    52. Dim cap As New Capture(audioDevices(deviceIndex).DriverGuid)
    53. Dim desc As New CaptureBufferDescription()
    54. Dim wf As New WaveFormat()
    55. wf.BitsPerSample = 16
    56. wf.SamplesPerSecond = 44100
    57. wf.Channels = 2
    58. wf.BlockAlign = CShort(wf.Channels * wf.BitsPerSample / 8)
    59. wf.AverageBytesPerSecond = wf.BlockAlign * wf.SamplesPerSecond
    60. wf.FormatTag = WaveFormatTag.Pcm
    61. desc.Format = wf
    62. desc.BufferBytes = SAMPLES * wf.BlockAlign
    63. buffer = New Microsoft.DirectX.DirectSound.CaptureBuffer(desc, cap)
    64. buffer.Start(True)
    65. ' Start a seperate thread to read the buffer and update the progress bars
    66. liveVolumeThread = New Thread(AddressOf updateProgress) 'Thread starts at updateProgress
    67. Control.CheckForIllegalCrossThreadCalls = False ' This is needed otherwise the form will not update
    68. liveVolumeThread.Priority = ThreadPriority.Lowest ' Thread works in the background
    69. liveVolumeThread.Start()
    70. End If
    71. End Sub
    72. Public Sub [Stop]()
    73. If liveVolumeThread IsNot Nothing Then
    74. liveVolumeThread.Abort()
    75. liveVolumeThread.Join()
    76. liveVolumeThread = Nothing
    77. End If
    78. If buffer IsNot Nothing Then
    79. If buffer.Capturing Then
    80. buffer.[Stop]()
    81. End If
    82. buffer.Dispose()
    83. buffer = Nothing
    84. End If
    85. End Sub
    86.  
    87. Public Sub updateProgress()
    88. While True
    89. Dim tempFrameDelay As Integer = m_frameDelay
    90. Dim tempSampleDelay As Integer = m_sampleDelay
    91. Dim samples__1 As Array = buffer.Read(0, GetType(Int16), LockFlag.FromWriteCursor, SAMPLE_FORMAT_ARRAY)
    92. ' for each channel, determine the step size necessary for each iteration
    93. Dim leftGoal As Integer = 0
    94. Dim rightGoal As Integer = 0
    95. ' Sum the 8 samples
    96. For i As Integer = 0 To SAMPLES - 1
    97. leftGoal += CType(samples__1.GetValue(i, 0, 0), Int16)
    98. rightGoal += CType(samples__1.GetValue(i, 1, 0), Int16)
    99. Next
    100. ' Calculate the average of the 8 samples
    101. leftGoal = CInt(Math.Abs(leftGoal \ SAMPLES))
    102. rightGoal = CInt(Math.Abs(rightGoal \ SAMPLES))
    103. Dim range1 As Double = leftGoal - ProgressBar1.Value ' calculates the difference between new and the current progress bar value
    104. Dim range2 As Double = rightGoal - ProgressBar2.Value
    105. ' Assign the exact current value to the progress bar
    106. Dim exactValue1 As Double = ProgressBar1.Value
    107. Dim exactValue2 As Double = ProgressBar2.Value
    108. Dim stepSize1 As Double = range1 / tempSampleDelay * tempFrameDelay
    109. ' Limit the value range to positive values
    110. If Math.Abs(stepSize1) < 0.01 Then
    111. stepSize1 = Math.Sign(range1) * 0.01
    112. End If
    113. Dim absStepSize1 As Double = Math.Abs(stepSize1)
    114. Dim stepSize2 As Double = range2 / tempSampleDelay * tempFrameDelay
    115. If Math.Abs(stepSize2) < 0.01 Then
    116. stepSize2 = Math.Sign(range2) * 0.01
    117. End If
    118. Dim absStepSize2 As Double = Math.Abs(stepSize2)
    119. ' increment/decrement the bars' values until both equal their desired goals,
    120. ' sleeping between iterations
    121. If (ProgressBar1.Value = leftGoal) AndAlso (ProgressBar2.Value = rightGoal) Then
    122. Thread.Sleep(tempSampleDelay)
    123. Else
    124. Do
    125. If ProgressBar1.Value <> leftGoal Then
    126. If absStepSize1 < Math.Abs(leftGoal - ProgressBar1.Value) Then
    127. exactValue1 += stepSize1
    128. ProgressBar1.Value = CInt(Math.Truncate(Math.Round(exactValue1)))
    129. 'This is the real value
    130. 'decibels = 20 * Log10(ProgressBar1.Value/ 32768.0)
    131. Else
    132. ProgressBar1.Value = leftGoal
    133. End If
    134. End If
    135. If ProgressBar2.Value <> rightGoal Then
    136. If absStepSize2 < Math.Abs(rightGoal - ProgressBar2.Value) Then
    137. exactValue2 += stepSize2
    138. ProgressBar2.Value = CInt(Math.Truncate(Math.Round(exactValue2)))
    139. Else
    140. ProgressBar2.Value = rightGoal
    141. End If
    142. End If
    143. Thread.Sleep(tempFrameDelay)
    144. Loop While (ProgressBar1.Value <> leftGoal) OrElse (ProgressBar2.Value <> rightGoal)
    145. End If
    146. End While
    147. End Sub
    148.  
    149. End Class[/CODE]
    Last edited by moti barski; Aug 23rd, 2011 at 03:11 PM.

  2. #162
    Frenzied Member
    Join Date
    Oct 2008
    Posts
    1,181

    Re: Sugestions or Comments about my Sound Tutorial

    I read your tutorial at http://www.vbforums.com/showthread.php?t=388562 but it is lacking something important, something that most people making video games etc will need to do, and that is playing sounds generated on the fly WITHOUT first storing them in a WAV file. For example this code here generates an array of a sine wave.
    Code:
    dim mysound(44099) as integer
    for n = 0 to 44099
    mysound(n)=sin(n*2*3.14159*1000/44099)*&h7fff
    next n
    This generates an array of 16bit signed integers that holds a sine wave that if played back at 44100 samples per second will last for 1 second and the tone will be at a frequency of 1000hz.

    I want to then use that array and feed it into a command that will cause it to be played through the sound card at a rate of 44100 samples per second. Your tutorial did NOT cover such, and instead focused ONLY on how to play WAV files, which is actually trivial to do with the Windows Media Player ActiveX control.

    I'm looking for a tutorial for how to feed raw sound data in an array to my sound card, tell my sound card length of the array, the sample rate, bit depth, and number of channels that the sound is supposed to be played at, and the result is I get the desired sound being instantly played as intended, NO INTERMEDIATE STEPS (like saving WAV files) needed.

    Now can I do this in DirectX? Or maybe a Windows API call, or maybe some kind of DLL or OCX file? Any help would be nice, but your tuturoial didn't help me with my endevour. As soon as I saw it talking about WAV files, I knew it wasn't going to help me.

  3. #163

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

    Re: Sugestions or Comments about my Sound Tutorial

    Quote Originally Posted by Ben321 View Post
    ...but your tuturoial didn't help me with my endevour. As soon as I saw it talking about WAV files, I knew it wasn't going to help me.
    It took me this long to reply because of that statement alone...

    The point of the tutorial was to make people understand how it works.

    I did not say anywhere in the article that you have to use wave files, that is just an example. If you understand how to process the sound, then you should be able to modify the examples I have in the article for your needs.

    There is a sample Split Buffer Play in post #4, that should help you for what you need, but I guess you did not get that far in the tutorial before you gave up on it...

    I doesn't look like your trying too hard. Try to figure things out on your own. How do you think I figured out everything? there was no tutorial to help me!

    I can't make a tutorial for every single possible need, and I will not spoon feed you (or anyone).

  4. #164
    Junior Member
    Join Date
    Jun 2012
    Posts
    20

    Re: Sugestions or Comments about my Sound Tutorial

    Hi,
    Can we play wave file at different frequencies, I meant to say that i have wave file of 240 HZ and i want to play it as 360 HZ,without modifying original file or creating new modified file of the 360 HZ,
    I know i can do this by generating the sine wave and then changing its parameters, but i want to develop educational program on music and timber of sound is very important. so that i can record Base note and then play it as different frequency. Is it possible?? i have put this in the thread in this forum but one person gave me idea by creating new modified file with change in sampling rate and bit rate and then play it. It is OK but the problem is it is not working under the FOR LOOP.
    Can we have only one wave file and then play it as different frequency?

  5. #165

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

    Re: Sugestions or Comments about my Sound Tutorial

    In my sound tutorial, take a look at post #7. Use the function ConvertWave16ReSample to resample your buffer.

    But you have to calculate in Sample Rate rather than frequency. You are not saying what is the sample rate of your wave file, I'll assume it is 22050Hz (so that I can make an example for you)

    So, let's say your sound is 22050Hz sample rate, and in it you have a sound frequency of 240Hz.

    To get a frequency of 360Hz, then you have to do some math: 240 / 360 = 0.666666

    So, if your sample rate is 22050Hz then you will have to resample it at 22050 * 0.666666 = 14700 Hz

    Now convert your buffer like this:
    ResultBuffer = ConvertWave16ReSample(Your_Buffer, 22050, 14700, False)
    (I also assume your wave file is Mono)

    Of you can do the calculations when you call the function, for example:
    ResultBuffer = ConvertWave16ReSample(Your_Buffer, 22050, 22050 * (240 / 360), False)

    This will result in compressing the sound to a lower sample rate, but when you play it at original sample rate (22050Hz), the sound (frequency) will play faster, at 360Hz.
    Last edited by CVMichael; Jun 21st, 2012 at 09:22 AM.

  6. #166
    Junior Member
    Join Date
    Jun 2012
    Posts
    20

    Re: Sugestions or Comments about my Sound Tutorial

    I Did the same. i first copy the code for the playing the file with DirectX7 and then put a command button to play it. Then as per your instructions i Copied the function if the converwave16Resample function and passed the arguments to this function like this

    resultbuffer = ConvertWave16ReSample(DSSecBuffer, 22500, 14700, False)

    which gives me the error to type mismatch:array or user defined type should be used for DSSecBuffer

    Can you help me?

  7. #167
    Junior Member
    Join Date
    Jun 2012
    Posts
    20

    Re: Sugestions or Comments about my Sound Tutorial

    Here is the total code running

    Private DX As New DirectX7
    Private DSEnum As DirectSoundEnum
    Private DIS As DirectSound

    Private DSSecBuffer As DirectSoundBuffer

    Private Sub Form_Load()
    Dim BuffDesc As DSBUFFERDESC, WaveFormat As WAVEFORMATEX

    ' get enumeration object
    Set DSEnum = DX.GetDSEnum

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

    ' Set the Cooperative Level to normal
    DIS.SetCooperativeLevel Me.hWnd, DSSCL_NORMAL

    ' load the wave file, and create the buffer for it
    Set DSSecBuffer = DIS.CreateSoundBufferFromFile("C:\WINDOWS\Media\tada.wav", BuffDesc, WaveFormat)

    resultbuffer = ConvertWave16ReSample(DSSecBuffer, 22500, 14700, False)


    resultbuffer.Play DSBPLAY_DEFAULT

    End Sub


    Public Function ConvertWave16ReSample(Buff() As Integer, ByVal FromSample As Long, ByVal ToSample As Long, ByVal Stereo As Boolean) As Integer()
    Dim K As Long, Lx As Long, RX As Long
    Dim Ret() As Integer, Per As Double, NewSize As Long

    If Not Stereo Then
    NewSize = Fix((UBound(Buff) + 1) * ToSample / FromSample + 0.5)
    ReDim Ret(NewSize - 1)

    For K = 0 To UBound(Ret) - 1
    Per = K / UBound(Ret)

    Lx = Fix(UBound(Buff) * Per)

    Ret(K) = FindYForX(UBound(Buff) * Per, Lx, Buff(Lx), Lx + 1, Buff(Lx + 1))
    Next K

    Ret(UBound(Ret)) = Buff(UBound(Buff))
    Else
    NewSize = Fix((UBound(Buff) + 1) * ToSample / FromSample + 0.5)
    NewSize = NewSize - (NewSize Mod 2)
    ReDim Ret(NewSize - 1)

    For K = 0 To UBound(Ret) Step 2
    Per = K / (UBound(Ret) + 2)

    ' Left channel
    Lx = Fix(UBound(Buff) * Per / 2#) * 2
    Ret(K + 0) = FindYForX(UBound(Buff) * Per, Lx, Buff(Lx), Lx + 2, Buff(Lx + 2))

    ' Right channel
    RX = Lx + 1
    Ret(K + 1) = FindYForX(UBound(Buff) * Per + 1, RX, Buff(RX), RX + 2, Buff(RX + 2))
    Next K

    Ret(UBound(Ret) - 1) = Buff(UBound(Buff) - 1)
    Ret(UBound(Ret)) = Buff(UBound(Buff))
    End If

    ConvertWave16ReSample = Ret
    End Function
    Last edited by jignesh142; Jun 23rd, 2012 at 06:12 AM.

  8. #168
    Junior Member
    Join Date
    Jun 2012
    Posts
    20

    Re: Sugestions or Comments about my Sound Tutorial

    I request CVMichael to help me as i have limited knowledge about this. I think you can only help me to complete my educational software on music.

  9. #169

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

    Re: Sugestions or Comments about my Sound Tutorial

    After this long, you still did not figure out that you cannot pass an object to a function that expects an array?

    If you cannot fallow my tutorial, and if you cannot figure out something so simple, that means you need a LOT of help, and I don't have time for that. I gave you enough clues, you just have to try harder, or put the project asside until you know more programming.

  10. #170
    Junior Member
    Join Date
    Jun 2012
    Posts
    20

    Re: Sugestions or Comments about my Sound Tutorial

    It is true that i have very little knowledge of the VB as i am not professional programmer.I don't expect the explanations of the each term or logic in the reply as your time is very Important, what i need your help is to modify the above code with the correct code, if you can do so then it will be great help for me and i believe that it will not spend your much time.

  11. #171
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: Sugestions or Comments about my Sound Tutorial

    If you want somebody to write code for you and make sure it works, then that can easily take lots of time (explaining a few things to you generally takes much less effort).

    While somebody may be able to do it faster than you, it doesn't mean it will only take them a few seconds - it wouldn't be surprising if it took at least an hour.

    It is unfair to ask a complete stranger to do that scale of favour for you, especially as there is a very slim chance that you will do anything for them in return, and you are very likely to expect the same kind of "help" again in future. In addition to that, a large percentage of people who ask for help on the forum can be helped in about a minute or two, so doing something for you would mean ignoring lots of other people who want help too.

    If you want the work done for you, it is unreasonable to expect it for free (there are several sites where you can hire people for that kind of thing). If you want it for free, you are almost certainly going to have to do almost everything yourself, and only get help in terms of relatively quick answers (post #165 above is better than you should expect).

  12. #172
    Junior Member
    Join Date
    Jun 2012
    Posts
    20

    Re: Sugestions or Comments about my Sound Tutorial

    Finally i have made my software regarding the music.

    It is better to generate the different frequency sounds then to change the frequency of the particular sound. It is easy to generate the sine wave sound with the different frequencies.

    Thank you to all to help me , Specially CVMichel...

  13. #173
    New Member
    Join Date
    Oct 2014
    Posts
    1

    Re: Sugestions or Comments about my Sound Tutorial

    VB6.0 – Sound and DirectXSound Tutorial

    Hi, I hope, that I'm on the right path...and thank you for that fine tutorial!
    My problem is, that I cannot record in higher resolution than 16bit, stereo 44100Hz, I sucessfully wrote a sound generator using "play wave" that makes a sound in highest resolution (my onboard-soundsystem supplies wave up to 192KHz and 24Bit) by writing header with "extended-format". But I never suceeded to apply same header to "wave_sound_record" Can you please give me a kick :-) thanx a lot!
    vb6zip

  14. #174
    Frenzied Member
    Join Date
    Oct 2008
    Posts
    1,181

    Re: Sugestions or Comments about my Sound Tutorial

    In your tutorial on split buffer playing, you use a Form to hold the direct sound code, instead of a Class. Why? As playing a sound is not a visual task, it shouldn't require a visual element, such as a Form.

  15. #175

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

    Re: Sugestions or Comments about my Sound Tutorial

    Quote Originally Posted by Ben321 View Post
    In your tutorial on split buffer playing, you use a Form to hold the direct sound code, instead of a Class. Why? As playing a sound is not a visual task, it shouldn't require a visual element, such as a Form.
    DirectSound needs a window handle to return events, so a form is used. Classes don't have window handles....

  16. #176
    Frenzied Member
    Join Date
    Oct 2008
    Posts
    1,181

    Re: Sugestions or Comments about my Sound Tutorial

    Quote Originally Posted by CVMichael View Post
    DirectSound needs a window handle to return events, so a form is used. Classes don't have window handles....
    I should be able to simply pass my program's main form hWnd as a parameter to an initialization method in the class, so that the class for operating direct sound doesn't need to have its own useless form object. Would this work? Or what about using the computer screen's own hWnd as returned by the Windows API function GetDesktopWindow?

  17. #177

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

    Re: Sugestions or Comments about my Sound Tutorial

    It doesn't take the hWnd as input parameter anywhere...

    But you can pass the event to the class, like this:
    In your form:
    Code:
    Implements DirectXEvent8
    Private WithEvents DXPlay As clsDX_Play ' the class
    
    ' the event from DirectXSound
    Private Sub DirectXEvent8_DXCallback(ByVal EventID As Long)
        ' pass the event to the class
        DXPlay.DirectXEvent8_DXCallback EventID
    End Sub
    Then in the class just create a function to receive the event:
    Code:
    Public Sub DirectXEvent8_DXCallback(ByVal EventID As Long)
    
    End Sub

  18. #178
    Frenzied Member
    Join Date
    Oct 2008
    Posts
    1,181

    Re: Sugestions or Comments about my Sound Tutorial

    Quote Originally Posted by CVMichael View Post
    It doesn't take the hWnd as input parameter anywhere...
    Actually it does, in the DirectSound SetCooperativeLevel method.


    Ok, so I tired to come up with a class-only solution for this, and here's what I created for the class.
    Code:
    Dim DX8 As New DirectX8
    Dim DS As DirectSound8
    Dim DSB As DirectSoundSecondaryBuffer8
    Dim DSBD As DSBUFFERDESC
    Dim Buffer() As Single
    Dim BuffSize As Long
    Dim Positions(2) As DSBPOSITIONNOTIFY
    Dim EventStart As Long
    Dim EventMid As Long
    Dim EventEnd As Long
    Dim StreamIsInit As Boolean
    
    Implements DirectXEvent8
    
    Public Event GetBuffer(ByRef AudioBuffer() As Single)
    
    
    Public Sub StreamStart()
    If StreamIsInit = False Then Exit Sub
    DSB.Play DSBPLAY_LOOPING
    End Sub
    
    Public Sub StreamStop()
    If StreamIsInit = False Then Exit Sub
    DSB.Stop
    End Sub
    
    Private Sub Class_Initialize()
    Set DS = DX8.DirectSoundCreate("")
    End Sub
    
    Private Sub Class_Terminate()
    DSB.Stop
    Set DSB = Nothing
    DX8.DestroyEvent EventStart
    DX8.DestroyEvent EventMid
    DX8.DestroyEvent EventEnd
    Set DS = Nothing
    Set DX8 = Nothing
    End Sub
    
    Private Sub DirectXEvent8_DXCallback(ByVal eventid As Long)
    If eventid = EventEnd Then Exit Sub
    
    RaiseEvent GetBuffer(Buffer)
    
    Select Case eventid
        Case EventStart
            DSB.WriteBuffer BuffSize * 4, BuffSize * 4, Buffer(0), DSCBLOCK_DEFAULT
        Case EventMid
            DSB.WriteBuffer 0, BuffSize * 4, Buffer(0), DSBLOCK_DEFAULT
    End Select
    End Sub
    
    
    Public Sub InitStreamObject(ByVal hWnd As Long, Optional ByVal BufferSize As Long = 1024, Optional ByVal SampleRate As Long = 8000)
    If StreamIsInit Then Exit Sub
    StreamIsInit = True
    BuffSize = BufferSize
    DS.SetCooperativeLevel hWnd, DSSCL_PRIORITY
    
    With DSBD
        .lFlags = DSBCAPS_GLOBALFOCUS Or DSBCAPS_CTRLPOSITIONNOTIFY
        .lBufferBytes = BuffSize * 2 * 4
        With .fxFormat
            .lSamplesPerSec = SampleRate
            .nBitsPerSample = 32
            .nBlockAlign = .nBitsPerSample \ 8
            .nChannels = 1
            .nFormatTag = 3
            .lAvgBytesPerSec = .nBlockAlign * .lSamplesPerSec
        End With
    End With
    
    Set DSB = DS.CreateSoundBuffer(DSBD)
    
    EventStart = DX8.CreateEvent(Me)
    EventMid = DX8.CreateEvent(Me)
    EventEnd = DX8.CreateEvent(Me)
    
    With Positions(0)
        .hEventNotify = EventStart
        .lOffset = 0
    End With
    With Positions(1)
        .hEventNotify = EventMid
        .lOffset = BuffSize * 4
    End With
    With Positions(2)
        .hEventNotify = EventEnd
        .lOffset = BuffSize * 2 * 4 - 1
    End With
    
    DSB.SetNotificationPositions 3, Positions()
    End Sub

    Then in my main program's form (not part of the DirectSound routine, just the program's form), the first thing it does is to initialize an instance of this class. Here's the form of the
    Code:
    Dim WithEvents DSOut As Class1
    
    Private Sub Form_Load()
    Set DSOut = New Class1
    DSOut.InitStreamObject Me.hWnd
    End Sub
    Unfortunately this generates an error when it gets to this line of code in the class method InitStreamObject.
    Code:
    EventStart = DX8.CreateEvent(Me)
    The error is:
    Run-time error '-2147467259 (80004005)':

    Automation error
    Unspecified error
    I do not know why this error is happening. The code in this class is almost exactly identical to the DirectSound input class that I created previously, with only a few changes needed to make it work with output instead of input. The DirectSound input class does not generate this error when it gets to the CreateEvent method. Please explain why this error is being generated with my DirectSound output class.
    Last edited by Ben321; Sep 15th, 2015 at 03:43 PM.

  19. #179

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

    Re: Sugestions or Comments about my Sound Tutorial

    Quote Originally Posted by Ben321 View Post
    ... Please explain why this error is being generated with my DirectSound output class.
    Don't have any idea... you are alone on this one...

    I haven't been using VB6 for about 5-6 years (don't have it installed on my computer since then), and it's been almost 10 years since I created this thread about sound... so I don't remember much!

  20. #180
    Frenzied Member
    Join Date
    Oct 2008
    Posts
    1,181

    Re: Sugestions or Comments about my Sound Tutorial

    Quote Originally Posted by CVMichael View Post
    Don't have any idea... you are alone on this one...

    I haven't been using VB6 for about 5-6 years (don't have it installed on my computer since then), and it's been almost 10 years since I created this thread about sound... so I don't remember much!

    Anybody else on here know about using DirectSound? Or are you like the one guy on these forums (or any VB6 related forums for that matter) that has any knowledge of how do use DirectSound in VB6? Is this knowledge of how to use DirectSound in VB6 becoming something like forever lost knowledge in the world?

  21. #181
    Frenzied Member
    Join Date
    Oct 2008
    Posts
    1,181

    Re: Sugestions or Comments about my Sound Tutorial

    Now I'm having another problem. When I stop my sound buffer from playing, and then I later start it up again, with different data, it for a fraction of a second continues playing the previous data, before it reads the new data. I assume that's because when I stopped it, I stopped it before it had finished playing the previous segment of the buffer. So to fix that, I just made sure to load an empty array like this

    Code:
    DSB.Stop
    If ResetBuffer Then
        DSB.SetCurrentPosition 0
        ReDim EmptyBuffer(BuffSize * 2 - 1)
        ' The *2 accounts for the entire buffer size, not just the half-buffer size that is stored in the BuffSize variable.
        DSB.WriteBuffer 0, 0, EmptyBuffer(0), DSBLOCK_ENTIREBUFFER
    End If
    DSB is the name I gave the DirectSound Buffer object. By stopping the playback, and then clearing the entire buffer, it should make it so that it completely overwrites the content of the buffer. Unfortunately, this only MOSTLY works. It leaves a tiny amount at the start of the buffer that appears that it can't be overwritten. The next time I start the buffer playing, there is a VERY brief "click" sound at the beginning (about 100 samples or so I would guess, remained untouched by my overwriting the buffer with blank data it seems), and then for about a tenth of a second there's silence (where the buffer was successfully overwritten) and then it starts playing the desired sound.

    Why are a few samples at the start of the buffer untouched by the write operation that I use to try to clear the buffer?
    Last edited by Ben321; Sep 19th, 2015 at 05:41 AM.

Page 5 of 5 FirstFirst ... 2345

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