--- xwave-0.7-orig/src/audio.c 2006-05-21 15:04:19 +0900 +++ xwave-0.7/src/audio.c 2010-02-22 23:33:25 +0900 @@ -67,6 +67,8 @@ static Audio_File af; static int stop_record; +static int mono_to_stereo; + #if defined (linux) || defined (FreeBSD) int set_dsp(int o_mode,int res, int channels, int freq, int *buf_size) { @@ -85,7 +87,13 @@ fprintf(stderr,"XWave: Device doesn't accept resolution \"%i\"!\n",res); return(-1); } - check=channels-1; + if (channels==1) { + mono_to_stereo=1; + check=1; + } else { + mono_to_stereo=0; + check=channels-1; + } if (ioctl(audio, SNDCTL_DSP_STEREO, &check)==-1) { fprintf(stderr,"XWave: Device doesn't accept %i channels !\n",channels); return(-1); @@ -474,7 +482,39 @@ while (playlength>0) { if (playlengthres==8) { + const unsigned char *src = (const unsigned char *)buffer; + unsigned char *dest = (unsigned char *)buffer2; + int i; + for (i = 0; i < buf_size; i++) { + dest[i*2+0] = src[i]; + dest[i*2+1] = src[i]; + } + } else if (wd->res==16) { + const short *src = (const short *)buffer; + short *dest = (short *)buffer2; + int i; + for (i = 0; i < buf_size/2; i++) { + dest[i*2+0] = src[i]; + dest[i*2+1] = src[i]; + } + } else { + static int warned = 0; + if (!warned) { + fprintf(stderr, "Don't know how to upgrade %d-bit audio\n", wd->res); + warned = 1; + } + memset(buffer2, 0, buf_size*2); + } + result = write(audio, buffer2, buf_size*2); + free(buffer2); + } else { + result = write(audio, buffer, buf_size); + } + if (result==-1) { close(audio); kill((pid_t) getppid(),SIGUSR1); return; @@ -519,7 +559,39 @@ return; } #if defined (linux) || defined (FreeBSD) || defined (sun) - if (write(audio,(char*) md->mg->fbuf,length)==-1) { + int result; + if (mono_to_stereo) { + void *buffer2 = malloc(length*2); + if (wd->res==8) { + const unsigned char *src = (const unsigned char *)md->mg->fbuf; + unsigned char *dest = (unsigned char *)buffer2; + int i; + for (i = 0; i < length; i++) { + dest[i*2+0] = src[i]; + dest[i*2+1] = src[i]; + } + } else if (wd->res==16) { + const short *src = (const short *)md->mg->fbuf; + short *dest = (short *)buffer2; + int i; + for (i = 0; i < length/2; i++) { + dest[i*2+0] = src[i]; + dest[i*2+1] = src[i]; + } + } else { + static int warned = 0; + if (!warned) { + fprintf(stderr, "Don't know how to upgrade %d-bit audio\n", wd->res); + warned = 1; + } + memset(buffer2, 0, length*2); + } + result = write(audio, buffer2, length*2); + free(buffer2); + } else { + result = write(audio, md->mg->fbuf, length); + } + if (result==-1) { close(audio); kill((pid_t) getppid(),SIGUSR1); return;