ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/Unix/audio_oss_esd.cpp
(Generate patch)

Comparing BasiliskII/src/Unix/audio_oss_esd.cpp (file contents):
Revision 1.7 by cebix, 2001-07-05T20:30:51Z vs.
Revision 1.11 by gbeauche, 2001-07-15T05:40:12Z

# Line 60 | Line 60 | static int audio_channel_count_index = 0
60   // Global variables
61   static int audio_fd = -1;                                                       // fd of /dev/dsp or ESD
62   static int mixer_fd = -1;                                                       // fd of /dev/mixer
63 static bool formats_known = false;                                      // Flag: available audio formats have been probed
63   static sem_t audio_irq_done_sem;                                        // Signal from interrupt to streaming thread: data block read
64   static bool sem_inited = false;                                         // Flag: audio_irq_done_sem initialized
65   static int sound_buffer_size;                                           // Size of sound buffer in bytes
# Line 100 | Line 99 | static bool open_dsp(void)
99          printf("Using " DSP_NAME " audio output\n");
100  
101          // Get supported sample formats
102 <        if (!formats_known) {
102 >        if (audio_sample_sizes.empty()) {
103                  unsigned long format;
104                  ioctl(audio_fd, SNDCTL_DSP_GETFMTS, &format);
105                  if (format & AFMT_U8)
# Line 133 | Line 132 | static bool open_dsp(void)
132                  audio_sample_rate_index = audio_sample_rates.size() - 1;
133                  audio_sample_size_index = audio_sample_sizes.size() - 1;
134                  audio_channel_count_index = audio_channel_counts.size() - 1;
136                formats_known = true;
135          }
136  
137          // Set DSP parameters
# Line 144 | Line 142 | static bool open_dsp(void)
142                  silence_byte = 0x80;
143          } else {
144                  unsigned long sup_format;
145 <                ioctl(audio_fd, SNDCTL_DSP_GETFMTS, &format);
145 >                ioctl(audio_fd, SNDCTL_DSP_GETFMTS, &sup_format);
146                  if (sup_format & AFMT_S16_BE) {
147                          little_endian = false;
148                          format = AFMT_S16_BE;
# Line 172 | Line 170 | static bool open_dsp(void)
170   static bool open_esd(void)
171   {
172   #ifdef ENABLE_ESD
173 <        // ESD supports a variety of audio formats
174 <        if (!formats_known) {
177 <                audio_sample_rates.push_back(11025 << 16);
178 <                audio_sample_rates.push_back(22050 << 16);
179 <                audio_sample_rates.push_back(44100 << 16);
180 <                audio_sample_sizes.push_back(8);
181 <                audio_sample_sizes.push_back(16);
182 <                audio_channel_counts.push_back(1);
183 <                audio_channel_counts.push_back(2);
173 >        int rate;
174 >        esd_format_t format = ESD_STREAM | ESD_PLAY;
175  
176 <                // Default to 44.1kHz, 16-bit, stereo
186 <                audio_sample_rate_index = 2;
187 <                audio_sample_size_index = 1;
188 <                audio_channel_count_index = 1;
189 <                formats_known = true;
190 <        }
176 >        if (audio_sample_sizes.empty()) {
177  
178 <        // ESD audio format
179 <        esd_format_t format = ESD_STREAM | ESD_PLAY;
180 <        if (audio_sample_sizes[audio_sample_size_index] == 8)
181 <                format |= ESD_BITS8;
182 <        else
183 <                format |= ESD_BITS16;
184 <        if (audio_channel_counts[audio_channel_count_index] == 1)
185 <                format |= ESD_MONO;
186 <        else
187 <                format |= ESD_STEREO;
178 >                // Default values
179 >                rate = 44100;
180 >                format |= (ESD_BITS16 | ESD_STEREO);
181 >
182 >        } else {
183 >
184 >                rate = audio_sample_rates[audio_sample_rate_index] >> 16;
185 >                if (audio_sample_sizes[audio_sample_size_index] == 8)
186 >                        format |= ESD_BITS8;
187 >                else
188 >                        format |= ESD_BITS16;
189 >                if (audio_channel_counts[audio_channel_count_index] == 1)
190 >                        format |= ESD_MONO;
191 >                else
192 >                        format |= ESD_STEREO;
193 >        }
194  
195   #if WORDS_BIGENDIAN
196          little_endian = false;
# Line 208 | Line 200 | static bool open_esd(void)
200          silence_byte = 0;       // Is this correct for 8-bit mode?
201  
202          // Open connection to ESD server
203 <        audio_fd = esd_play_stream(format, audio_sample_rates[audio_sample_rate_index] >> 16, NULL, NULL);
203 >        audio_fd = esd_play_stream(format, rate, NULL, NULL);
204          if (audio_fd < 0) {
205                  fprintf(stderr, "WARNING: Cannot open ESD connection\n");
214                formats_known = false;
206                  return false;
207          }
208  
209          printf("Using ESD audio output\n");
210  
211 +        // ESD supports a variety of twisted little audio formats, all different
212 +        if (audio_sample_sizes.empty()) {
213 +
214 +                // The reason we do this here is that we don't want to add sample
215 +                // rates etc. unless the ESD server connection could be opened
216 +                // (if ESD fails, /dev/dsp might be tried next)
217 +                audio_sample_rates.push_back(11025 << 16);
218 +                audio_sample_rates.push_back(22050 << 16);
219 +                audio_sample_rates.push_back(44100 << 16);
220 +                audio_sample_sizes.push_back(8);
221 +                audio_sample_sizes.push_back(16);
222 +                audio_channel_counts.push_back(1);
223 +                audio_channel_counts.push_back(2);
224 +
225 +                // Default to highest supported values
226 +                audio_sample_rate_index = audio_sample_rates.size() - 1;
227 +                audio_sample_size_index = audio_sample_sizes.size() - 1;
228 +                audio_channel_count_index = audio_channel_counts.size() - 1;
229 +        }
230 +
231          // Sound buffer size = 4096 frames
232          audio_frames_per_block = 4096;
233          return true;
234 + #else
235 +        // ESD is not enabled, shut up the compiler
236 +        return false;
237   #endif
238   }
239  
# Line 273 | Line 287 | dev_opened:
287  
288   void AudioInit(void)
289   {
276        char str[256];
277
290          // Init audio status (reasonable defaults) and feature flags
291          AudioStatus.sample_rate = 44100 << 16;
292          AudioStatus.sample_size = 16;
# Line 329 | Line 341 | static void close_audio(void)
341  
342   void AudioExit(void)
343   {
344 +        // Close audio device
345 +        close_audio();
346 +
347 +        // Delete semaphore
348          if (sem_inited) {
349                  sem_destroy(&audio_irq_done_sem);
350                  sem_inited = false;
# Line 366 | Line 382 | void audio_exit_stream()
382   *  Streaming function
383   */
384  
369 static uint32 apple_stream_info;        // Mac address of SoundComponentData struct describing next buffer
370
385   static void *stream_func(void *arg)
386   {
387          int16 *silent_buffer = new int16[sound_buffer_size / 2];

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines