1

I am writing a program to display audio samples on a time/amplitude graph. I want to use the real-time audio playing on the computer and am using WasapiLoopbackCapture from the CSCore library, but the data shows on my graph always seems erroneous.

when I try to read the audio stream buffer with a bit depth of 32, the last byte of the array written to debug in

Debug.WriteLine(BitConverter.ToString(_sample));

is always 3B,3C,3D,3E,BC,BC or BE

I also found that reading the buffer as 32 bit (capture.WaveFormat.BitsPerSample returns 32) appears to show completely erroneous amplitudes on the graph whereas manually setting a bit depth
of 16 and reading the byte array with ReadInt16BigEndian appears to represent each sample somewhat accurately.

capture = new WasapiLoopbackCapture();

_bitDepth = capture.WaveFormat.BitsPerSample;
_byteDepth = bitDepth / 8;

Debug.WriteLine(bitDepth);

capture.DataAvailable += (s, a) =>
    {
        //for loop where i steps through each sample (each sample is multiple bytes)
        for(int i = 0; i < a.Buffer.Length; i += _byteDepth)
        {
            //creates new byte array with 4 bytes / 32 bits
            var _sample = new byte[_byteDepth];

            //copies 1 sample from the buffer into the _sample byte array
            Buffer.BlockCopy(a.Buffer, i, _sample,0,_byteDepth);

            Debug.WriteLine(BitConverter.ToString(_sample));
            
            //reads the byte array to an int
            var _intSample = BinaryPrimitives.ReadInt32BigEndian(_sample);

            currentData.Add(_intSample);
        }
    }; 

1 Answer 1

2

WASAPI uses 32 bit floating point (float) as a sample format. It's not a 32 bit integer.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.