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

Adding 16 Bit Stereo , Conversion in WasapiLoopback.

Aug 29, 2013 at 2:37 AM
Could you implement this into the WasapiLoopBack:
        unsafe void WasapiLoopBack(object sender, NAudio.Wave.WaveInEventArgs e)

                    Int32 bytesrecorded = e.BytesRecorded;
                    byte[] newArray16Bit = new byte[bytesrecorded / 2];
                    fixed (byte* sourcePtr = e.Buffer)
                    fixed (byte* targetPtr = newArray16Bit)
                        float* sourceTyped = (float*)sourcePtr;
                        short* targetTyped = (short*)targetPtr;

                        Int32 count = bytesrecorded / 4;
                        for (int i = 0; i < count; i++)
                            targetTyped[i] = (Int16)(sourceTyped[i] * Int16.MaxValue);
It works perfectly, and it´s very fast, would be nice to have it inbuilt to the class somehow.
Sep 7, 2013 at 12:09 AM
Does it actually benefit from the conversion? I am still learning about bit depth and digital audio in general, but if the loopback records the buffer at 8 bit and you convert it to 16 bit doesn't that just increase the potential precision and not actually affect the information in the buffer?
Sep 7, 2013 at 1:42 AM
Not sure where you got 8 bit from. WasapiLoopBack is in Float, 32 Bit. And no inbuilt conversion is available.
And as for most applications, you probably don´t want Float, and 16 bit, or 24 bit.

So this converts it from Float 32bit to 16bit. So there is no benefit in terms of quality, there is probably less quality, but that´s inaudible probably.

If it were in 8 bit, it would be extremely noisy. 16 bit sounds clean and the noise floor is far below what´s audible. 8 bit however has noise no matter what, the noise floor is so high up, that it´s impossible to have any sound audible without hearing the noise probably, at least in all normal scenarios.
Sep 7, 2013 at 1:53 AM
Ah, for some reason I was under the impression WasapiLoopBack recorded at 8 bit.

Thanks for clearing that up.

Just out of curiosity though if you did convert an 8 bit file to 16 bit, would there be any benefit in terms of noise reduction?
Sep 7, 2013 at 1:57 AM
No worries, it´s always good to ask, i do it all the time:)

And no, Quality is always determined by it´s weakest link. Meaning, if it´s 8 bit, it will always have that quality no matter what.

Same with anything really, you can´t improve what isn´t there, or well you can "Enhance" but that isn´t necessarily improving, more like, altering.

But i would recommend you to never work with 8 bit, there is no benefit in it, except, less size for Lossless. You should work with Float, and in the end convert to 16 bit or 24 bit (most likely 16 bit).