fix shm properly :)

This commit is contained in:
Bill Currie 2004-01-08 03:46:11 +00:00
parent 4597b44334
commit ccfa9081b0
13 changed files with 232 additions and 250 deletions

View file

@ -34,7 +34,7 @@
/*
All sound plugins must export these functions
*/
typedef qboolean (QFPLUGIN *P_S_O_Init) (void);
typedef volatile struct dma_s *(QFPLUGIN *P_S_O_Init) (void);
typedef void (QFPLUGIN *P_S_O_Shutdown) (void);
typedef int (QFPLUGIN *P_S_O_GetDMAPos) (void);
typedef void (QFPLUGIN *P_S_O_Submit) (void);

View file

@ -59,8 +59,7 @@ struct sfx_s
void (*release) (sfx_t *sfx);
};
typedef struct
{
typedef struct dma_s {
qboolean gamealive;
qboolean soundalive;
qboolean splitbuffer;
@ -119,8 +118,6 @@ extern vec3_t listener_origin;
extern vec3_t listener_forward;
extern vec3_t listener_right;
extern vec3_t listener_up;
extern volatile dma_t *shm;
extern volatile dma_t sn;
extern vec_t sound_nominal_clip_dist;
extern struct cvar_s *snd_loadas8bit;

View file

@ -132,6 +132,7 @@ void SND_PaintChannelFrom16 (channel_t *ch, sfxbuffer_t *sc, int count);
void SND_PaintChannelStereo8 (channel_t *ch, sfxbuffer_t *sc, int count);
void SND_PaintChannelStereo16 (channel_t *ch, sfxbuffer_t *sc, int count);
extern volatile dma_t *shm;
extern channel_t channels[MAX_CHANNELS];
// 0 to MAX_DYNAMIC_CHANNELS-1 = normal entity sounds
// MAX_DYNAMIC_CHANNELS to MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS -1 = water, etc

View file

@ -152,15 +152,13 @@ SND_SoundInfo_f (void)
static void
SND_Startup (void)
{
int rc;
if (!snd_initialized)
return;
if (!fakedma) {
rc = snd_output_funcs->pS_O_Init ();
shm = snd_output_funcs->pS_O_Init ();
if (!rc) {
if (!shm) {
Sys_Printf ("S_Startup: S_O_Init failed.\n");
sound_started = 0;
return;

View file

@ -107,7 +107,7 @@ SNDDMA_Init_Cvars (void)
static int SNDDMA_GetDMAPos (void);
static qboolean
static volatile dma_t *
SNDDMA_Init (void)
{
int err;
@ -259,29 +259,28 @@ SNDDMA_Init (void)
goto error;
}
shm = &sn;
memset ((dma_t *) shm, 0, sizeof (*shm));
shm->splitbuffer = 0;
shm->channels = stereo + 1;
memset ((dma_t *) &sn, 0, sizeof (sn));
sn.splitbuffer = 0;
sn.channels = stereo + 1;
qfsnd_pcm_hw_params_get_period_size (hw, (snd_pcm_uframes_t *)
&shm->submission_chunk, 0);
&sn.submission_chunk, 0);
// don't mix less than this
shm->samplepos = 0; // in mono samples
shm->samplebits = bps;
sn.samplepos = 0; // in mono samples
sn.samplebits = bps;
qfsnd_pcm_hw_params_get_buffer_size (hw, &buffer_size); // FIXME: check error return value
shm->samples = buffer_size * shm->channels; // mono samples in buffer
shm->speed = rate;
SNDDMA_GetDMAPos (); //XXX sets shm->buffer
Sys_Printf ("%5d stereo\n", shm->channels - 1);
Sys_Printf ("%5d samples\n", shm->samples);
Sys_Printf ("%5d samplepos\n", shm->samplepos);
Sys_Printf ("%5d samplebits\n", shm->samplebits);
Sys_Printf ("%5d submission_chunk\n", shm->submission_chunk);
Sys_Printf ("%5d speed\n", shm->speed);
Sys_Printf ("0x%x dma buffer\n", (int) shm->buffer);
sn.samples = buffer_size * sn.channels; // mono samples in buffer
sn.speed = rate;
SNDDMA_GetDMAPos (); //XXX sets sn.buffer
Sys_Printf ("%5d stereo\n", sn.channels - 1);
Sys_Printf ("%5d samples\n", sn.samples);
Sys_Printf ("%5d samplepos\n", sn.samplepos);
Sys_Printf ("%5d samplebits\n", sn.samplebits);
Sys_Printf ("%5d submission_chunk\n", sn.submission_chunk);
Sys_Printf ("%5d speed\n", sn.speed);
Sys_Printf ("0x%x dma buffer\n", (int) sn.buffer);
snd_inited = 1;
return 1;
return &sn;
error:
qfsnd_pcm_close (pcm);
return 0;
@ -292,18 +291,18 @@ SNDDMA_GetDMAPos (void)
{
const snd_pcm_channel_area_t *areas;
snd_pcm_uframes_t offset;
snd_pcm_uframes_t nframes = shm->samples/shm->channels;
snd_pcm_uframes_t nframes = sn.samples/sn.channels;
if (!snd_inited)
return 0;
qfsnd_pcm_avail_update (pcm);
qfsnd_pcm_mmap_begin (pcm, &areas, &offset, &nframes);
offset *= shm->channels;
nframes *= shm->channels;
shm->samplepos = offset;
shm->buffer = areas->addr; //XXX FIXME there's an area per channel
return shm->samplepos;
offset *= sn.channels;
nframes *= sn.channels;
sn.samplepos = offset;
sn.buffer = areas->addr; //XXX FIXME there's an area per channel
return sn.samplepos;
}
static void
@ -333,7 +332,7 @@ SNDDMA_Submit (void)
if (snd_blocked)
return;
nframes = count / shm->channels;
nframes = count / sn.channels;
qfsnd_pcm_avail_update (pcm);
qfsnd_pcm_mmap_begin (pcm, &areas, &offset, &nframes);

View file

@ -56,7 +56,7 @@ static __attribute__ ((unused)) const char rcsid[] =
static int snd_inited;
static QFile *snd_file;
static int snd_blocked = 0;
//FIXME static volatile dma_t sn;
static volatile dma_t sn;
static plugin_t plugin_info;
static plugin_data_t plugin_info_data;
@ -68,45 +68,44 @@ static snd_output_funcs_t plugin_info_snd_output_funcs;
/* FIXME
static qboolean
static volatile dma_t *
SNDDMA_Init (void)
{
shm = &sn;
memset ((dma_t *) shm, 0, sizeof (*shm));
shm->splitbuffer = 0;
shm->channels = 2;
shm->submission_chunk = 1; // don't mix less than this #
shm->samplepos = 0; // in mono samples
shm->samplebits = 16;
shm->samples = 16384; // mono samples in buffer
shm->speed = 44100;
shm->buffer = malloc (shm->samples * shm->channels * shm->samplebits / 8);
if (!shm->buffer) {
memset ((dma_t *) sn, 0, sizeof (sn));
sn.splitbuffer = 0;
sn.channels = 2;
sn.submission_chunk = 1; // don't mix less than this #
sn.samplepos = 0; // in mono samples
sn.samplebits = 16;
sn.samples = 16384; // mono samples in buffer
sn.speed = 44100;
sn.buffer = malloc (sn.samples * sn.channels * sn.samplebits / 8);
if (!sn.buffer) {
Sys_Printf ("SNDDMA_Init: memory allocation failure\n");
return 0;
}
Sys_Printf ("%5d stereo\n", shm->channels - 1);
Sys_Printf ("%5d samples\n", shm->samples);
Sys_Printf ("%5d samplepos\n", shm->samplepos);
Sys_Printf ("%5d samplebits\n", shm->samplebits);
Sys_Printf ("%5d submission_chunk\n", shm->submission_chunk);
Sys_Printf ("%5d speed\n", shm->speed);
Sys_Printf ("0x%x dma buffer\n", (int) shm->buffer);
Sys_Printf ("%5d stereo\n", sn.channels - 1);
Sys_Printf ("%5d samples\n", sn.samples);
Sys_Printf ("%5d samplepos\n", sn.samplepos);
Sys_Printf ("%5d samplebits\n", sn.samplebits);
Sys_Printf ("%5d submission_chunk\n", sn.submission_chunk);
Sys_Printf ("%5d speed\n", sn.speed);
Sys_Printf ("0x%x dma buffer\n", (int) sn.buffer);
if (!(snd_file = Qopen ("qf.raw", "wb")))
return 0;
snd_inited = 1;
return 1;
return &sn;
}
*/
static int
SNDDMA_GetDMAPos (void)
{
shm->samplepos = 0;
return shm->samplepos;
sn.samplepos = 0;
return sn.samplepos;
}
static void
@ -115,7 +114,7 @@ SNDDMA_Shutdown (void)
if (snd_inited) {
Qclose (snd_file);
snd_file = 0;
free (shm->buffer);
free (sn.buffer);
snd_inited = 0;
}
}
@ -130,12 +129,12 @@ SNDDMA_Submit (void)
{
int count = ((*plugin_info_snd_output_data.paintedtime -
*plugin_info_snd_output_data.soundtime) *
shm->samplebits / 8);
sn.samplebits / 8);
if (snd_blocked)
return;
Qwrite (snd_file, shm->buffer, count);
Qwrite (snd_file, sn.buffer, count);
}
static void

View file

@ -156,17 +156,15 @@ SNDDMA_InitDirect (void)
memset ((void *) &sn, 0, sizeof (sn));
shm = &sn;
shm->channels = 2;
shm->samplebits = 16;
shm->speed = 11025;
sn.channels = 2;
sn.samplebits = 16;
sn.speed = 11025;
memset (&format, 0, sizeof (format));
format.wFormatTag = WAVE_FORMAT_PCM;
format.nChannels = shm->channels;
format.wBitsPerSample = shm->samplebits;
format.nSamplesPerSec = shm->speed;
format.nChannels = sn.channels;
format.wBitsPerSample = sn.samplebits;
format.nSamplesPerSec = sn.speed;
format.nBlockAlign = format.nChannels * format.wBitsPerSample / 8;
format.cbSize = 0;
format.nAvgBytesPerSec = format.nSamplesPerSec * format.nBlockAlign;
@ -256,9 +254,9 @@ SNDDMA_InitDirect (void)
return SIS_FAILURE;
}
shm->channels = format.nChannels;
shm->samplebits = format.wBitsPerSample;
shm->speed = format.nSamplesPerSec;
sn.channels = format.nChannels;
sn.samplebits = format.wBitsPerSample;
sn.speed = format.nSamplesPerSec;
if (DS_OK != IDirectSound_GetCaps (pDSBuf, &dsbcaps)) {
Sys_Printf ("DS:GetCaps failed\n");
@ -321,13 +319,13 @@ SNDDMA_InitDirect (void)
&dwWrite);
IDirectSoundBuffer_Play (pDSBuf, 0, 0, DSBPLAY_LOOPING);
shm->soundalive = true;
shm->splitbuffer = false;
shm->samples = gSndBufSize / (shm->samplebits / 8);
shm->samplepos = 0;
shm->submission_chunk = 1;
shm->buffer = lpData;
sample16 = (shm->samplebits / 8) - 1;
sn.soundalive = true;
sn.splitbuffer = false;
sn.samples = gSndBufSize / (sn.samplebits / 8);
sn.samplepos = 0;
sn.submission_chunk = 1;
sn.buffer = lpData;
sample16 = (sn.samplebits / 8) - 1;
dsound_init = true;
@ -341,7 +339,7 @@ SNDDMA_InitDirect (void)
Try to find a sound device to mix for.
Returns false if nothing is found.
*/
static qboolean
static volatile dma_t *
SNDDMA_Init (void)
{
sndinitstat stat;
@ -362,7 +360,7 @@ SNDDMA_Init (void)
}
}
return 1;
return &sn;
}
/*
@ -385,7 +383,7 @@ SNDDMA_GetDMAPos (void)
Sys_Printf ("DSOUND_LockBuffer fails!\n");
return -1;
}
shm->buffer = (unsigned char *) pbuf;
sn.buffer = (unsigned char *) pbuf;
mmtime.wType = TIME_SAMPLES;
IDirectSoundBuffer_GetCurrentPosition (pDSBuf, &mmtime.u.sample,
&dwWrite);
@ -393,7 +391,7 @@ SNDDMA_GetDMAPos (void)
s >>= sample16;
s &= (shm->samples - 1);
s &= (sn.samples - 1);
return s;
}
@ -472,7 +470,7 @@ DSOUND_ClearBuffer (int clear)
// FIXME: this should be called with 2nd pbuf2 = NULL, dwsize =0
pData = DSOUND_LockBuffer (true);
memset (pData, clear, shm->samples * shm->samplebits / 8);
memset (pData, clear, sn.samples * sn.samplebits / 8);
DSOUND_LockBuffer (false);
}

View file

@ -131,17 +131,15 @@ SNDDMA_InitWav ( void )
snd_sent = 0;
snd_completed = 0;
shm = &sn;
shm->channels = 2;
shm->samplebits = 16;
shm->speed = 11025;
sn.channels = 2;
sn.samplebits = 16;
sn.speed = 11025;
memset(format, 0, sizeof(*format));
format->wf.wFormatTag = WAVE_FORMAT_PCM;
format->wf.nChannels = shm->channels;
format->wBitsPerSample = shm->samplebits;
format->wf.nSamplesPerSec = shm->speed;
format->wf.nChannels = sn.channels;
format->wBitsPerSample = sn.samplebits;
format->wf.nSamplesPerSec = sn.speed;
format->wf.nBlockAlign = format->wf.nChannels
*format->wBitsPerSample / 8;
format->wf.nAvgBytesPerSec = format->wf.nSamplesPerSec
@ -200,13 +198,13 @@ SNDDMA_InitWav ( void )
lpWaveHdr[i].lpData = lpData + i*WAV_BUFFER_SIZE;
}
shm->soundalive = true;
shm->splitbuffer = false;
shm->samples = gSndBufSize/(shm->samplebits/8);
shm->samplepos = 0;
shm->submission_chunk = 1;
shm->buffer = (unsigned char *) lpData;
sample16 = (shm->samplebits/8) - 1;
sn.soundalive = true;
sn.splitbuffer = false;
sn.samples = gSndBufSize/(sn.samplebits/8);
sn.samplepos = 0;
sn.submission_chunk = 1;
sn.buffer = (unsigned char *) lpData;
sample16 = (sn.samplebits/8) - 1;
wav_init = true;
@ -219,7 +217,7 @@ SNDDMA_InitWav ( void )
Try to find a sound device to mix for.
Returns false if nothing is found.
*/
static qboolean
static volatile dma_t *
SNDDMA_Init ( void )
{
wav_init = 0;
@ -245,7 +243,7 @@ SNDDMA_Init ( void )
return 0;
}
return 1;
return &sn;
}
/*
@ -266,7 +264,7 @@ SNDDMA_GetDMAPos ( void )
s >>= sample16;
s &= (shm->samples-1);
s &= (sn.samples-1);
return s;
}

View file

@ -115,7 +115,7 @@ SNDDMA_Init_Cvars (void)
"mmaped io");
}
static int
static volatile dma_t *
try_open (int rw)
{
int caps, fmt, rc, tmp, i;
@ -176,67 +176,66 @@ try_open (int rw)
return 0;
}
shm = &sn;
shm->splitbuffer = 0;
sn.splitbuffer = 0;
// set sample bits & speed
shm->samplebits = snd_bits->int_val;
sn.samplebits = snd_bits->int_val;
if (shm->samplebits != 16 && shm->samplebits != 8) {
if (sn.samplebits != 16 && sn.samplebits != 8) {
ioctl (audio_fd, SNDCTL_DSP_GETFMTS, &fmt);
if (fmt & AFMT_S16_LE) { // little-endian 16-bit signed
shm->samplebits = 16;
sn.samplebits = 16;
} else {
if (fmt & AFMT_U8) { // unsigned 8-bit ulaw
shm->samplebits = 8;
sn.samplebits = 8;
}
}
}
if (snd_rate->int_val) {
shm->speed = snd_rate->int_val;
sn.speed = snd_rate->int_val;
} else {
for (i = 0; i < ((int) sizeof (tryrates) / 4); i++)
if (!ioctl (audio_fd, SNDCTL_DSP_SPEED, &tryrates[i]))
break;
shm->speed = tryrates[i];
sn.speed = tryrates[i];
}
if (!snd_stereo->int_val) {
shm->channels = 1;
sn.channels = 1;
} else {
shm->channels = 2;
sn.channels = 2;
}
shm->samples = info.fragstotal * info.fragsize / (shm->samplebits / 8);
shm->submission_chunk = 1;
sn.samples = info.fragstotal * info.fragsize / (sn.samplebits / 8);
sn.submission_chunk = 1;
tmp = 0;
if (shm->channels == 2)
if (sn.channels == 2)
tmp = 1;
rc = ioctl (audio_fd, SNDCTL_DSP_STEREO, &tmp);
if (rc < 0) {
Sys_Printf ("Could not set %s to stereo=%d: %s\n", snd_dev,
shm->channels, strerror (errno));
sn.channels, strerror (errno));
close (audio_fd);
return 0;
}
if (tmp)
shm->channels = 2;
sn.channels = 2;
else
shm->channels = 1;
sn.channels = 1;
rc = ioctl (audio_fd, SNDCTL_DSP_SPEED, &shm->speed);
rc = ioctl (audio_fd, SNDCTL_DSP_SPEED, &sn.speed);
if (rc < 0) {
Sys_Printf ("Could not set %s speed to %d: %s\n", snd_dev, shm->speed,
Sys_Printf ("Could not set %s speed to %d: %s\n", snd_dev, sn.speed,
strerror (errno));
close (audio_fd);
return 0;
}
if (shm->samplebits == 16) {
if (sn.samplebits == 16) {
rc = AFMT_S16_LE;
rc = ioctl (audio_fd, SNDCTL_DSP_SETFMT, &rc);
if (rc < 0) {
@ -245,7 +244,7 @@ try_open (int rw)
close (audio_fd);
return 0;
}
} else if (shm->samplebits == 8) {
} else if (sn.samplebits == 8) {
rc = AFMT_U8;
rc = ioctl (audio_fd, SNDCTL_DSP_SETFMT, &rc);
if (rc < 0) {
@ -255,7 +254,7 @@ try_open (int rw)
return 0;
}
} else {
Sys_Printf ("%d-bit sound not supported. %s", shm->samplebits,
Sys_Printf ("%d-bit sound not supported. %s", sn.samplebits,
strerror (errno));
close (audio_fd);
return 0;
@ -266,15 +265,15 @@ try_open (int rw)
unsigned long len = info.fragstotal * info.fragsize;
len = (len + sz - 1) & ~(sz - 1);
shm->buffer = (byte *) mmap (NULL, len, mmmode, mmflags, audio_fd, 0);
if (shm->buffer == MAP_FAILED) {
sn.buffer = (byte *) mmap (NULL, len, mmmode, mmflags, audio_fd, 0);
if (sn.buffer == MAP_FAILED) {
Sys_Printf ("Could not mmap %s: %s\n", snd_dev, strerror (errno));
close (audio_fd);
return 0;
}
} else {
shm->buffer = malloc (shm->samples * (shm->samplebits / 8) * 2);
if (!shm->buffer) {
sn.buffer = malloc (sn.samples * (sn.samplebits / 8) * 2);
if (!sn.buffer) {
Sys_Printf ("SNDDMA_Init: memory allocation failure\n");
close (audio_fd);
return 0;
@ -287,7 +286,7 @@ try_open (int rw)
if (rc < 0) {
Sys_Printf ("Could not toggle.: %s\n", strerror (errno));
if (mmaped_io)
munmap (shm->buffer, shm->samples * shm->samplebits / 8);
munmap (sn.buffer, sn.samples * sn.samplebits / 8);
close (audio_fd);
return 0;
}
@ -296,22 +295,23 @@ try_open (int rw)
if (rc < 0) {
Sys_Printf ("Could not toggle.: %s\n", strerror (errno));
if (mmaped_io)
munmap (shm->buffer, shm->samples * shm->samplebits / 8);
munmap (sn.buffer, sn.samples * sn.samplebits / 8);
close (audio_fd);
return 0;
}
shm->samplepos = 0;
sn.samplepos = 0;
snd_inited = 1;
return 1;
return &sn;
}
static qboolean
static volatile dma_t *
SNDDMA_Init (void)
{
if (try_open (0))
return 1;
volatile dma_t *shm;
if ((shm = try_open (0)))
return shm;
return try_open (1);
}
@ -326,16 +326,16 @@ SNDDMA_GetDMAPos (void)
if (ioctl (audio_fd, SNDCTL_DSP_GETOPTR, &count) == -1) {
Sys_Printf ("Uh, %s dead: %s\n", snd_dev, strerror (errno));
if (mmaped_io)
munmap (shm->buffer, shm->samples * shm->samplebits / 8);
munmap (sn.buffer, sn.samples * sn.samplebits / 8);
close (audio_fd);
snd_inited = 0;
return 0;
}
// shm->samplepos = (count.bytes / (shm->samplebits / 8)) & (shm->samples-1);
// sn.samplepos = (count.bytes / (sn.samplebits / 8)) & (sn.samples-1);
// fprintf(stderr, "%d \r", count.ptr);
shm->samplepos = count.ptr / (shm->samplebits / 8);
sn.samplepos = count.ptr / (sn.samplebits / 8);
return shm->samplepos;
return sn.samplepos;
}
@ -344,13 +344,13 @@ SNDDMA_Shutdown (void)
{
if (snd_inited) {
if (mmaped_io)
munmap (shm->buffer, shm->samples * shm->samplebits / 8);
munmap (sn.buffer, sn.samples * sn.samplebits / 8);
close (audio_fd);
snd_inited = 0;
}
}
#define BITSIZE (shm->samplebits / 8)
#define BITSIZE (sn.samplebits / 8)
#define BYTES (samples / BITSIZE)
/*
@ -367,13 +367,13 @@ SNDDMA_Submit (void)
samples = *plugin_info_snd_output_data.paintedtime
- *plugin_info_snd_output_data.soundtime;
if (shm->samplepos + BYTES <= shm->samples)
write (audio_fd, shm->buffer + BYTES, samples);
if (sn.samplepos + BYTES <= sn.samples)
write (audio_fd, sn.buffer + BYTES, samples);
else {
write (audio_fd, shm->buffer + BYTES, shm->samples -
shm->samplepos);
write (audio_fd, shm->buffer, BYTES - (shm->samples -
shm->samplepos));
write (audio_fd, sn.buffer + BYTES, sn.samples -
sn.samplepos);
write (audio_fd, sn.buffer, BYTES - (sn.samples -
sn.samplepos));
}
*plugin_info_snd_output_data.soundtime += samples;
}

View file

@ -49,7 +49,7 @@ static __attribute__ ((unused)) const char rcsid[] =
#include "QF/sound.h"
#include "QF/sys.h"
static dma_t the_shm;
static dma_t sn;
static int snd_inited;
static int snd_blocked = 0;
@ -70,26 +70,24 @@ paint_audio (void *unused, Uint8 * stream, int len)
{
int sampleposbytes, samplesbytes, streamsamples;
if (shm) {
streamsamples = len / (shm->samplebits / 8);
sampleposbytes = shm->samplepos * (shm->samplebits / 8);
samplesbytes = shm->samples * (shm->samplebits / 8);
streamsamples = len / (sn.samplebits / 8);
sampleposbytes = sn.samplepos * (sn.samplebits / 8);
samplesbytes = sn.samples * (sn.samplebits / 8);
shm->samplepos += streamsamples;
while (shm->samplepos >= shm->samples)
shm->samplepos -= shm->samples;
// SND_PaintChannels (*plugin_info_snd_output_data.soundtime + streamsamples);
sn.samplepos += streamsamples;
while (sn.samplepos >= sn.samples)
sn.samplepos -= sn.samples;
// SND_PaintChannels (*plugin_info_snd_output_data.soundtime + streamsamples);
if (shm->samplepos + streamsamples <= shm->samples)
memcpy (stream, shm->buffer + sampleposbytes, len);
else {
memcpy (stream, shm->buffer + sampleposbytes, samplesbytes -
sampleposbytes);
memcpy (stream + samplesbytes - sampleposbytes, shm->buffer, len -
(samplesbytes - sampleposbytes));
}
*plugin_info_snd_output_data.soundtime += streamsamples;
if (sn.samplepos + streamsamples <= sn.samples)
memcpy (stream, sn.buffer + sampleposbytes, len);
else {
memcpy (stream, sn.buffer + sampleposbytes, samplesbytes -
sampleposbytes);
memcpy (stream + samplesbytes - sampleposbytes, sn.buffer, len -
(samplesbytes - sampleposbytes));
}
*plugin_info_snd_output_data.soundtime += streamsamples;
}
static void
@ -97,7 +95,7 @@ SNDDMA_Init_Cvars (void)
{
}
static qboolean
static volatile dma_t *
SNDDMA_Init (void)
{
SDL_AudioSpec desired, obtained;
@ -164,28 +162,27 @@ SNDDMA_Init (void)
SDL_PauseAudio (0);
/* Fill the audio DMA information block */
shm = &the_shm;
shm->splitbuffer = 0;
shm->samplebits = (obtained.format & 0xFF);
shm->speed = obtained.freq;
shm->channels = obtained.channels;
shm->samples = obtained.samples * 16;
shm->samplepos = 0;
shm->submission_chunk = 1;
shm->buffer = calloc(shm->samples * (shm->samplebits / 8), 1);
if (!shm->buffer)
sn.splitbuffer = 0;
sn.samplebits = (obtained.format & 0xFF);
sn.speed = obtained.freq;
sn.channels = obtained.channels;
sn.samples = obtained.samples * 16;
sn.samplepos = 0;
sn.submission_chunk = 1;
sn.buffer = calloc(sn.samples * (sn.samplebits / 8), 1);
if (!sn.buffer)
{
Sys_Error ("Failed to allocate buffer for sound!");
}
snd_inited = 1;
return 1;
return &sn;
}
static int
SNDDMA_GetDMAPos (void)
{
return shm->samplepos;
return sn.samplepos;
}
static void
@ -196,7 +193,6 @@ SNDDMA_Shutdown (void)
SDL_UnlockAudio ();
SDL_CloseAudio ();
snd_inited = 0;
shm = NULL;
}
}

View file

@ -64,7 +64,7 @@ static snd_output_data_t plugin_info_snd_output_data;
static snd_output_funcs_t plugin_info_snd_output_funcs;
static qboolean
static volatile dma_t *
SNDDMA_Init (void)
{
char *s;
@ -79,8 +79,7 @@ SNDDMA_Init (void)
return 0;
}
shm = &sn;
shm->splitbuffer = 0;
sn.splitbuffer = 0;
/* get & probe settings */
/* sample format */
@ -94,11 +93,11 @@ SNDDMA_Init (void)
/* sample bits */
s = getenv ("QUAKE_SOUND_SAMPLEBITS");
if (s)
shm->samplebits = atoi (s);
sn.samplebits = atoi (s);
else if ((i = COM_CheckParm ("-sndbits")) != 0)
shm->samplebits = atoi (com_argv[i + 1]);
sn.samplebits = atoi (com_argv[i + 1]);
if (shm->samplebits != 16 && shm->samplebits != 8) {
if (sn.samplebits != 16 && sn.samplebits != 8) {
alpv.param = AL_WORDSIZE;
if (alGetParams (AL_DEFAULT_OUTPUT, &alpv, 1) < 0) {
@ -108,10 +107,10 @@ SNDDMA_Init (void)
}
if (alpv.value.i >= 16) {
shm->samplebits = 16;
sn.samplebits = 16;
} else {
if (alpv.value.i >= 8)
shm->samplebits = 8;
sn.samplebits = 8;
else {
Sys_Printf ("Sound disabled since interface "
"doesn't even support 8 bit.");
@ -124,9 +123,9 @@ SNDDMA_Init (void)
/* sample rate */
s = getenv ("QUAKE_SOUND_SPEED");
if (s)
shm->speed = atoi (s);
sn.speed = atoi (s);
else if ((i = COM_CheckParm ("-sndspeed")) != 0)
shm->speed = atoi (com_argv[i + 1]);
sn.speed = atoi (com_argv[i + 1]);
else {
alpv.param = AL_RATE;
@ -144,33 +143,33 @@ SNDDMA_Init (void)
return 0;
}
shm->speed = tryrates[i];
sn.speed = tryrates[i];
}
/* channels */
s = getenv ("QUAKE_SOUND_CHANNELS");
if (s)
shm->channels = atoi (s);
sn.channels = atoi (s);
else if ((i = COM_CheckParm ("-sndmono")) != 0)
shm->channels = 1;
sn.channels = 1;
else if ((i = COM_CheckParm ("-sndstereo")) != 0)
shm->channels = 2;
sn.channels = 2;
else
shm->channels = 2;
sn.channels = 2;
/* set 'em */
/* channels */
while (shm->channels > 0) {
if (alSetChannels (alc, shm->channels) < 0) {
while (sn.channels > 0) {
if (alSetChannels (alc, sn.channels) < 0) {
Sys_Printf ("Unable to set number of channels to %d, "
"trying half\n", shm->channels);
shm->channels /= 2;
"trying half\n", sn.channels);
sn.channels /= 2;
} else
break;
}
if (shm->channels <= 0) {
if (sn.channels <= 0) {
Sys_Printf ("Sound disabled since interface doesn't even support 1 "
"channel\n");
alFreeConfig (alc);
@ -179,11 +178,11 @@ SNDDMA_Init (void)
/* sample rate */
alpv.param = AL_RATE;
alpv.value.ll = alDoubleToFixed (shm->speed);
alpv.value.ll = alDoubleToFixed (sn.speed);
if (alSetParams (AL_DEFAULT_OUTPUT, &alpv, 1) < 0) {
Sys_Printf ("Could not set samplerate of default output to %d: %s\n",
shm->speed, alGetErrorString (oserror ()));
sn.speed, alGetErrorString (oserror ()));
alFreeConfig (alc);
return 0;
}
@ -192,7 +191,7 @@ SNDDMA_Init (void)
frequency of 11025 use *huge* buffers since at least my indigo2
has enough to do to get sound on the way anyway
*/
bufsize = 32768 * (int) ((double) shm->speed / 11025.0);
bufsize = 32768 * (int) ((double) sn.speed / 11025.0);
dma_buffer = malloc (bufsize);
@ -214,7 +213,7 @@ SNDDMA_Init (void)
}
/* sample bits */
switch (shm->samplebits) {
switch (sn.samplebits) {
case 24:
i = AL_SAMPLE_24;
break;
@ -230,7 +229,7 @@ SNDDMA_Init (void)
if (alSetWidth (alc, i) < 0) {
Sys_Printf ("Could not set wordsize of default output to %d: %s\n",
shm->samplebits, alGetErrorString (oserror ()));
sn.samplebits, alGetErrorString (oserror ()));
free (write_buffer);
free (dma_buffer);
alFreeConfig (alc);
@ -248,16 +247,16 @@ SNDDMA_Init (void)
return 0;
}
shm->soundalive = true;
shm->samples = bufsize / (shm->samplebits / 8);
shm->samplepos = 0;
shm->submission_chunk = 1;
shm->buffer = dma_buffer;
sn.soundalive = true;
sn.samples = bufsize / (sn.samplebits / 8);
sn.samplepos = 0;
sn.submission_chunk = 1;
sn.buffer = dma_buffer;
framecount = 0;
snd_inited = 1;
return 1;
return &sn;
}
static void
@ -268,11 +267,11 @@ SNDDMA_Init_Cvars (void)
static int
SNDDMA_GetDMAPos (void)
{
/* Sys_Printf("framecount: %d %d\n", (framecount * shm->channels) %
shm->samples, alGetFilled(alp)); */
shm->samplepos = ((framecount - alGetFilled (alp))
* shm->channels) % shm->samples;
return shm->samplepos;
/* Sys_Printf("framecount: %d %d\n", (framecount * sn.channels) %
sn.samples, alGetFilled(alp)); */
sn.samplepos = ((framecount - alGetFilled (alp))
* sn.channels) % sn.samples;
return sn.samplepos;
}
static void
@ -305,7 +304,7 @@ SNDDMA_Submit (void)
if (*plugin_info_snd_output_data.paintedtime < wbufp)
wbufp = 0; // reset
bsize = shm->channels * (shm->samplebits / 8);
bsize = sn.channels * (sn.samplebits / 8);
bytes = (*plugin_info_snd_output_data.paintedtime - wbufp) * bsize;
if (!bytes)

View file

@ -75,7 +75,7 @@ static snd_output_data_t plugin_info_sound_data;
static snd_output_funcs_t plugin_info_sound_funcs;
static qboolean
static volatile dma_t *
SNDDMA_Init (void)
{
if (snd_inited) {
@ -83,8 +83,7 @@ SNDDMA_Init (void)
return 0;
}
shm = &sn;
shm->splitbuffer = 0;
sn.splitbuffer = 0;
audio_fd = open ("/dev/audio", O_WRONLY | O_NDELAY);
@ -112,7 +111,7 @@ SNDDMA_Init (void)
AUDIO_INITINFO (&info);
shm->speed = 11025;
sn.speed = 11025;
// try 16 bit stereo
info.play.encoding = AUDIO_ENCODING_LINEAR;
@ -131,23 +130,23 @@ SNDDMA_Init (void)
return 0;
}
Sys_Printf ("16 bit mono sound initialized\n");
shm->samplebits = 16;
shm->channels = 1;
sn.samplebits = 16;
sn.channels = 1;
} else { // 16 bit stereo
Sys_Printf ("16 bit stereo sound initialized\n");
shm->samplebits = 16;
shm->channels = 2;
sn.samplebits = 16;
sn.channels = 2;
}
shm->soundalive = true;
shm->samples = sizeof (dma_buffer) / (shm->samplebits / 8);
shm->samplepos = 0;
shm->submission_chunk = 1;
shm->buffer = (unsigned char *) dma_buffer;
sn.soundalive = true;
sn.samples = sizeof (dma_buffer) / (sn.samplebits / 8);
sn.samplepos = 0;
sn.submission_chunk = 1;
sn.buffer = (unsigned char *) dma_buffer;
snd_inited = 1;
return 1;
return &sn;
}
static int
@ -164,7 +163,7 @@ SNDDMA_GetDMAPos (void)
return (0);
}
return ((info.play.samples * shm->channels) % shm->samples);
return ((info.play.samples * sn.channels) % sn.samples);
}
static int
@ -212,7 +211,7 @@ SNDDMA_Submit (void)
if (*plugin_info_sound_data.paintedtime < wbufp)
wbufp = 0; // reset
bsize = shm->channels * (shm->samplebits / 8);
bsize = sn.channels * (sn.samplebits / 8);
bytes = (*plugin_info_sound_data.paintedtime - wbufp) * bsize;
if (!bytes)

View file

@ -152,17 +152,15 @@ SNDDMA_InitWav (void)
snd_sent = 0;
snd_completed = 0;
shm = &sn;
shm->channels = 2;
shm->samplebits = 16;
shm->speed = 11025;
sn.channels = 2;
sn.samplebits = 16;
sn.speed = 11025;
memset (&format, 0, sizeof (format));
format.wFormatTag = WAVE_FORMAT_PCM;
format.nChannels = shm->channels;
format.wBitsPerSample = shm->samplebits;
format.nSamplesPerSec = shm->speed;
format.nChannels = sn.channels;
format.wBitsPerSample = sn.samplebits;
format.nSamplesPerSec = sn.speed;
format.nBlockAlign = format.nChannels * format.wBitsPerSample / 8;
format.cbSize = 0;
format.nAvgBytesPerSec = format.nSamplesPerSec * format.nBlockAlign;
@ -236,13 +234,13 @@ SNDDMA_InitWav (void)
}
}
shm->soundalive = true;
shm->splitbuffer = false;
shm->samples = gSndBufSize / (shm->samplebits / 8);
shm->samplepos = 0;
shm->submission_chunk = 1;
shm->buffer = (unsigned char *) lpData;
sample16 = (shm->samplebits / 8) - 1;
sn.soundalive = true;
sn.splitbuffer = false;
sn.samples = gSndBufSize / (sn.samplebits / 8);
sn.samplepos = 0;
sn.submission_chunk = 1;
sn.buffer = (unsigned char *) lpData;
sample16 = (sn.samplebits / 8) - 1;
return true;
}
@ -253,7 +251,7 @@ SNDDMA_InitWav (void)
Try to find a sound device to mix for.
Returns false if nothing is found.
*/
static qboolean
static volatile dma_t *
SNDDMA_Init (void)
{
if (snd_firsttime) {
@ -265,7 +263,7 @@ SNDDMA_Init (void)
}
snd_firsttime = false;
return 1;
return &sn;
}
/*
@ -284,7 +282,7 @@ SNDDMA_GetDMAPos (void)
s >>= sample16;
s &= (shm->samples - 1);
s &= (sn.samples - 1);
return s;
}