This project has moved. For the latest updates, please go here.

17640 buffer size

Nov 18, 2013 at 4:52 PM
right now I am getting 17640 samples from this code
 void waveIn_DataAvailable(object sender, WaveInEventArgs e)
        {

            byte[] buffer = e.Buffer;
            int bytesRecorded = e.BytesRecorded;
            buffer1 = new float[bytesRecorded];
            //  WriteToFile(buffer, bytesRecorded);

            for (int index = 0; index < e.BytesRecorded; index += 2)
            {
                short sample = (short)((buffer[index + 1] << 8) |
                                        buffer[index + 0]);
                float sample32 = sample / 32768f;
                buffer1[index] = sample32;
            }
I need to get 2^X samples at a time without losing any samples
so 2^14 is 16384... how can i get 16384 samples at a time with out losing any data?
I just want to take 16384 and run it in to a DSP and then move to the next 16384 samples with out losing any sound data... can this be done?
Coordinator
Nov 19, 2013 at 12:34 PM
If you look through the NAudio demo code, you'll see a class called SampleAggregator which is one way of batching up audio into powers of two so it can be passed into an FFT.
Nov 20, 2013 at 5:22 AM
Markheath

do you mean the VoiceReorder project ?
this ?

namespace VoiceRecorder.Audio
{
    public class SampleAggregator
    {
        // volume
        public event EventHandler<MaxSampleEventArgs> MaximumCalculated;
        public float maxValue;
        public float minValue;
        public int NotificationCount { get; set; }
        int count;

        public SampleAggregator()
        {
        }

        private void Reset()
        {
            count = 0;
            maxValue = minValue = 0;            
        }

        public void Add(float value)
        {
            maxValue = Math.Max(maxValue, value);
            minValue = Math.Min(minValue, value);
            count++;
            if (count >= NotificationCount && NotificationCount > 0)
            {
                if (MaximumCalculated != null)
                {
                    MaximumCalculated(this, new MaxSampleEventArgs(minValue, maxValue));
                }
                Reset();
            }   
        }
    }

    public class MaxSampleEventArgs : EventArgs
    {
        [DebuggerStepThrough]
        public MaxSampleEventArgs(float minValue, float maxValue)
        {
            this.MaxSample = maxValue;
            this.MinSample = minValue;
        }
        public float MaxSample { get; private set; }
        public float MinSample { get; private set; }
    }
}
How do i use it?
Coordinator
Nov 20, 2013 at 9:33 PM