mackron / miniaudio

Audio playback and capture library written in C, in a single source file.
https://miniaud.io
Other
4.07k stars 361 forks source link

Please add ma_format_s24_32 #494

Closed agorangetek closed 2 years ago

agorangetek commented 2 years ago

Hi, I have 2 very popular USB audio devices Both use Int32LSB as native formats. When trying to use Exclusive mode with either ma_format_s24 or ma_format_s32 , I get an error Native Format not supported. Windows reports the bit depth as 24bits in the Audio Control Panel. I guess this requires ma_format_s24_32.

agorangetek commented 2 years ago

for now i fixed it.

if (pWFEX->Samples.wValidBitsPerSample == 24) {
    if (pWFEX->Format.wBitsPerSample == 32) {
        return ma_format_s32;
    }
    if (pWFEX->Format.wBitsPerSample == 24) {
        return ma_format_s24;
    }
}

not sure if its correct but i get clean audio in exclusive mode now.

mackron commented 2 years ago

OK, that's interesting. It sounds like it's not so much a 24_32 format thing, but rather a format misdetection? I'm somewhat surprised though - I assumed that the bit alignment would be incorrect with that change you made. I thought it would look like this:

xxxxxxxx111111111111111111111111

But from your description it sounds like it's laid out like this?:

111111111111111111111111xxxxxxxx

Does the volume sound correct to you? As in it's not super quiet? If it sounds correct for you I can probably apply your change and monitor the feedback from the community, but that bit layout just isn't what I thought.

agorangetek commented 2 years ago

Everything about the sound is the same when I switch between shared and exclusive. I had a quick look through the portaudio wasapi source to see how it handles this and as far as I can see it does not check for a 24_32 format, it treats this as 32bit Int. I'll do some more testing to make sure everything works as expected.

mackron commented 2 years ago

OK, I'm happy to make the change as per your proposal. It sounds like a simple misunderstanding on my part. If it's wrong the community will let me know about it in time. It's in the dev branch now.