X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=snd_oss.c;h=f50c321c58c03d2cd2aa7d6145091c72ce7575bc;hb=2e81949c22f8e7bfe4ed477a3e0eda12cb61dcc1;hp=10c2a085d8512fc3ed100b8bbe9f516670d1bacd;hpb=8e579bbf57c9235bc3c11838e5a68bc52be3e9df;p=xonotic%2Fdarkplaces.git diff --git a/snd_oss.c b/snd_oss.c index 10c2a085..f50c321c 100644 --- a/snd_oss.c +++ b/snd_oss.c @@ -34,9 +34,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "snd_main.h" int audio_fd; -int snd_inited; -static int tryrates[] = {44100, 22050, 11025, 8000}; +static int tryrates[] = {44100, 48000, 22050, 24000, 11025, 16000, 8000}; qboolean SNDDMA_Init(void) { @@ -54,7 +53,6 @@ qboolean SNDDMA_Init(void) #else format16bit = AFMT_S16_LE; #endif - snd_inited = 0; // open /dev/dsp, confirm capability to mmap, and get size of dma buffer audio_fd = open("/dev/dsp", O_RDWR); // we have to open it O_RDWR for mmap @@ -121,7 +119,7 @@ qboolean SNDDMA_Init(void) shm->format.speed = atoi(com_argv[i+1]); else { - for (i = 0;i < (int) sizeof(tryrates) / sizeof(tryrates[0]);i++) + for (i = 0;i < (int) sizeof(tryrates) / (int) sizeof(tryrates[0]);i++) if (!ioctl(audio_fd, SNDCTL_DSP_SPEED, &tryrates[i])) break; @@ -189,7 +187,8 @@ qboolean SNDDMA_Init(void) return 0; } - shm->samples = info.fragstotal * info.fragsize / shm->format.width; + shm->sampleframes = info.fragstotal * info.fragsize / shm->format.width / shm->format.channels; + shm->samples = shm->sampleframes * shm->format.channels; // memory map the dma buffer shm->bufferlength = info.fragstotal * info.fragsize; @@ -224,7 +223,6 @@ qboolean SNDDMA_Init(void) shm->samplepos = 0; - snd_inited = 1; return 1; } @@ -233,14 +231,13 @@ int SNDDMA_GetDMAPos(void) struct count_info count; - if (!snd_inited) return 0; + if (!shm) return 0; if (ioctl(audio_fd, SNDCTL_DSP_GETOPTR, &count)==-1) { perror("/dev/dsp"); Con_Print("Uh, sound dead.\n"); - close(audio_fd); - snd_inited = 0; + S_Shutdown(); return 0; } shm->samplepos = count.ptr / shm->format.width; @@ -251,19 +248,15 @@ int SNDDMA_GetDMAPos(void) void SNDDMA_Shutdown(void) { int tmp; - if (snd_inited) - { - // unmap the memory - munmap(shm->buffer, shm->bufferlength); - // stop the sound - tmp = 0; - ioctl(audio_fd, SNDCTL_DSP_SETTRIGGER, &tmp); - ioctl(audio_fd, SNDCTL_DSP_RESET, 0); - // close the device - close(audio_fd); - audio_fd = -1; - snd_inited = 0; - } + // unmap the memory + munmap(shm->buffer, shm->bufferlength); + // stop the sound + tmp = 0; + ioctl(audio_fd, SNDCTL_DSP_SETTRIGGER, &tmp); + ioctl(audio_fd, SNDCTL_DSP_RESET, 0); + // close the device + close(audio_fd); + audio_fd = -1; } /*