#include "snd_main.h"
int audio_fd;
-int snd_inited;
-static int tryrates[] = {44100, 22050, 11025, 8000};
+static int tryrates[] = {44100, 48000, 22050, 24000, 11025, 16000, 8000};
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
shm->format.speed = atoi(com_argv[i+1]);
else
{
- for (i = 0;i < (int) sizeof(tryrates) / sizeof(tryrates[0]);i++)
+ for (i = 0;i < (int) sizeof(tryrates) / (int) sizeof(tryrates[0]);i++)
if (!ioctl(audio_fd, SNDCTL_DSP_SPEED, &tryrates[i]))
break;
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;
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;
}
/*