]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - snd_bsd.c
don't apply dlights to opaque models (this was happening when flashblend is on)
[xonotic/darkplaces.git] / snd_bsd.c
index a771b4c5a8d7de4d3ffbcc27755dd8ba58fe7e05..0ca754f1711f3a0b595ba0cc86dfcdd03a0d3c11 100644 (file)
--- a/snd_bsd.c
+++ b/snd_bsd.c
@@ -28,9 +28,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include <unistd.h>
 
 #include "quakedef.h"
+#include "snd_main.h"
 
 
-static const int tryrates[] = {44100, 22051, 11025, 8000};
+static const int tryrates[] = {44100, 22050, 11025, 8000};
 
 static int audio_fd = -1;
 static qboolean snd_inited = false;
@@ -45,32 +46,37 @@ static qbyte writebuf [SND_BUFF_SIZE];
 qboolean SNDDMA_Init (void)
 {
        unsigned int i;
-       const char *snddev = _PATH_SOUND;
+       const char *snddev;
        audio_info_t info;
 
        memset ((void*)shm, 0, sizeof (*shm));
 
        // Open the audio device
+#ifdef _PATH_SOUND
+       snddev = _PATH_SOUND;
+#else
+       snddev = "/dev/sound";
+#endif
        audio_fd = open (snddev, O_WRONLY | O_NDELAY | O_NONBLOCK);
        if (audio_fd < 0)
        {
-               Con_Printf ("Can't open the sound device (%s)\n", snddev);
+               Con_Printf("Can't open the sound device (%s)\n", snddev);
                return false;
        }
 
        // Look for an appropriate sound format
        // TODO: we should also test mono/stereo and bits
        // TODO: support "-sndspeed", "-sndbits", "-sndmono" and "-sndstereo"
-       shm->channels = 2;
-       shm->samplebits = 16;
+       shm->format.channels = 2;
+       shm->format.width = 2;
        for (i = 0; i < sizeof (tryrates) / sizeof (tryrates[0]); i++)
        {
-               shm->speed = tryrates[i];
+               shm->format.speed = tryrates[i];
 
                AUDIO_INITINFO (&info);
-               info.play.sample_rate = shm->speed;
-               info.play.channels = shm->channels;
-               info.play.precision = shm->samplebits;
+               info.play.sample_rate = shm->format.speed;
+               info.play.channels = shm->format.channels;
+               info.play.precision = shm->format.width * 8;
 // We only handle sound cards of the same endianess than the CPU
 #if BYTE_ORDER == BIG_ENDIAN
                info.play.encoding = AUDIO_ENCODING_SLINEAR_BE;
@@ -82,18 +88,18 @@ qboolean SNDDMA_Init (void)
        }
        if (i == sizeof (tryrates) / sizeof (tryrates[0]))
        {
-               Con_Print("Can't select an appropriate sound output format\n");
+               Con_Print("Can't select an appropriate sound output format\n");
                close (audio_fd);
                return false;
        }
 
        // Print some information
-       Con_Printf ("%d bit %s sound initialized (rate: %dHz)\n",
+       Con_Printf("%d bit %s sound initialized (rate: %dHz)\n",
                                info.play.precision,
                                (info.play.channels == 2) ? "stereo" : "mono",
                                info.play.sample_rate);
 
-       shm->samples = sizeof (dma_buffer) / (shm->samplebits / 8);
+       shm->samples = sizeof (dma_buffer) / shm->format.width;
        shm->samplepos = 0;
        shm->buffer = dma_buffer;
 
@@ -110,12 +116,12 @@ int SNDDMA_GetDMAPos (void)
 
        if (ioctl (audio_fd, AUDIO_GETINFO, &info) < 0)
        {
-               Con_Print("Error: can't get audio info\n");
+               Con_Print("Error: can't get audio info\n");
                SNDDMA_Shutdown ();
                return 0;
        }
 
-       return ((info.play.samples * shm->channels) % shm->samples);
+       return ((info.play.samples * shm->format.channels) % shm->samples);
 }
 
 void SNDDMA_Shutdown (void)
@@ -150,7 +156,7 @@ void SNDDMA_Submit (void)
        if (paintedtime < wbufp)
                wbufp = 0; // reset
 
-       bsize = shm->channels * (shm->samplebits / 8);
+       bsize = shm->format.channels * shm->format.width;
        bytes = (paintedtime - wbufp) * bsize;
 
        if (!bytes)
@@ -173,7 +179,7 @@ void SNDDMA_Submit (void)
        }
 
        if (write (audio_fd, writebuf, bytes) < bytes)
-               Con_Print("audio can't keep up!\n");
+               Con_Print("audio can't keep up!\n");
 
        wbufp = stop;
 }