#include "quakedef.h"
#include "snd_main.h"
-static int snd_inited;
static snd_pcm_uframes_t buffer_size;
static const char *pcmname = NULL;
shm->samples = shm->sampleframes * shm->format.channels;
SNDDMA_GetDMAPos (); // sets shm->buffer
- snd_inited = 1;
return true;
}
return false;
snd_pcm_uframes_t offset;
snd_pcm_uframes_t nframes = shm->sampleframes;
- if (!snd_inited)
+ if (!shm)
return 0;
snd_pcm_avail_update (pcm);
void SNDDMA_Shutdown (void)
{
- if (snd_inited) {
- snd_pcm_close (pcm);
- snd_inited = 0;
- }
+ snd_pcm_close (pcm);
}
/*
static const int tryrates[] = {44100, 22050, 11025, 8000};
static int audio_fd = -1;
-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)
shm->samplepos = 0;
shm->buffer = dma_buffer;
- snd_inited = true;
return true;
}
{
audio_info_t info;
- if (!snd_inited)
+ if (!shm)
return 0;
if (ioctl (audio_fd, AUDIO_GETINFO, &info) < 0)
void SNDDMA_Shutdown (void)
{
- if (snd_inited)
- {
- close (audio_fd);
- audio_fd = -1;
- snd_inited = false;
- }
+ close (audio_fd);
+ audio_fd = -1;
}
/*
int idx;
int stop = paintedtime;
- if (!snd_inited)
+ if (!shm)
return;
if (paintedtime < wbufp)
// Linked list of known sfx
sfx_t *known_sfx = NULL;
-qboolean sound_started = false;
qboolean sound_spatialized = false;
// Fake dma is a synchronous faking of the DMA progress used for
void S_SoundInfo_f(void)
{
- if (!sound_started)
+ if (!shm)
{
Con_Print("sound system not started\n");
return;
{
Con_Print("S_Startup: SNDDMA_Init failed.\n");
shm = NULL;
- sound_started = false;
sound_spatialized = false;
return;
}
}
- sound_started = true;
-
Con_Printf("Sound format: %dHz, %d bit, %d channels\n", shm->format.speed,
shm->format.width * 8, shm->format.channels);
}
void S_Shutdown(void)
{
- if (!sound_started)
+ if (!shm)
return;
if (fakedma)
SNDDMA_Shutdown();
shm = NULL;
- sound_started = false;
sound_spatialized = false;
}
int ch_idx;
int skip;
- if (!sound_started || !sfx || nosound.integer)
+ if (!shm || !sfx || nosound.integer)
return -1;
if (!sfx->fetcher)
{
unsigned int i;
unsigned char *pbuf;
- if (!sound_started)
+ if (!shm)
return;
for (i = 0; i < total_channels; i++)
{
channel_t *target_chan;
- if (!sound_started || !sfx || nosound.integer)
+ if (!shm || !sfx || nosound.integer)
return;
if (!sfx->fetcher)
{
channel_t *ch, *combine;
matrix4x4_t basematrix, rotatematrix;
- if (!snd_initialized.integer || (snd_blocked > 0))
+ if (!snd_initialized.integer || (snd_blocked > 0) || !shm)
return;
Matrix4x4_Invert_Simple(&basematrix, listenermatrix);
{
unsigned endtime;
- if (!sound_started || (snd_blocked > 0))
+ if (!shm || (snd_blocked > 0))
return;
// Updates DMA time
#include "snd_main.h"
int audio_fd;
-int snd_inited;
static int tryrates[] = {44100, 22050, 11025, 8000};
#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
shm->samplepos = 0;
- snd_inited = 1;
return 1;
}
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;
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;
}
/*