Mercurial > sdl-ios-xcode
comparison src/audio/dart/SDL_dart.c @ 3851:405a192b68e7 SDL-1.2
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.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Fri, 01 Sep 2006 22:50:24 +0000 |
parents | d910939febfa |
children | 5b5e549382b3 |
comparison
equal
deleted
inserted
replaced
3850:28db418c7573 | 3851:405a192b68e7 |
---|---|
73 } | 73 } |
74 | 74 |
75 | 75 |
76 int DART_OpenAudio(_THIS, SDL_AudioSpec *spec) | 76 int DART_OpenAudio(_THIS, SDL_AudioSpec *spec) |
77 { | 77 { |
78 SDL_AudioFormat test_format = SDL_FirstAudioFormat(spec->format); | |
79 int valid_datatype = 0; | |
78 MCI_AMP_OPEN_PARMS AmpOpenParms; | 80 MCI_AMP_OPEN_PARMS AmpOpenParms; |
79 MCI_GENERIC_PARMS GenericParms; | 81 MCI_GENERIC_PARMS GenericParms; |
80 int iDeviceOrd = 0; // Default device to be used | 82 int iDeviceOrd = 0; // Default device to be used |
81 int bOpenShared = 1; // Try opening it shared | 83 int bOpenShared = 1; // Try opening it shared |
82 int iBits = 16; // Default is 16 bits signed | 84 int iBits = 16; // Default is 16 bits signed |
104 // Save the device ID we got from DART! | 106 // Save the device ID we got from DART! |
105 // We will use this in the next calls! | 107 // We will use this in the next calls! |
106 iDeviceOrd = AmpOpenParms.usDeviceID; | 108 iDeviceOrd = AmpOpenParms.usDeviceID; |
107 | 109 |
108 // Determine the audio parameters from the AudioSpec | 110 // Determine the audio parameters from the AudioSpec |
109 switch ( spec->format & 0xFF ) | 111 if (spec->channels > 2) |
110 { | 112 spec->channels = 2; // !!! FIXME: more than stereo support in OS/2? |
111 case 8: | 113 |
112 /* Unsigned 8 bit audio data */ | 114 while ((!valid_datatype) && (test_format)) { |
113 spec->format = AUDIO_U8; | 115 spec->format = test_format; |
116 valid_datatype = 1; | |
117 switch (test_format) { | |
118 case AUDIO_U8: | |
119 // Unsigned 8 bit audio data | |
114 iSilence = 0x80; | 120 iSilence = 0x80; |
115 iBits = 8; | 121 iBits = 8; |
116 break; | 122 break; |
117 case 16: | 123 |
118 /* Signed 16 bit audio data */ | 124 case AUDIO_S16LSB: |
119 spec->format = AUDIO_S16; | 125 // Signed 16 bit audio data |
120 iSilence = 0x00; | 126 iSilence = 0x00; |
121 iBits = 16; | 127 iBits = 16; |
122 break; | 128 break; |
123 default: | 129 |
124 // Close DART, and exit with error code! | 130 default: |
125 mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0); | 131 valid_datatype = 0; |
126 SDL_SetError("Unsupported audio format"); | 132 test_format = SDL_NextAudioFormat(); |
127 return(-1); | 133 break; |
128 } | 134 } |
135 } | |
136 | |
137 if (!valid_datatype) { // shouldn't happen, but just in case... | |
138 // Close DART, and exit with error code! | |
139 mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0); | |
140 SDL_SetError("Unsupported audio format"); | |
141 return (-1); | |
142 } | |
143 | |
129 iFreq = spec->freq; | 144 iFreq = spec->freq; |
130 iChannels = spec->channels; | 145 iChannels = spec->channels; |
131 /* Update the fragment size as size in bytes */ | 146 /* Update the fragment size as size in bytes */ |
132 SDL_CalculateAudioSpec(spec); | 147 SDL_CalculateAudioSpec(spec); |
133 iBufSize = spec->size; | 148 iBufSize = spec->size; |