1 |
|
/* |
2 |
|
* audio.cpp - Audio support |
3 |
|
* |
4 |
< |
* Basilisk II (C) 1997-1999 Christian Bauer |
4 |
> |
* Basilisk II (C) 1997-2001 Christian Bauer |
5 |
|
* Portions (C) 1997-1999 Marc Hellwig |
6 |
|
* |
7 |
|
* This program is free software; you can redistribute it and/or modify |
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 |
53 |
|
|
54 |
|
|
55 |
|
/* |
56 |
+ |
* Reset audio emulation |
57 |
+ |
*/ |
58 |
+ |
|
59 |
+ |
void AudioReset(void) |
60 |
+ |
{ |
61 |
+ |
audio_data = 0; |
62 |
+ |
} |
63 |
+ |
|
64 |
+ |
|
65 |
+ |
/* |
66 |
|
* Get audio info |
67 |
|
*/ |
68 |
|
|
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 |
|
|
421 |
|
|
422 |
|
// Init sound component data |
423 |
|
WriteMacInt32(audio_data + adatData + scd_flags, 0); |
424 |
< |
WriteMacInt32(audio_data + adatData + scd_format, AudioStatus.sample_size == 16 ? 'twos' : 'raw '); |
424 |
> |
WriteMacInt32(audio_data + adatData + scd_format, AudioStatus.sample_size == 16 ? FOURCC('t','w','o','s') : FOURCC('r','a','w',' ')); |
425 |
|
WriteMacInt16(audio_data + adatData + scd_numChannels, AudioStatus.channels); |
426 |
|
WriteMacInt16(audio_data + adatData + scd_sampleSize, AudioStatus.sample_size); |
427 |
|
WriteMacInt32(audio_data + adatData + scd_sampleRate, AudioStatus.sample_rate); |
487 |
|
return badComponentSelector; |
488 |
|
} |
489 |
|
} |
490 |
+ |
|
491 |
+ |
|
492 |
+ |
/* |
493 |
+ |
* Sound input driver Open() routine |
494 |
+ |
*/ |
495 |
+ |
|
496 |
+ |
int16 SoundInOpen(uint32 pb, uint32 dce) |
497 |
+ |
{ |
498 |
+ |
D(bug("SoundInOpen\n")); |
499 |
+ |
return noErr; |
500 |
+ |
} |
501 |
+ |
|
502 |
+ |
|
503 |
+ |
/* |
504 |
+ |
* Sound input driver Prime() routine |
505 |
+ |
*/ |
506 |
+ |
|
507 |
+ |
int16 SoundInPrime(uint32 pb, uint32 dce) |
508 |
+ |
{ |
509 |
+ |
D(bug("SoundInPrime\n")); |
510 |
+ |
//!! |
511 |
+ |
return paramErr; |
512 |
+ |
} |
513 |
+ |
|
514 |
+ |
|
515 |
+ |
/* |
516 |
+ |
* Sound input driver Control() routine |
517 |
+ |
*/ |
518 |
+ |
|
519 |
+ |
int16 SoundInControl(uint32 pb, uint32 dce) |
520 |
+ |
{ |
521 |
+ |
uint16 code = ReadMacInt16(pb + csCode); |
522 |
+ |
D(bug("SoundInControl %d\n", code)); |
523 |
+ |
|
524 |
+ |
if (code == 1) { |
525 |
+ |
D(bug(" SoundInKillIO\n")); |
526 |
+ |
//!! |
527 |
+ |
return noErr; |
528 |
+ |
} |
529 |
+ |
|
530 |
+ |
if (code != 2) |
531 |
+ |
return -231; // siUnknownInfoType |
532 |
+ |
|
533 |
+ |
uint32 *param = (uint32 *)Mac2HostAddr(pb + csParam); |
534 |
+ |
uint32 selector = param[0]; |
535 |
+ |
D(bug(" selector %c%c%c%c\n", selector >> 24, selector >> 16, selector >> 8, selector)); |
536 |
+ |
|
537 |
+ |
switch (selector) { |
538 |
+ |
default: |
539 |
+ |
return -231; // siUnknownInfoType |
540 |
+ |
} |
541 |
+ |
} |
542 |
+ |
|
543 |
+ |
|
544 |
+ |
/* |
545 |
+ |
* Sound input driver Status() routine |
546 |
+ |
*/ |
547 |
+ |
|
548 |
+ |
int16 SoundInStatus(uint32 pb, uint32 dce) |
549 |
+ |
{ |
550 |
+ |
uint16 code = ReadMacInt16(pb + csCode); |
551 |
+ |
D(bug("SoundInStatus %d\n", code)); |
552 |
+ |
if (code != 2) |
553 |
+ |
return -231; // siUnknownInfoType |
554 |
+ |
|
555 |
+ |
uint32 *param = (uint32 *)Mac2HostAddr(pb + csParam); |
556 |
+ |
uint32 selector = param[0]; |
557 |
+ |
D(bug(" selector %c%c%c%c\n", selector >> 24, selector >> 16, selector >> 8, selector)); |
558 |
+ |
switch (selector) { |
559 |
+ |
#if 0 |
560 |
+ |
case siDeviceName: { |
561 |
+ |
const char *str = GetString(STR_SOUND_IN_NAME); |
562 |
+ |
param[0] = 0; |
563 |
+ |
memcpy((void *)param[1], str, strlen(str)); |
564 |
+ |
return noErr; |
565 |
+ |
} |
566 |
+ |
|
567 |
+ |
case siDeviceIcon: { |
568 |
+ |
M68kRegisters r; |
569 |
+ |
static const uint16 proc[] = { |
570 |
+ |
0x558f, // subq.l #2,sp |
571 |
+ |
0xa994, // CurResFile |
572 |
+ |
0x4267, // clr.w -(sp) |
573 |
+ |
0xa998, // UseResFile |
574 |
+ |
0x598f, // subq.l #4,sp |
575 |
+ |
0x4879, 0x4943, 0x4e23, // move.l #'ICN#',-(sp) |
576 |
+ |
0x3f3c, 0xbf76, // move.w #-16522,-(sp) |
577 |
+ |
0xa9a0, // GetResource |
578 |
+ |
0x245f, // move.l (sp)+,a2 |
579 |
+ |
0xa998, // UseResFile |
580 |
+ |
0x200a, // move.l a2,d0 |
581 |
+ |
0x6604, // bne 1 |
582 |
+ |
0x7000, // moveq #0,d0 |
583 |
+ |
M68K_RTS, |
584 |
+ |
0x2f0a, //1 move.l a2,-(sp) |
585 |
+ |
0xa992, // DetachResource |
586 |
+ |
0x204a, // move.l a2,a0 |
587 |
+ |
0xa04a, // HNoPurge |
588 |
+ |
0x7001, // moveq #1,d0 |
589 |
+ |
M68K_RTS |
590 |
+ |
}; |
591 |
+ |
Execute68k((uint32)proc, &r); |
592 |
+ |
if (r.d[0]) { |
593 |
+ |
param[0] = 4; // Length of returned data |
594 |
+ |
param[1] = r.a[2]; // Handle to icon suite |
595 |
+ |
return noErr; |
596 |
+ |
} else |
597 |
+ |
return -192; // resNotFound |
598 |
+ |
} |
599 |
+ |
#endif |
600 |
+ |
default: |
601 |
+ |
return -231; // siUnknownInfoType |
602 |
+ |
} |
603 |
+ |
} |
604 |
+ |
|
605 |
+ |
|
606 |
+ |
/* |
607 |
+ |
* Sound input driver Close() routine |
608 |
+ |
*/ |
609 |
+ |
|
610 |
+ |
int16 SoundInClose(uint32 pb, uint32 dce) |
611 |
+ |
{ |
612 |
+ |
D(bug("SoundInClose\n")); |
613 |
+ |
return noErr; |
614 |
+ |
} |