Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
MiNT audio driver cleanups for clamping types and channels to supported
Browse files Browse the repository at this point in the history
 values. int32 support now available in one instance.
  • Loading branch information
icculus committed Sep 1, 2006
1 parent c79ee3a commit 8c941da
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 70 deletions.
18 changes: 12 additions & 6 deletions src/audio/mint/SDL_mintaudio_dma8.c
Expand Up @@ -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;

Expand Down Expand Up @@ -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));

Expand Down
108 changes: 74 additions & 34 deletions src/audio/mint/SDL_mintaudio_gsxb.c
Expand Up @@ -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 */
Expand All @@ -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;
}
}

Expand All @@ -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;
}
}

Expand All @@ -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));

Expand All @@ -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;
Expand All @@ -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;
Expand Down
28 changes: 17 additions & 11 deletions src/audio/mint/SDL_mintaudio_mcsn.c
Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
Expand All @@ -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));

Expand All @@ -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;
Expand Down
28 changes: 19 additions & 9 deletions src/audio/mint/SDL_mintaudio_stfa.c
Expand Up @@ -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++) {
Expand All @@ -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));

Expand All @@ -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;
Expand All @@ -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;
Expand Down
26 changes: 16 additions & 10 deletions src/audio/mint/SDL_mintaudio_xbios.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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));

Expand All @@ -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;
Expand Down

0 comments on commit 8c941da

Please sign in to comment.