|
|
1.1 root 1: /*
2: * UAE - The Un*x Amiga Emulator
3: *
4: * Support for Amiga audio.device sound
5: *
6: * Copyright 1996, 1997 Samuel Devulder
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.3 ! 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 <pDOS/Lock.h>
22: #include <pDOS/Files.h>
23: #include <pDOS/DosSig.h>
24: #include <pDOS/DosErrors.h>
25: #include <pInline/pDos2.h>
26:
27: extern struct pOS_DosBase *gb_DosBase;
28:
29: static struct pOS_MsgPort AudioMP;
30: struct pOS_AudioIO *AudioIO;
31: struct pOS_Std8AudioMap AudioMap;
32:
33: unsigned char *buffers[2];
34: uae_u16 *sndbuffer;
35: uae_u16 *sndbufpt;
36: int sndbufsize;
37: int bufidx;
38: static int port_created, devopen, channel_allocated;
39:
40: int have_sound;
41:
42: FILE *AUDIO_FILE;
43:
44: static FILE *TST_AUDIO_FILE(char *buff, char *name, int rate, int bsize)
45: {
46: struct pOS_FileLock *lock;
47:
48: if(!name) return 0;
49: sprintf(buff,name,rate,bsize);
50: lock = pOS_LockObject(NULL, buff, FILELKACC_Exclusive|FILELKACC_NoReq);
51: if(lock) {
52: pOS_UnlockObject(lock);
53: return fopen(buff,"wb");
54: }
55: return NULL;
56: }
57:
58: int setup_sound(void)
59: {
60: sound_available = 1;
61: return 1;
62: }
63:
64: int init_sound (void)
65: {
66: int rate;
67: char buff[256],*devname = NULL;
68:
69: atexit(close_sound); /* if only amiga os had resource tracking */
70:
71: sndbufsize = (currprefs.sound_maxbsiz + 1)&~1;
72:
73: /* check freq */
74: if (!currprefs.sound_freq) currprefs.sound_freq = 11025;
75: rate = currprefs.sound_freq;
76:
77: /* check for $AUDIONAME or AUD: or AUDIO: device */
78: devname = buff;
79: AUDIO_FILE = TST_AUDIO_FILE(buff, getenv("AUDIONAME"),
80: rate, sndbufsize);
81: if(!AUDIO_FILE) /* AHI */
82: AUDIO_FILE = TST_AUDIO_FILE(buff, "AUDIO:FREQUENCY=%d/BUFFER=%d",
83: rate, sndbufsize);
84: if(!AUDIO_FILE) /* AUD: */
85: AUDIO_FILE = TST_AUDIO_FILE(buff, "AUDIO:FREQUENCY%d/BUFFER%d",
86: rate, sndbufsize);
87: if(!AUDIO_FILE)
88: AUDIO_FILE = TST_AUDIO_FILE(buff, "AUD:FREQUENCY%d/BUFFER%d",
89: rate, sndbufsize);
90:
91: /* else use audio.device */
92: if(!AUDIO_FILE) {
93: if(!pOS_ConstructMsgPort(&AudioMP)) goto fail;
94: port_created = 1;
95: AudioIO = (void*)pOS_CreateIORequest(&AudioMP,
96: sizeof(struct pOS_AudioIO));
97: if(!AudioIO) goto fail;
98:
99: if(pOS_OpenDevice(devname = "pAudio.device", 0, (void*)AudioIO, 0,0))
100: goto fail;
101: devopen = 1;
102:
103: AudioIO->aio_Command = AUDIOCMD_AllocChannel;
104: AudioIO->aio_U.aio_AllocCh.alio_Tags = NULL;
105: if(pOS_DoIO((struct pOS_IORequest*)AudioIO)) goto fail;
106: channel_allocated = 1;
107: }
108:
109: /* get the buffers */
110: if(AUDIO_FILE) {
111: buffers[0] = malloc(sndbufsize);
112: buffers[1] = NULL;
113: if(!buffers[0]) goto fail;
114: } else {
115: buffers[0] = malloc(sndbufsize);
116: buffers[1] = malloc(sndbufsize);
117: if(!buffers[0] || !buffers[1]) goto fail;
118: }
119: bufidx = 0;
120: sndbuffer = sndbufpt = (uae_u16*)buffers[bufidx];
121:
122: AudioIO->aio_U.aio_Map.amio_AudioMap = (struct pOS_AudioMap*)&AudioMap;
123: AudioMap.bam_Audio.am_Type = AUDIOMAPTYP_Std8Bit;
124: AudioMap.bam_Audio.am_Frequency = rate;
125: AudioMap.bam_Length = sndbufsize;
126: AudioMap.bam_Sample = (void*)sndbuffer;
127:
1.1.1.3 ! root 128: scaled_sample_evtime = (unsigned long)maxhpos * maxvpos * vblank_hz * CYCLE_UNIT / rate;
! 129: scaled_sample_evtime_ok = 1;
! 130:
1.1 root 131: init_sound_table8 ();
1.1.1.2 root 132: sample_handler = sample8_handler;
1.1 root 133:
134: fprintf(stderr, "Sound driver found and configured for %d bits "
135: "at %d Hz, buffer is %d bytes (%s)\n",
136: 8, rate, sndbufsize,devname);
137:
138: sound_available = 1;
139: return 1;
140: fail:
141: sound_available = 0;
142: return 0;
143: }
144:
145: void close_sound(void)
146: {
147: if(AUDIO_FILE) {
148: fclose(AUDIO_FILE);
149: AUDIO_FILE = NULL;
150: }
151: if(channel_allocated) {
152: AudioIO->aio_Command = AUDIOCMD_FreeChannel;
153: pOS_DoIO((struct pOS_IORequest*)AudioIO);
154: channel_allocated = 0;
155: }
156: if(devopen) {
157: pOS_CloseDevice((void*)AudioIO);
158: devopen = 0;
159: }
160: if(AudioIO) {
161: pOS_DeleteIORequest((void*)AudioIO);
162: AudioIO = NULL;
163: }
164: if(port_created) {
165: pOS_DestructMsgPort(&AudioMP);
166: port_created = 0;
167: }
168: if(buffers[0]) {free(buffers[0]);buffers[0] = 0;}
169: if(buffers[1]) {free(buffers[1]);buffers[1] = 0;}
170: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.