1 /* FCE Ultra - NES/Famicom Emulator
3 * Copyright notice for this file:
4 * Copyright (C) 2002 Ben Parnell
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include <sys/ioctl.h>
30 #include <sys/types.h>
33 #include <sys/soundcard.h>
35 #include "../../types.h"
40 // fsize is in samples, not bytes(gets translated before ioctl())
41 int InitUNIXDSPSound(int *rate, int bits, int fsize, int nfrags)
45 printf(" Opening /dev/dsp...");
46 dspfd=open("/dev/dsp",O_WRONLY);
47 if(dspfd==-1) goto __disperror;
49 if(!bits) goto skip16check;
52 printf("\n Setting format to 16-bit, signed, LSB first...");
53 if(ioctl(dspfd,SNDCTL_DSP_SETFMT,&x)==-1)
57 printf("\n Setting format to 8-bit, unsigned...");
58 if(ioctl(dspfd,SNDCTL_DSP_SETFMT,&x)==-1) goto __disperror;
62 printf("\n Setting fragment size to %d samples and number of fragments to %d...",1<<fsize,nfrags);
68 if(ioctl(dspfd,SNDCTL_DSP_SETFRAGMENT,&x)==-1)
69 printf("ERROR (continuing anyway)\n");
71 printf("\n Setting mono sound...");
72 if(ioctl(dspfd,SNDCTL_DSP_STEREO,&x)==-1) goto __disperror;
73 printf("\n Setting playback rate of %d hz...",*rate);
74 if(ioctl(dspfd,SNDCTL_DSP_SPEED,rate)==-1) goto __disperror;
75 printf("Set to %d hz\n",*rate);
76 if(*rate<8192 || *rate>65535)
78 printf(" Sample rate is out of the acceptable range(8192-65535).\n");
88 void KillUNIXDSPSound(void)
93 static int16 MBuffer[2048];
94 void WriteUNIXDSPSound(int32 *Buffer, int Count, int noblocking)
101 uint8 *dest=(uint8 *)MBuffer;
102 for(P=Count;P;P--,dest++,src++)
103 *dest=(uint8)((*src)>>8)^128;
109 for(P=Count;P;P--,dest++,src++)
114 // noblocking=!noblocking; // speed testing
117 struct audio_buf_info ai;
118 if(!ioctl(dspfd,SNDCTL_DSP_GETOSPACE,&ai))
122 write(dspfd,(uint8 *)MBuffer,c);