36 |
|
#include "debug.h" |
37 |
|
|
38 |
|
|
39 |
+ |
// Supported sample rates, sizes and channels |
40 |
+ |
vector<uint32> audio_sample_rates; |
41 |
+ |
vector<uint16> audio_sample_sizes; |
42 |
+ |
vector<uint16> audio_channel_counts; |
43 |
+ |
|
44 |
|
// Global variables |
45 |
|
struct audio_status AudioStatus; // Current audio status (sample rate etc.) |
46 |
|
bool audio_open = false; // Flag: audio is initialized and ready |
78 |
|
break; |
79 |
|
|
80 |
|
case siSampleSizeAvailable: { |
81 |
< |
r.d[0] = audio_num_sample_sizes * 2; |
81 |
> |
r.d[0] = audio_sample_sizes.size() * 2; |
82 |
|
Execute68kTrap(0xa122, &r); // NewHandle() |
83 |
|
uint32 h = r.a[0]; |
84 |
|
if (h == 0) |
85 |
|
return memFullErr; |
86 |
< |
WriteMacInt16(infoPtr + sil_count, audio_num_sample_sizes); |
86 |
> |
WriteMacInt16(infoPtr + sil_count, audio_sample_sizes.size()); |
87 |
|
WriteMacInt32(infoPtr + sil_infoHandle, h); |
88 |
|
uint32 sp = ReadMacInt32(h); |
89 |
< |
for (i=0; i<audio_num_sample_sizes; i++) |
89 |
> |
for (i=0; i<audio_sample_sizes.size(); i++) |
90 |
|
WriteMacInt16(sp + i*2, audio_sample_sizes[i]); |
91 |
|
break; |
92 |
|
} |
96 |
|
break; |
97 |
|
|
98 |
|
case siChannelAvailable: { |
99 |
< |
r.d[0] = audio_num_channel_counts * 2; |
99 |
> |
r.d[0] = audio_channel_counts.size() * 2; |
100 |
|
Execute68kTrap(0xa122, &r); // NewHandle() |
101 |
|
uint32 h = r.a[0]; |
102 |
|
if (h == 0) |
103 |
|
return memFullErr; |
104 |
< |
WriteMacInt16(infoPtr + sil_count, audio_num_channel_counts); |
104 |
> |
WriteMacInt16(infoPtr + sil_count, audio_channel_counts.size()); |
105 |
|
WriteMacInt32(infoPtr + sil_infoHandle, h); |
106 |
|
uint32 sp = ReadMacInt32(h); |
107 |
< |
for (i=0; i<audio_num_channel_counts; i++) |
107 |
> |
for (i=0; i<audio_channel_counts.size(); i++) |
108 |
|
WriteMacInt16(sp + i*2, audio_channel_counts[i]); |
109 |
|
break; |
110 |
|
} |
114 |
|
break; |
115 |
|
|
116 |
|
case siSampleRateAvailable: { |
117 |
< |
r.d[0] = audio_num_sample_rates * 4; |
117 |
> |
r.d[0] = audio_sample_rates.size() * 4; |
118 |
|
Execute68kTrap(0xa122, &r); // NewHandle() |
119 |
|
uint32 h = r.a[0]; |
120 |
|
if (h == 0) |
121 |
|
return memFullErr; |
122 |
< |
WriteMacInt16(infoPtr + sil_count, audio_num_sample_rates); |
122 |
> |
WriteMacInt16(infoPtr + sil_count, audio_sample_rates.size()); |
123 |
|
WriteMacInt32(infoPtr + sil_infoHandle, h); |
124 |
|
uint32 lp = ReadMacInt32(h); |
125 |
< |
for (i=0; i<audio_num_sample_rates; i++) |
125 |
> |
for (i=0; i<audio_sample_rates.size(); i++) |
126 |
|
WriteMacInt32(lp + i*4, audio_sample_rates[i]); |
127 |
|
break; |
128 |
|
} |
194 |
|
D(bug(" set sample size %08lx\n", infoPtr)); |
195 |
|
if (AudioStatus.num_sources) |
196 |
|
return siDeviceBusyErr; |
197 |
< |
for (i=0; i<audio_num_sample_sizes; i++) |
197 |
> |
if (infoPtr == AudioStatus.sample_size) |
198 |
> |
return noErr; |
199 |
> |
for (i=0; i<audio_sample_sizes.size(); i++) |
200 |
|
if (audio_sample_sizes[i] == infoPtr) { |
201 |
< |
audio_set_sample_size(i); |
202 |
< |
return noErr; |
201 |
> |
if (audio_set_sample_size(i)) |
202 |
> |
return noErr; |
203 |
> |
else |
204 |
> |
return siInvalidSampleSize; |
205 |
|
} |
206 |
|
return siInvalidSampleSize; |
207 |
|
|
209 |
|
D(bug(" set sample rate %08lx\n", infoPtr)); |
210 |
|
if (AudioStatus.num_sources) |
211 |
|
return siDeviceBusyErr; |
212 |
< |
for (i=0; i<audio_num_sample_rates; i++) |
212 |
> |
if (infoPtr == AudioStatus.sample_rate) |
213 |
> |
return noErr; |
214 |
> |
for (i=0; i<audio_sample_rates.size(); i++) |
215 |
|
if (audio_sample_rates[i] == infoPtr) { |
216 |
< |
audio_set_sample_rate(i); |
217 |
< |
return noErr; |
216 |
> |
if (audio_set_sample_rate(i)) |
217 |
> |
return noErr; |
218 |
> |
else |
219 |
> |
return siInvalidSampleRate; |
220 |
|
} |
221 |
|
return siInvalidSampleRate; |
222 |
|
|
224 |
|
D(bug(" set number of channels %08lx\n", infoPtr)); |
225 |
|
if (AudioStatus.num_sources) |
226 |
|
return siDeviceBusyErr; |
227 |
< |
for (i=0; i<audio_num_channel_counts; i++) |
227 |
> |
if (infoPtr == AudioStatus.channels) |
228 |
> |
return noErr; |
229 |
> |
for (i=0; i<audio_channel_counts.size(); i++) |
230 |
|
if (audio_channel_counts[i] == infoPtr) { |
231 |
< |
audio_set_channels(i); |
232 |
< |
return noErr; |
231 |
> |
if (audio_set_channels(i)) |
232 |
> |
return noErr; |
233 |
> |
else |
234 |
> |
return badChannel; |
235 |
|
} |
236 |
|
return badChannel; |
237 |
|
|