|
|
1.1.1.4 root 1: /*
1.1 root 2: * UAE - The Un*x Amiga Emulator
1.1.1.4 root 3: *
1.1 root 4: * Support for the Silicon Graphics Audio Library (AL)
1.1.1.4 root 5: *
1.1 root 6: * Copyright 1998 Ari Heikkinen
7: */
8:
9: #include "sysconfig.h"
10: #include "sysdeps.h"
11:
12: #include "options.h"
13: #include "memory.h"
1.1.1.2 root 14: #include "events.h"
1.1 root 15: #include "custom.h"
16: #include "audio.h"
17: #include "gensound.h"
18: #include "sounddep/sound.h"
19:
20: #include <dmedia/audio.h>
21:
22: uae_u16 sndbuffer[88200];
23: uae_u16 *sndbufpt;
24: int sndblocksize;
25:
26: ALport al_port = 0;
27: int to_frames_divisor = 1;
28:
29: static double old_rate = 0;
30:
31: static ALport open_audio(char *name, int width, int channels, int buffers)
32: {
33: ALconfig alc;
34: ALport alp;
35:
36: if (channels <= 0 || buffers <= 0)
37: return 0;
38:
39: alc = alNewConfig();
40: if (!alc)
41: return 0;
42: if (alSetWidth(alc, width)) {
43: alFreeConfig(alc);
44: return 0;
45: }
46: if (alSetChannels(alc, channels)) {
47: alFreeConfig(alc);
48: return 0;
49: }
50: if (alSetQueueSize(alc, buffers)) {
51: alFreeConfig(alc);
52: return 0;
53: }
54: alp = alOpenPort(name, "w", alc);
55: alFreeConfig(alc);
56: return alp ? alp : 0;
57: }
58:
59: static double get_sample_rate(void)
60: {
61: ALpv alpv;
62:
63: alpv.param = AL_RATE;
64: if (alGetParams(AL_DEFAULT_OUTPUT, &alpv, 1) != 1)
65: return 0;
66: return alFixedToDouble(alpv.value.ll);
67: }
68:
69: static int set_sample_rate(double rate)
70: {
71: ALpv alpv[2];
72:
73: if (rate < 0)
74: return -1;
75: alpv[0].param = AL_MASTER_CLOCK;
76: alpv[0].value.i = AL_CRYSTAL_MCLK_TYPE;
77: alpv[1].param = AL_RATE;
78: alpv[1].value.ll = alDoubleToFixed(rate);
79: if (alSetParams(AL_DEFAULT_OUTPUT, alpv, 2) != 2)
80: return -1;
81: return 0;
82: }
83:
84: int init_sound(void)
85: {
86: int width = AL_SAMPLE_16;
87: /* if someone knows how to get 8bit sound working on SGI fix it and
88: use this instead of the line above...
89: int width = currprefs.sound_bits >= 12 ? AL_SAMPLE_16 : AL_SAMPLE_8;
90: */
91: int channels = currprefs.stereo ? 2 : 1;
92: int rate = currprefs.sound_freq;
93:
94: if (currprefs.sound_maxbsiz < 128 || currprefs.sound_maxbsiz > 44100) {
95: fprintf(stderr, "Sound buffer size %d out of range.\n",
96: currprefs.sound_maxbsiz);
97: currprefs.sound_maxbsiz = 8192;
98: }
99:
100: al_port = open_audio("UAE Sound", width, channels,
101: currprefs.sound_maxbsiz * 2);
102: if (!al_port) {
103: sound_available = 0;
104: return 0;
105: }
106:
107: old_rate = get_sample_rate();
108: if (old_rate <= 0 || set_sample_rate((double)rate)
109: || (rate = (int)get_sample_rate()) <= 0) {
110: alClosePort(al_port);
111: sound_available = 0;
112: return 0;
113: }
114:
1.1.1.5 ! root 115: obtained_freq = rate;
1.1 root 116:
117: sndbufpt = sndbuffer;
118: if (width == AL_SAMPLE_16) {
119: sndblocksize = currprefs.sound_maxbsiz * channels * 2;
120: sample_handler = currprefs.stereo
121: ? sample16s_handler
122: : sample16_handler;
123: to_frames_divisor = channels * 2;
124: init_sound_table16();
125: } else {
126: sndblocksize = currprefs.sound_maxbsiz * channels;
127: sample_handler = currprefs.stereo
128: ? sample8s_handler
129: : sample8_handler;
130: to_frames_divisor = channels;
131: init_sound_table8();
132: }
133: printf("Sound driver configured for %d bits (%s) at %d Hz, "
134: "buffer is %d bytes\n", width == AL_SAMPLE_16 ? 16 : 8,
135: channels == 2 ? "stereo" : "mono", rate, sndblocksize);
136: return 1;
137: }
138:
139: int setup_sound(void)
140: {
141: ALport alp;
142:
143: sound_available = 0;
144: alp = open_audio("UAE Sound (test)", AL_SAMPLE_16, 1, 44100);
145: if (!alp) {
146: printf("SetupSound failed - sound hardware unavailable.\n");
147: return 0;
148: }
149: sound_available = 1;
150: alClosePort(alp);
151: printf("SetupSound ok - sound hardware available.\n");
152: return 1;
153: }
154:
155: void close_sound(void)
156: {
157: if (old_rate > 0)
158: (void)set_sample_rate(old_rate);
159: if (al_port)
160: alClosePort(al_port);
161: printf("CloseSound ok\n");
162: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.