What is Windows Core Audio doing with my mic sound? Why does it look dynamically compressed/expanded?

25 Views Asked by At

I am working on a Windows Core Audio capture application. I am sure it has issues, but it seems to be able to capture sounds. I am plotting the wave form using GDI+.

I am capture sound from a USB audio interface. It is a cheap one. It has a gain control for the microphone. When the gain is 10 a more or less legit wave form is plot. But when the gain is 1, I get a square wave. This is the opposite of what gain does to audio signal, so I am thinking that Windows Core Audio is dynamically compressing/expanding the signal.

Comparison between low and high volume

This page about audio processing modes seems to suggest that yes, that's a possibility and hints that applications cannot directly set the mode. But I want to disable any effect, and access the raw signal. Is there any way to do this with the API or with Windows?

Here is how I am creating the stream, if it helps.

WAVEFORMATEXTENSIBLE wfex;
wfex.Format.cbSize = sizeof(WAVEFORMATEXTENSIBLE);
wfex.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
wfex.Format.nChannels = 2;
wfex.Format.nSamplesPerSec = 44100;
wfex.Format.wBitsPerSample = 16;
wfex.Format.nBlockAlign = wfex.Format.nChannels * wfex.Format.wBitsPerSample / 8;
wfex.Format.nAvgBytesPerSec = wfex.Format.nSamplesPerSec * wfex.Format.nBlockAlign;
wfex.Samples.wValidBitsPerSample = wfex.Format.wBitsPerSample;
wfex.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
wfex.dwChannelMask = 0;

WAVEFORMATEX* pwfx = reinterpret_cast<WAVEFORMATEX*>(&wfex);
WAVEFORMATEX* pWfxout = nullptr;

hr = pAudioClient->IsFormatSupported(
    AUDCLNT_SHAREMODE_EXCLUSIVE,
    pwfx,
    &pWfxout
);

assert(hr == S_OK);

hr = pAudioClient->Initialize(
    AUDCLNT_SHAREMODE_EXCLUSIVE,
    0,
    hnsRequestedDuration,
    0,
    pwfx,
    nullptr);

assert(hr == S_OK);
0

There are 0 best solutions below