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 |
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) |
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 |
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; |
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; |