25 #include "soundheader.h"
29 char *dspBlock = NULL;
38 int bytesPerCycle = 0;
41 int soundcardBufferEmptySize = 0;
42 int soundcardBufferCurrentSize = 0;
45 int SystemBPSample = 16;
47 long int Rate = 22050;
51 short int CombiningBuffer[MAXBUFSIZE];
52 void initializeCombiningBuffer();
54 void playWavFragment() {
56 audio_buf_info leftover;
77 if (DSPplaying != 0) {
83 bytesPerCycle = MAXBUFSIZE/2;
86 mydata = soundcardBufferEmptySize - soundcardBufferCurrentSize;
102 if (mydata <= (bytesPerCycle*2)) {
103 initializeCombiningBuffer();
105 streamMoreData(bytesPerCycle);
108 if (ioctl(dspFile, SNDCTL_DSP_GETOSPACE,&leftover) <0) {
109 printf (
"error, SNDCTL_DSP_GETOSPACE\n");
113 soundcardBufferCurrentSize = leftover.bytes;
120 wavfile->type=WAVFILE;
126 if (dspBlock!=NULL) free(dspBlock);
127 if (dspFile>=0) close(dspFile);
134 audio_buf_info leftover;
136 if ( (dspFile = open(
"/dev/dsp",O_WRONLY|O_NONBLOCK))
139 printf (
"FreeWRL::SoundEngine::open /dev/dsp problem (is something else using it?)\n");
144 i = (N_FRAGMENTS<<16) | FRAG_SIZE;
145 if ( ioctl(dspFile, SNDCTL_DSP_SETFRAGMENT,
147 printf(
"ioctl set fragment problem\n");
154 if (ioctl(dspFile, SNDCTL_DSP_GETOSPACE,&leftover) <0) {
155 printf (
"error, SNDCTL_DSP_GETOSPACE\n");
158 soundcardBufferEmptySize = leftover.bytes;
162 if (ioctl(dspFile,SNDCTL_DSP_SETFMT,&SystemBPSample)<0) {
163 printf (
"unable to set DSP bit size to %d\n",SystemBPSample);
168 if (ioctl(dspFile,SNDCTL_DSP_STEREO,&MaxChannels)<0) {
169 printf (
"unable to set mono/stereo mode to %d\n",MaxChannels);
174 if (ioctl(dspFile,SNDCTL_DSP_SPEED,&Rate)<0) {
175 printf (
"unable to set DSP sampling rate to %ld\n",Rate);
184 void initializeCombiningBuffer() {
187 for (count =0; count < MAXBUFSIZE; count++) {
189 CombiningBuffer[count] = 0;
195 void addToCombiningBuffer(
int source,
int readSize,
int offset) {
205 ampl = 100 - (sndfile[source]->ampl);
206 if (ampl < 1) ampl = 1;
208 switch (sndfile[source]->FormatChunk.wBitsPerSample) {
210 siptr = (
short int *)(sndfile[source]->data);
211 lbal = sndfile[source]->balance;
221 for (tc=0; tc<(readSize/2); tc++) {
223 if ((tc & 0x01) == 0) {
226 tmp = (tmp *100)/ampl;
227 tmp = (tmp * lbal) / 50;
233 tmp = (tmp *100)/ampl;
234 tmp = (tmp * rbal) / 50;
239 tmp = tmp + (int)CombiningBuffer[offset];
240 if ((tmp > 32767) || (tmp <-32768)) {
250 CombiningBuffer[offset] = tmp;
258 printf (
"woops, addToStreaming not for this type\n");