-
Aug 22nd, 2011, 03:38 PM
#161
Banned
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:
[CODE]Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Drawing
Imports System.Windows.Forms
Imports Microsoft.DirectX.DirectSound
Imports System.Threading
Imports System.Collections.Specialized
Public Class Sound_Card_Form
Private Sub StartButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles FindButton.Click
'Dim MyVU As New VolumeMeter
'MyVU.Start()
Start()
End Sub
Private Sub FindButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles FindButton.Click
'Dim MyVU As New VolumeMeter
'MyVU.FindDevices()
FindDevices()
End Sub
' Public Class VolumeMeter
'Inherits System.Windows.Forms.UserControl
'Public Delegate Sub VolumeChangedEventHandler(ByVal vcea As VolumeChangedEventArgs)
'Public Event VolumeChanged As VolumeChangedEventHandler
Private Const SAMPLES As Integer = 8
Private Shared SAMPLE_FORMAT_ARRAY As Integer() = {SAMPLES, 2, 1}
Public Shared audioDevices As CaptureDevicesCollection
Private Shared m_deviceNames As StringCollection
Private deviceName As String = "(none)"
Private deviceIndex As Integer = -1
Private buffer As Microsoft.DirectX.DirectSound.CaptureBuffer
Private liveVolumeThread As System.Threading.Thread
Private m_sampleDelay As Integer = 100
Private m_frameDelay As Integer = 10
Private m_autoStart As Boolean = True
'Private components As System.ComponentModel.Container = Nothing
Public Sub FindDevices()
Dim audioDevices As New CaptureDevicesCollection
Dim x As Integer = 0
While x < audioDevices.Count
ComboBox1.Items.Add(audioDevices.Item(x).Description)
x = x + 1
End While
ComboBox1.SelectedIndex = 0
End Sub
Public Sub Start()
[Stop]()
Dim audioDevices As New CaptureDevicesCollection
deviceIndex = ComboBox1.SelectedIndex
If deviceIndex <> -1 Then
' initialize the capture buffer and start the animation thread
Dim cap As New Capture(audioDevices(deviceIndex).DriverGuid)
Dim desc As New CaptureBufferDescription()
Dim wf As New WaveFormat()
wf.BitsPerSample = 16
wf.SamplesPerSecond = 44100
wf.Channels = 2
wf.BlockAlign = CShort(wf.Channels * wf.BitsPerSample / 8)
wf.AverageBytesPerSecond = wf.BlockAlign * wf.SamplesPerSecond
wf.FormatTag = WaveFormatTag.Pcm
desc.Format = wf
desc.BufferBytes = SAMPLES * wf.BlockAlign
buffer = New Microsoft.DirectX.DirectSound.CaptureBuffer(desc, cap)
buffer.Start(True)
' Start a seperate thread to read the buffer and update the progress bars
liveVolumeThread = New Thread(AddressOf updateProgress) 'Thread starts at updateProgress
Control.CheckForIllegalCrossThreadCalls = False ' This is needed otherwise the form will not update
liveVolumeThread.Priority = ThreadPriority.Lowest ' Thread works in the background
liveVolumeThread.Start()
End If
End Sub
Public Sub [Stop]()
If liveVolumeThread IsNot Nothing Then
liveVolumeThread.Abort()
liveVolumeThread.Join()
liveVolumeThread = Nothing
End If
If buffer IsNot Nothing Then
If buffer.Capturing Then
buffer.[Stop]()
End If
buffer.Dispose()
buffer = Nothing
End If
End Sub
Public Sub updateProgress()
While True
Dim tempFrameDelay As Integer = m_frameDelay
Dim tempSampleDelay As Integer = m_sampleDelay
Dim samples__1 As Array = buffer.Read(0, GetType(Int16), LockFlag.FromWriteCursor, SAMPLE_FORMAT_ARRAY)
' for each channel, determine the step size necessary for each iteration
Dim leftGoal As Integer = 0
Dim rightGoal As Integer = 0
' Sum the 8 samples
For i As Integer = 0 To SAMPLES - 1
leftGoal += CType(samples__1.GetValue(i, 0, 0), Int16)
rightGoal += CType(samples__1.GetValue(i, 1, 0), Int16)
Next
' Calculate the average of the 8 samples
leftGoal = CInt(Math.Abs(leftGoal \ SAMPLES))
rightGoal = CInt(Math.Abs(rightGoal \ SAMPLES))
Dim range1 As Double = leftGoal - ProgressBar1.Value ' calculates the difference between new and the current progress bar value
Dim range2 As Double = rightGoal - ProgressBar2.Value
' Assign the exact current value to the progress bar
Dim exactValue1 As Double = ProgressBar1.Value
Dim exactValue2 As Double = ProgressBar2.Value
Dim stepSize1 As Double = range1 / tempSampleDelay * tempFrameDelay
' Limit the value range to positive values
If Math.Abs(stepSize1) < 0.01 Then
stepSize1 = Math.Sign(range1) * 0.01
End If
Dim absStepSize1 As Double = Math.Abs(stepSize1)
Dim stepSize2 As Double = range2 / tempSampleDelay * tempFrameDelay
If Math.Abs(stepSize2) < 0.01 Then
stepSize2 = Math.Sign(range2) * 0.01
End If
Dim absStepSize2 As Double = Math.Abs(stepSize2)
' increment/decrement the bars' values until both equal their desired goals,
' sleeping between iterations
If (ProgressBar1.Value = leftGoal) AndAlso (ProgressBar2.Value = rightGoal) Then
Thread.Sleep(tempSampleDelay)
Else
Do
If ProgressBar1.Value <> leftGoal Then
If absStepSize1 < Math.Abs(leftGoal - ProgressBar1.Value) Then
exactValue1 += stepSize1
ProgressBar1.Value = CInt(Math.Truncate(Math.Round(exactValue1)))
'This is the real value
'decibels = 20 * Log10(ProgressBar1.Value/ 32768.0)
Else
ProgressBar1.Value = leftGoal
End If
End If
If ProgressBar2.Value <> rightGoal Then
If absStepSize2 < Math.Abs(rightGoal - ProgressBar2.Value) Then
exactValue2 += stepSize2
ProgressBar2.Value = CInt(Math.Truncate(Math.Round(exactValue2)))
Else
ProgressBar2.Value = rightGoal
End If
End If
Thread.Sleep(tempFrameDelay)
Loop While (ProgressBar1.Value <> leftGoal) OrElse (ProgressBar2.Value <> rightGoal)
End If
End While
End Sub
End Class[/CODE]
Last edited by moti barski; Aug 23rd, 2011 at 03:11 PM.
-
May 19th, 2012, 04:22 PM
#162
Frenzied Member
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.
-
May 24th, 2012, 09:06 AM
#163
Re: Sugestions or Comments about my Sound Tutorial
Originally Posted by Ben321
...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).
-
Jun 21st, 2012, 06:06 AM
#164
Junior Member
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?
-
Jun 21st, 2012, 09:13 AM
#165
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.
-
Jun 21st, 2012, 09:01 PM
#166
Junior Member
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?
-
Jun 22nd, 2012, 03:36 AM
#167
Junior Member
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.
-
Jun 23rd, 2012, 06:17 AM
#168
Junior Member
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.
-
Jul 4th, 2012, 07:56 AM
#169
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.
-
Jul 5th, 2012, 12:12 AM
#170
Junior Member
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.
-
Jul 5th, 2012, 06:51 AM
#171
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).
-
Jan 3rd, 2013, 04:51 AM
#172
Junior Member
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...
-
Oct 20th, 2014, 01:50 PM
#173
New Member
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
-
Sep 12th, 2015, 09:50 PM
#174
Frenzied Member
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.
-
Sep 12th, 2015, 09:56 PM
#175
Re: Sugestions or Comments about my Sound Tutorial
Originally Posted by Ben321
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....
-
Sep 13th, 2015, 01:49 AM
#176
Frenzied Member
Re: Sugestions or Comments about my Sound Tutorial
Originally Posted by CVMichael
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?
-
Sep 13th, 2015, 08:42 AM
#177
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
-
Sep 15th, 2015, 03:40 PM
#178
Frenzied Member
Re: Sugestions or Comments about my Sound Tutorial
Originally Posted by CVMichael
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.
-
Sep 15th, 2015, 04:24 PM
#179
Re: Sugestions or Comments about my Sound Tutorial
Originally Posted by Ben321
... 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!
-
Sep 15th, 2015, 04:35 PM
#180
Frenzied Member
Re: Sugestions or Comments about my Sound Tutorial
Originally Posted by CVMichael
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?
-
Sep 19th, 2015, 05:31 AM
#181
Frenzied Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|