]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - snd_bsd.c
eliminated qbyte type, now uses unsigned char throughout the engine for this purpose
[xonotic/darkplaces.git] / snd_bsd.c
index 1c39404c0af6e0359c3974d68c20ec5b2ef7bb9d..caa7ee0c54c7fe31c3a540ff896e83e4ab38522b 100644 (file)
--- a/snd_bsd.c
+++ b/snd_bsd.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
 See the GNU General Public License for more details.
 
@@ -20,17 +20,22 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 #include <sys/param.h>
 #include <sys/audioio.h>
+#ifndef SUNOS
 #include <sys/endian.h>
+#endif
 #include <sys/ioctl.h>
 
 #include <fcntl.h>
+#ifndef SUNOS
 #include <paths.h>
+#endif
 #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;
@@ -38,19 +43,28 @@ static qboolean snd_inited = false;
 // TODO: allocate them in SNDDMA_Init, with a size depending on
 // the sound format (enough for 0.5 sec of sound for instance)
 #define SND_BUFF_SIZE 65536
-static qbyte dma_buffer [SND_BUFF_SIZE];
-static qbyte writebuf [SND_BUFF_SIZE];
+static unsigned char dma_buffer [SND_BUFF_SIZE];
+static unsigned char 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
+#ifndef SUNOS
+       snddev = "/dev/sound";
+#else
+       snddev = "/dev/audio";
+#endif
+#endif
        audio_fd = open (snddev, O_WRONLY | O_NDELAY | O_NONBLOCK);
        if (audio_fd < 0)
        {
@@ -61,21 +75,25 @@ qboolean SNDDMA_Init (void)
        // 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;
 #else
+#ifndef SUNOS
                info.play.encoding = AUDIO_ENCODING_SLINEAR_LE;
+#else
+               info.play.encoding = AUDIO_ENCODING_LINEAR;
+#endif
 #endif
                if (ioctl (audio_fd, AUDIO_SETINFO, &info) == 0)
                        break;
@@ -93,7 +111,7 @@ qboolean SNDDMA_Init (void)
                                (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;
 
@@ -115,7 +133,7 @@ int SNDDMA_GetDMAPos (void)
                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 +168,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)