creating a circular array
-
Hello, VS 2008 I am filling the buffer with the read method in the code below, using SlimDX to capture the audio input from the microphone. The problem I have is that the buffer will overrun. It there anyway to create a circuler buffer that once it gets to the the end it will start over again? Many thanks for any suggestions,
private void bgwAudioInput_DoWork(object sender, DoWorkEventArgs e)
{
Int16[] samples = new Int16[8192 / sizeof(Int16)];
Int16 audioValue = 0;
int i = 0;
captureBuff.Start(true);while (captureAudio) { if (!this.bgwAudioInput.CancellationPending) { captureBuff.Read(samples, 0, true); audioValue = Math.Abs(samples\[i++\]); this.bgwAudioInput.ReportProgress(audioValue); } }
}
-
Hello, VS 2008 I am filling the buffer with the read method in the code below, using SlimDX to capture the audio input from the microphone. The problem I have is that the buffer will overrun. It there anyway to create a circuler buffer that once it gets to the the end it will start over again? Many thanks for any suggestions,
private void bgwAudioInput_DoWork(object sender, DoWorkEventArgs e)
{
Int16[] samples = new Int16[8192 / sizeof(Int16)];
Int16 audioValue = 0;
int i = 0;
captureBuff.Start(true);while (captureAudio) { if (!this.bgwAudioInput.CancellationPending) { captureBuff.Read(samples, 0, true); audioValue = Math.Abs(samples\[i++\]); this.bgwAudioInput.ReportProgress(audioValue); } }
}
Hi,
Steve1_rm wrote:
The problem I have is that the buffer will overrun
Are you sure about that? It looks to me as if you are attempting to read beyond the end of the array. Every iteration of the while loop reads data into the samples array. That's ok but eventually the indexer i has the value 4096 and the array access in the line
audioValue = Math.Abs(samples[i++]);
will fail. I can't understand the meaning of audioValue and how it would relate to progress. Did you mean to report total amount of data read perhaps? Alan. -
Hello, VS 2008 I am filling the buffer with the read method in the code below, using SlimDX to capture the audio input from the microphone. The problem I have is that the buffer will overrun. It there anyway to create a circuler buffer that once it gets to the the end it will start over again? Many thanks for any suggestions,
private void bgwAudioInput_DoWork(object sender, DoWorkEventArgs e)
{
Int16[] samples = new Int16[8192 / sizeof(Int16)];
Int16 audioValue = 0;
int i = 0;
captureBuff.Start(true);while (captureAudio) { if (!this.bgwAudioInput.CancellationPending) { captureBuff.Read(samples, 0, true); audioValue = Math.Abs(samples\[i++\]); this.bgwAudioInput.ReportProgress(audioValue); } }
}