]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - snd_oss.c
added description string to all cvars and commands
[xonotic/darkplaces.git] / snd_oss.c
index eef8e62c9681a851357b69ec8ddba4e79e3b7ee4..9e1711af33f816f2661c7ea7ddbda6e4677f21f1 100644 (file)
--- a/snd_oss.c
+++ b/snd_oss.c
@@ -34,7 +34,6 @@ 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};
 
@@ -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
@@ -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;
 }
 
 /*