From 8c941dabf17cc10ed54fcd317be5d19f92f11830 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Fri, 1 Sep 2006 06:32:54 +0000 Subject: [PATCH] MiNT audio driver cleanups for clamping types and channels to supported values. int32 support now available in one instance. --- src/audio/mint/SDL_mintaudio_dma8.c | 18 +++-- src/audio/mint/SDL_mintaudio_gsxb.c | 108 ++++++++++++++++++--------- src/audio/mint/SDL_mintaudio_mcsn.c | 28 ++++--- src/audio/mint/SDL_mintaudio_stfa.c | 28 ++++--- src/audio/mint/SDL_mintaudio_xbios.c | 26 ++++--- 5 files changed, 138 insertions(+), 70 deletions(-) diff --git a/src/audio/mint/SDL_mintaudio_dma8.c b/src/audio/mint/SDL_mintaudio_dma8.c index a6c6bec09..04afa8c04 100644 --- a/src/audio/mint/SDL_mintaudio_dma8.c +++ b/src/audio/mint/SDL_mintaudio_dma8.c @@ -218,12 +218,17 @@ Mint_CheckAudio(_THIS, SDL_AudioSpec * spec) int i, masterprediv, sfreq; unsigned long masterclock; - DEBUG_PRINT((DEBUG_NAME "asked: %d bits, ", spec->format & 0x00ff)); - DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000) != 0))); - DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000) != 0))); + DEBUG_PRINT((DEBUG_NAME "asked: %d bits, ", SDL_AUDIO_BITSIZE(spec->format))); + DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(spec->format))); + DEBUG_PRINT(("signed=%d, ", SDL_AUDIO_ISSIGNED(spec->format))); + DEBUG_PRINT(("big endian=%d, ", SDL_AUDIO_ISBIGENDIAN(spec->format))); DEBUG_PRINT(("channels=%d, ", spec->channels)); DEBUG_PRINT(("freq=%d\n", spec->freq)); + if (spec->channels > 2) { + spec->channels = 2; /* no more than stereo! */ + } + /* Check formats available */ spec->format = AUDIO_S8; @@ -269,9 +274,10 @@ Mint_CheckAudio(_THIS, SDL_AudioSpec * spec) MINTAUDIO_numfreq = SDL_MintAudio_SearchFrequency(this, spec->freq); spec->freq = MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency; - DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ", spec->format & 0x00ff)); - DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000) != 0))); - DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000) != 0))); + DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ", SDL_AUDIO_BITSIZE(spec->format))); + DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(spec->format))); + DEBUG_PRINT(("signed=%d, ", SDL_AUDIO_ISSIGNED(spec->format))); + DEBUG_PRINT(("big endian=%d, ", SDL_AUDIO_ISBIGENDIAN(spec->format))); DEBUG_PRINT(("channels=%d, ", spec->channels)); DEBUG_PRINT(("freq=%d\n", spec->freq)); diff --git a/src/audio/mint/SDL_mintaudio_gsxb.c b/src/audio/mint/SDL_mintaudio_gsxb.c index 4cad66b8f..3475007f3 100644 --- a/src/audio/mint/SDL_mintaudio_gsxb.c +++ b/src/audio/mint/SDL_mintaudio_gsxb.c @@ -208,38 +208,70 @@ Mint_CheckAudio(_THIS, SDL_AudioSpec * spec) { long snd_format; int i, resolution, format_signed, format_bigendian; + SDL_AudioFormat test_format = SDL_FirstAudioFormat(spec->format); + int valid_datatype = 0; - resolution = spec->format & 0x00ff; - format_signed = ((spec->format & 0x8000) != 0); - format_bigendian = ((spec->format & 0x1000) != 0); + resolution = SDL_AUDIO_BITSIZE(spec->format); + format_signed = SDL_AUDIO_ISSIGNED(spec->format); + format_bigendian = SDL_AUDIO_ISBIGENDIAN(spec->format); - DEBUG_PRINT((DEBUG_NAME "asked: %d bits, ", spec->format & 0x00ff)); - DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000) != 0))); - DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000) != 0))); + DEBUG_PRINT((DEBUG_NAME "asked: %d bits, ", resolution)); + DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(spec->format))); + DEBUG_PRINT(("signed=%d, ", format_signed)); + DEBUG_PRINT(("big endian=%d, ", format_bigendian)); DEBUG_PRINT(("channels=%d, ", spec->channels)); DEBUG_PRINT(("freq=%d\n", spec->freq)); - /* Check formats available */ - snd_format = Sndstatus(SND_QUERYFORMATS); - switch (resolution) { - case 8: - if ((snd_format & SND_FORMAT8) == 0) { - SDL_SetError("Mint_CheckAudio: 8 bits samples not supported"); - return -1; - } - snd_format = Sndstatus(SND_QUERY8BIT); - break; - case 16: - if ((snd_format & SND_FORMAT16) == 0) { - SDL_SetError("Mint_CheckAudio: 16 bits samples not supported"); - return -1; + if (spec->channels > 2) { + spec->channels = 2; /* no more than stereo! */ + } + + while ((!valid_datatype) && (test_format)) { + spec->format = test_format; + switch (test_format) { + case AUDIO_U8: + case AUDIO_S8: + case AUDIO_U16LSB: + case AUDIO_S16LSB: + case AUDIO_U16MSB: + case AUDIO_S16MSB: + case AUDIO_S32LSB: + case AUDIO_S32MSB: + /* no float support... */ + resolution = SDL_AUDIO_BITSIZE(spec->format); + format_signed = SDL_AUDIO_ISSIGNED(spec->format); + format_bigendian = SDL_AUDIO_ISBIGENDIAN(spec->format); + + /* Check formats available */ + snd_format = Sndstatus(SND_QUERYFORMATS); + switch (resolution) { + case 8: + if (snd_format & SND_FORMAT8) { + valid_datatype = 1; + snd_format = Sndstatus(SND_QUERY8BIT); + } + break; + case 16: + if (snd_format & SND_FORMAT16) { + valid_datatype = 1; + snd_format = Sndstatus(SND_QUERY16BIT); + } + break; + case 32: + if (snd_format & SND_FORMAT32) { + valid_datatype = 1; + snd_format = Sndstatus(SND_QUERY32BIT); + } + break; + } + + break; } - snd_format = Sndstatus(SND_QUERY16BIT); - break; - default: - SDL_SetError("Mint_CheckAudio: Unsupported sample resolution"); - return -1; - break; + } + + if (!valid_datatype) { + SDL_SetError("Unsupported audio format"); + return (-1); } /* Check signed/unsigned format */ @@ -248,14 +280,14 @@ Mint_CheckAudio(_THIS, SDL_AudioSpec * spec) /* Ok */ } else if (snd_format & SND_FORMATUNSIGNED) { /* Give unsigned format */ - spec->format = spec->format & (~0x8000); + spec->format = spec->format & (~SDL_AUDIO_MASK_SIGNED); } } else { if (snd_format & SND_FORMATUNSIGNED) { /* Ok */ } else if (snd_format & SND_FORMATSIGNED) { /* Give signed format */ - spec->format |= 0x8000; + spec->format |= SDL_AUDIO_MASK_SIGNED; } } @@ -264,14 +296,14 @@ Mint_CheckAudio(_THIS, SDL_AudioSpec * spec) /* Ok */ } else if (snd_format & SND_FORMATLITTLEENDIAN) { /* Give little endian format */ - spec->format = spec->format & (~0x1000); + spec->format = spec->format & (~SDL_AUDIO_MASK_ENDIAN); } } else { if (snd_format & SND_FORMATLITTLEENDIAN) { /* Ok */ } else if (snd_format & SND_FORMATBIGENDIAN) { /* Give big endian format */ - spec->format |= 0x1000; + spec->format |= SDL_AUDIO_MASK_ENDIAN; } } @@ -296,9 +328,10 @@ Mint_CheckAudio(_THIS, SDL_AudioSpec * spec) MINTAUDIO_numfreq = SDL_MintAudio_SearchFrequency(this, spec->freq); spec->freq = MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency; - DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ", spec->format & 0x00ff)); - DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000) != 0))); - DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000) != 0))); + DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ", SDL_AUDIO_BITSIZE(spec->format))); + DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(spec->format))); + DEBUG_PRINT(("signed=%d, ", SDL_AUDIO_ISSIGNED(spec->format))); + DEBUG_PRINT(("big endian=%d, ", SDL_AUDIO_ISBIGENDIAN(spec->format))); DEBUG_PRINT(("channels=%d, ", spec->channels)); DEBUG_PRINT(("freq=%d\n", spec->freq)); @@ -319,7 +352,7 @@ Mint_InitAudio(_THIS, SDL_AudioSpec * spec) Setmontracks(0); /* Select replay format */ - switch (spec->format & 0xff) { + switch (SDL_AUDIO_BITSIZE(spec->format)) { case 8: if (spec->channels == 2) { channels_mode = STEREO8; @@ -334,6 +367,13 @@ Mint_InitAudio(_THIS, SDL_AudioSpec * spec) channels_mode = MONO16; } break; + case 32: + if (spec->channels == 2) { + channels_mode = STEREO32; + } else { + channels_mode = MONO32; + } + break; default: channels_mode = STEREO16; break; diff --git a/src/audio/mint/SDL_mintaudio_mcsn.c b/src/audio/mint/SDL_mintaudio_mcsn.c index 64e2cf7d0..e043fa295 100644 --- a/src/audio/mint/SDL_mintaudio_mcsn.c +++ b/src/audio/mint/SDL_mintaudio_mcsn.c @@ -225,18 +225,23 @@ Mint_CheckAudio(_THIS, SDL_AudioSpec * spec) int i; unsigned long masterclock, masterprediv; - DEBUG_PRINT((DEBUG_NAME "asked: %d bits, ", spec->format & 0x00ff)); - DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000) != 0))); - DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000) != 0))); + DEBUG_PRINT((DEBUG_NAME "asked: %d bits, ", SDL_AUDIO_BITSIZE(spec->format))); + DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(spec->format))); + DEBUG_PRINT(("signed=%d, ", SDL_AUDIO_ISSIGNED(spec->format))); + DEBUG_PRINT(("big endian=%d, ", SDL_AUDIO_ISBIGENDIAN(spec->format))); DEBUG_PRINT(("channels=%d, ", spec->channels)); DEBUG_PRINT(("freq=%d\n", spec->freq)); + if (spec->channels > 2) { + spec->channels = 2; /* no more than stereo! */ + } + /* Check formats available */ MINTAUDIO_freqcount = 0; switch (cookie_mcsn->play) { case MCSN_ST: spec->channels = 1; - spec->format = 8; /* FIXME: is it signed or unsigned ? */ + spec->format = AUDIO_S8; /* FIXME: is it signed or unsigned ? */ SDL_MintAudio_AddFrequency(this, 12500, 0, 0, -1); break; case MCSN_TT: /* Also STE, Mega STE */ @@ -274,9 +279,9 @@ Mint_CheckAudio(_THIS, SDL_AudioSpec * spec) (1 << i) - 1, -1); } } - spec->format |= 0x8000; /* Audio is always signed */ - if ((spec->format & 0x00ff) == 16) { - spec->format |= 0x1000; /* Audio is always big endian */ + spec->format |= SDL_AUDIO_MASK_SIGNED; /* Audio is always signed */ + if ((SDL_AUDIO_BITSIZE(spec->format)) == 16) { + spec->format |= SDL_AUDIO_MASK_ENDIAN; /* Audio is always big endian */ spec->channels = 2; /* 16 bits always stereo */ } break; @@ -294,9 +299,10 @@ Mint_CheckAudio(_THIS, SDL_AudioSpec * spec) MINTAUDIO_numfreq = SDL_MintAudio_SearchFrequency(this, spec->freq); spec->freq = MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency; - DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ", spec->format & 0x00ff)); - DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000) != 0))); - DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000) != 0))); + DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ", SDL_AUDIO_BITSIZE(spec->format))); + DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(spec->format))); + DEBUG_PRINT(("signed=%d, ", SDL_AUDIO_ISSIGNED(spec->format))); + DEBUG_PRINT(("big endian=%d, ", SDL_AUDIO_ISBIGENDIAN(spec->format))); DEBUG_PRINT(("channels=%d, ", spec->channels)); DEBUG_PRINT(("freq=%d\n", spec->freq)); @@ -321,7 +327,7 @@ Mint_InitAudio(_THIS, SDL_AudioSpec * spec) /* Select replay format */ channels_mode = STEREO16; - switch (spec->format & 0xff) { + switch (SDL_AUDIO_BITSIZE(spec->format)) { case 8: if (spec->channels == 2) { channels_mode = STEREO8; diff --git a/src/audio/mint/SDL_mintaudio_stfa.c b/src/audio/mint/SDL_mintaudio_stfa.c index 393cfb1e5..2b10a009f 100644 --- a/src/audio/mint/SDL_mintaudio_stfa.c +++ b/src/audio/mint/SDL_mintaudio_stfa.c @@ -206,12 +206,21 @@ Mint_CheckAudio(_THIS, SDL_AudioSpec * spec) { int i; - DEBUG_PRINT((DEBUG_NAME "asked: %d bits, ", spec->format & 0x00ff)); - DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000) != 0))); - DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000) != 0))); + DEBUG_PRINT((DEBUG_NAME "asked: %d bits, ", SDL_AUDIO_BITSIZE(spec->format))); + DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(spec->format))); + DEBUG_PRINT(("signed=%d, ", SDL_AUDIO_ISSIGNED(spec->format))); + DEBUG_PRINT(("big endian=%d, ", SDL_AUDIO_ISBIGENDIAN(spec->format))); DEBUG_PRINT(("channels=%d, ", spec->channels)); DEBUG_PRINT(("freq=%d\n", spec->freq)); + if (SDL_AUDIO_BITSIZE(spec->format) > 16) { + spec->format = AUDIO_S16SYS; /* clamp out int32/float32 ... */ + } + + if (spec->channels > 2) { + spec->channels = 2; /* no more than stereo! */ + } + /* Check formats available */ MINTAUDIO_freqcount = 0; for (i = 0; i < 16; i++) { @@ -230,9 +239,10 @@ Mint_CheckAudio(_THIS, SDL_AudioSpec * spec) MINTAUDIO_numfreq = SDL_MintAudio_SearchFrequency(this, spec->freq); spec->freq = MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency; - DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ", spec->format & 0x00ff)); - DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000) != 0))); - DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000) != 0))); + DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ", SDL_AUDIO_BITSIZE(spec->format))); + DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(spec->format))); + DEBUG_PRINT(("signed=%d, ", SDL_AUDIO_ISSIGNED(spec->format))); + DEBUG_PRINT(("big endian=%d, ", SDL_AUDIO_ISBIGENDIAN(spec->format))); DEBUG_PRINT(("channels=%d, ", spec->channels)); DEBUG_PRINT(("freq=%d\n", spec->freq)); @@ -255,7 +265,7 @@ Mint_InitAudio(_THIS, SDL_AudioSpec * spec) /* Select replay format */ cookie_stfa->sound_control = MINTAUDIO_frequencies[MINTAUDIO_numfreq].predivisor; - if ((spec->format & 0xff) == 8) { + if (SDL_AUDIO_BITSIZE(spec->format) == 8) { cookie_stfa->sound_control |= STFA_FORMAT_8BIT; } else { cookie_stfa->sound_control |= STFA_FORMAT_16BIT; @@ -265,12 +275,12 @@ Mint_InitAudio(_THIS, SDL_AudioSpec * spec) } else { cookie_stfa->sound_control |= STFA_FORMAT_MONO; } - if ((spec->format & 0x8000) != 0) { + if (SDL_AUDIO_ISSIGNED(spec->format) != 0) { cookie_stfa->sound_control |= STFA_FORMAT_SIGNED; } else { cookie_stfa->sound_control |= STFA_FORMAT_UNSIGNED; } - if ((spec->format & 0x1000) != 0) { + if (SDL_AUDIO_ISBIGENDIAN(spec->format) != 0) { cookie_stfa->sound_control |= STFA_FORMAT_BIGENDIAN; } else { cookie_stfa->sound_control |= STFA_FORMAT_LITENDIAN; diff --git a/src/audio/mint/SDL_mintaudio_xbios.c b/src/audio/mint/SDL_mintaudio_xbios.c index c7e7f0b3b..a9393e7af 100644 --- a/src/audio/mint/SDL_mintaudio_xbios.c +++ b/src/audio/mint/SDL_mintaudio_xbios.c @@ -359,16 +359,21 @@ Mint_CheckAudio(_THIS, SDL_AudioSpec * spec) int i; Uint32 extclock; - DEBUG_PRINT((DEBUG_NAME "asked: %d bits, ", spec->format & 0x00ff)); - DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000) != 0))); - DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000) != 0))); + DEBUG_PRINT((DEBUG_NAME "asked: %d bits, ", SDL_AUDIO_BITSIZE(spec->format))); + DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(spec->format))); + DEBUG_PRINT(("signed=%d, ", SDL_AUDIO_ISSIGNED(spec->format))); + DEBUG_PRINT(("big endian=%d, ", SDL_AUDIO_ISBIGENDIAN(spec->format))); DEBUG_PRINT(("channels=%d, ", spec->channels)); DEBUG_PRINT(("freq=%d\n", spec->freq)); - spec->format |= 0x8000; /* Audio is always signed */ - if ((spec->format & 0x00ff) == 16) { - spec->format |= 0x1000; /* Audio is always big endian */ + spec->format |= SDL_AUDIO_MASK_SIGNED; /* Audio is always signed */ + + /* clamp out int32/float32 */ + if (SDL_AUDIO_BITSIZE(spec->format) >= 16) { + spec->format = AUDIO_S16MSB; /* Audio is always big endian */ spec->channels = 2; /* 16 bits always stereo */ + } else if (spec->channels > 2) { + spec->channels = 2; /* no more than stereo! */ } MINTAUDIO_freqcount = 0; @@ -400,9 +405,10 @@ Mint_CheckAudio(_THIS, SDL_AudioSpec * spec) MINTAUDIO_numfreq = SDL_MintAudio_SearchFrequency(this, spec->freq); spec->freq = MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency; - DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ", spec->format & 0x00ff)); - DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000) != 0))); - DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000) != 0))); + DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ", SDL_AUDIO_BITSIZE(spec->format))); + DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(spec->format))); + DEBUG_PRINT(("signed=%d, ", SDL_AUDIO_ISSIGNED(spec->format))); + DEBUG_PRINT(("big endian=%d, ", SDL_AUDIO_ISBIGENDIAN(spec->format))); DEBUG_PRINT(("channels=%d, ", spec->channels)); DEBUG_PRINT(("freq=%d\n", spec->freq)); @@ -427,7 +433,7 @@ Mint_InitAudio(_THIS, SDL_AudioSpec * spec) /* Select replay format */ channels_mode = STEREO16; - switch (spec->format & 0xff) { + switch (SDL_AUDIO_BITSIZE(spec->format)) { case 8: if (spec->channels == 2) { channels_mode = STEREO8;