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