Skip to content
Permalink
Browse files

Backport from 1.3: most of the audio drivers can now handle data

 conversion at a higher level when they can't open the hardware in the
 exact format requested.
  • Loading branch information
icculus committed Sep 1, 2006
1 parent dffcce3 commit df846417bb820037fcd0c33834a2667d8c94454a
@@ -220,47 +220,50 @@ static void AHI_CloseAudio(_THIS)

static int AHI_OpenAudio(_THIS, SDL_AudioSpec *spec)
{
// int width;

D(bug("AHI opening...\n"));

/* Determine the audio parameters from the AudioSpec */
switch ( spec->format & 0xFF ) {

case 8: { /* Signed 8 bit audio data */
D(bug("Samples a 8 bit...\n"));
spec->format = AUDIO_S8;
this->hidden->bytespersample=1;
if(spec->channels<2)
this->hidden->type = AHIST_M8S;
else
this->hidden->type = AHIST_S8S;
}
break;

case 16: { /* Signed 16 bit audio data */
D(bug("Samples a 16 bit...\n"));
spec->format = AUDIO_S16MSB;
this->hidden->bytespersample=2;
if(spec->channels<2)
this->hidden->type = AHIST_M16S;
else
this->hidden->type = AHIST_S16S;
}
break;

default: {
SDL_SetError("Unsupported audio format");
return(-1);
}
}

if(spec->channels!=1 && spec->channels!=2)
{
D(bug("Wrong channel number!\n"));
SDL_SetError("Channel number non supported");
return -1;
}
SDL_AudioFormat test_format = SDL_FirstAudioFormat(spec->format);
int valid_datatype = 1;

D(bug("AHI opening...\n"));

/* Determine the audio parameters from the AudioSpec */
while ((!valid_datatype) && (test_format)) {
valid_datatype = 1;
switch (test_format) {
case AUDIO_S8:
D(bug("AUDIO_S8...\n"));
spec->format = AUDIO_S8;
this->hidden->bytespersample = 1;
if (spec->channels < 2)
this->hidden->type = AHIST_M8S;
else
this->hidden->type = AHIST_S8S;
break;

case AUDIO_S16MSB:
D(bug("AUDIO_S16MSB...\n"));
spec->format = AUDIO_S16MSB;
this->hidden->bytespersample = 2;
if (spec->channels < 2)
this->hidden->type = AHIST_M16S;
else
this->hidden->type = AHIST_S16S;
break;

default:
valid_datatype = 0;
test_format = SDL_NextAudioFormat();
break;
}
}

if (!valid_datatype) { /* shouldn't happen, but just in case... */
SDL_SetError("Unsupported audio format");
return (-1);
}

if (spec->channels > 2) {
spec->channels = 2; /* will convert at higher level. */
}

D(bug("Before CalculateAudioSpec\n"));
/* Update the fragment size as size in bytes */
@@ -152,38 +152,55 @@ void BE_CloseAudio(_THIS)

int BE_OpenAudio(_THIS, SDL_AudioSpec *spec)
{
media_raw_audio_format format;
int valid_datatype = 0;
media_raw_audio_format format;
SDL_AudioFormat test_format = SDL_FirstAudioFormat(spec->format);

/* Parse the audio format and fill the Be raw audio format */
memset(&format, '\0', sizeof (media_raw_audio_format));
format.byte_order = B_MEDIA_LITTLE_ENDIAN;
format.frame_rate = (float) spec->freq;
format.channel_count = spec->channels; /* !!! FIXME: support > 2? */
while ((!valid_datatype) && (test_format)) {
valid_datatype = 1;
spec->format = test_format;
switch (test_format) {
case AUDIO_S8:
format.format = media_raw_audio_format::B_AUDIO_CHAR;
break;

case AUDIO_U8:
format.format = media_raw_audio_format::B_AUDIO_UCHAR;
break;

case AUDIO_S16LSB:
format.format = media_raw_audio_format::B_AUDIO_SHORT;
break;

case AUDIO_S16MSB:
format.format = media_raw_audio_format::B_AUDIO_SHORT;
format.byte_order = B_MEDIA_BIG_ENDIAN;
break;

default:
valid_datatype = 0;
test_format = SDL_NextAudioFormat();
break;
}
}

if (!valid_datatype) { /* shouldn't happen, but just in case... */
SDL_SetError("Unsupported audio format");
return (-1);
}

/* Initialize the Be Application, if it's not already started */
if (SDL_InitBeApp() < 0) {
return (-1);
}

format.buffer_size = spec->samples;

/* Initialize the Be Application, if it's not already started */
if ( SDL_InitBeApp() < 0 ) {
return(-1);
}

/* Parse the audio format and fill the Be raw audio format */
format.frame_rate = (float)spec->freq;
format.channel_count = spec->channels;
switch (spec->format&~0x1000) {
case AUDIO_S8:
/* Signed 8-bit audio unsupported, convert to U8 */
spec->format = AUDIO_U8;
case AUDIO_U8:
format.format = media_raw_audio_format::B_AUDIO_UCHAR;
format.byte_order = 0;
break;
case AUDIO_U16:
/* Unsigned 16-bit audio unsupported, convert to S16 */
spec->format ^= 0x8000;
case AUDIO_S16:
format.format = media_raw_audio_format::B_AUDIO_SHORT;
if ( spec->format & 0x1000 ) {
format.byte_order = 1; /* Big endian */
} else {
format.byte_order = 2; /* Little endian */
}
break;
}
format.buffer_size = spec->samples;

/* Calculate the final parameters for this audio specification */
SDL_CalculateAudioSpec(spec);

@@ -75,6 +75,8 @@ LONG APIENTRY DARTEventFunc(ULONG ulStatus,

int DART_OpenAudio(_THIS, SDL_AudioSpec *spec)
{
SDL_AudioFormat test_format = SDL_FirstAudioFormat(spec->format);
int valid_datatype = 0;
MCI_AMP_OPEN_PARMS AmpOpenParms;
MCI_GENERIC_PARMS GenericParms;
int iDeviceOrd = 0; // Default device to be used
@@ -106,26 +108,39 @@ int DART_OpenAudio(_THIS, SDL_AudioSpec *spec)
iDeviceOrd = AmpOpenParms.usDeviceID;

// Determine the audio parameters from the AudioSpec
switch ( spec->format & 0xFF )
{
case 8:
/* Unsigned 8 bit audio data */
spec->format = AUDIO_U8;
if (spec->channels > 2)
spec->channels = 2; // !!! FIXME: more than stereo support in OS/2?

while ((!valid_datatype) && (test_format)) {
spec->format = test_format;
valid_datatype = 1;
switch (test_format) {
case AUDIO_U8:
// Unsigned 8 bit audio data
iSilence = 0x80;
iBits = 8;
break;
case 16:
/* Signed 16 bit audio data */
spec->format = AUDIO_S16;

case AUDIO_S16LSB:
// Signed 16 bit audio data
iSilence = 0x00;
iBits = 16;
break;
default:
// Close DART, and exit with error code!
mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0);
SDL_SetError("Unsupported audio format");
return(-1);

default:
valid_datatype = 0;
test_format = SDL_NextAudioFormat();
break;
}
}

if (!valid_datatype) { // shouldn't happen, but just in case...
// Close DART, and exit with error code!
mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0);
SDL_SetError("Unsupported audio format");
return (-1);
}

iFreq = spec->freq;
iChannels = spec->channels;
/* Update the fragment size as size in bytes */
@@ -201,13 +201,30 @@ static void DCAUD_CloseAudio(_THIS)

static int DCAUD_OpenAudio(_THIS, SDL_AudioSpec *spec)
{
switch(spec->format&0xff) {
case 8: spec->format = AUDIO_S8; break;
case 16: spec->format = AUDIO_S16LSB; break;
default:
SDL_SetError("Unsupported audio format");
return(-1);
}
SDL_AudioFormat test_format = SDL_FirstAudioFormat(spec->format);
int valid_datatype = 0;
while ((!valid_datatype) && (test_format)) {
spec->format = test_format;
switch (test_format) {
/* only formats Dreamcast accepts... */
case AUDIO_S8:
case AUDIO_S16LSB:
valid_datatype = 1;
break;

default:
test_format = SDL_NextAudioFormat();
break;
}
}

if (!valid_datatype) { /* shouldn't happen, but just in case... */
SDL_SetError("Unsupported audio format");
return (-1);
}

if (spec->channels > 2)
spec->channels = 2; /* no more than stereo on the Dreamcast. */

/* Update the fragment size as size in bytes */
SDL_CalculateAudioSpec(spec);

0 comments on commit df84641

Please sign in to comment.