mirror of
https://git.code.sf.net/p/quake/nuq
synced 2025-02-16 09:01:16 +00:00
accept sound format paramtetsr and snd_alsa_0_6.c currently doesn't support
stereo for non-interleaved devices until I figure out how to get it to work. Kind of hard when I don't have such a device :(
This commit is contained in:
parent
d68561ccad
commit
e0679ee1bf
2 changed files with 71 additions and 23 deletions
|
@ -114,7 +114,7 @@ qboolean SNDDMA_Init(void)
|
|||
{
|
||||
int rc=0,i;
|
||||
char *err_msg="";
|
||||
int rate,format,bps,stereo,frag_size;
|
||||
int rate=-1,format=-1,bps,stereo=-1,frag_size;
|
||||
unsigned int mask;
|
||||
|
||||
mask = snd_cards_mask();
|
||||
|
@ -128,6 +128,27 @@ qboolean SNDDMA_Init(void)
|
|||
if ((i=COM_CheckParm("-snddev"))!=0) {
|
||||
dev=atoi(com_argv[i+1]);
|
||||
}
|
||||
if ((i=COM_CheckParm("-sndbits")) != 0) {
|
||||
i = atoi(com_argv[i+1]);
|
||||
if (i==16) {
|
||||
format = SND_PCM_SFMT_S16_LE;
|
||||
} else if (i==8) {
|
||||
format = SND_PCM_SFMT_U8;
|
||||
} else {
|
||||
Con_Printf("Error: invalid sample bits: %d\n", i);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if ((i=COM_CheckParm("-sndspeed")) != 0) {
|
||||
rate = atoi(com_argv[i+1]);
|
||||
if (rate!=44100 && rate!=22050 && rate!=11025) {
|
||||
Con_Printf("Error: invalid sample rate: %d\n", rate);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if ((i=COM_CheckParm("-sndmono")) != 0) {
|
||||
stereo=0;
|
||||
}
|
||||
if (card==-1) {
|
||||
for (card=0; card<SND_CARDS; card++) {
|
||||
if (!(mask & (1<<card)))
|
||||
|
@ -164,31 +185,31 @@ qboolean SNDDMA_Init(void)
|
|||
cinfo.channel = SND_PCM_CHANNEL_PLAYBACK;
|
||||
snd_pcm_channel_info(pcm_handle, &cinfo);
|
||||
Con_Printf("%08x %08x %08x\n",cinfo.flags,cinfo.formats,cinfo.rates);
|
||||
if (cinfo.rates & SND_PCM_RATE_44100) {
|
||||
if ((rate==-1 || rate==44100) && cinfo.rates & SND_PCM_RATE_44100) {
|
||||
rate=44100;
|
||||
frag_size=512; /* assuming stereo 8 bit */
|
||||
} else if (cinfo.rates & SND_PCM_RATE_22050) {
|
||||
} else if ((rate==-1 || rate==22050) && cinfo.rates & SND_PCM_RATE_22050) {
|
||||
rate=22050;
|
||||
frag_size=256; /* assuming stereo 8 bit */
|
||||
} else if (cinfo.rates & SND_PCM_RATE_11025) {
|
||||
} else if ((rate==-1 || rate==11025) && cinfo.rates & SND_PCM_RATE_11025) {
|
||||
rate=11025;
|
||||
frag_size=128; /* assuming stereo 8 bit */
|
||||
} else {
|
||||
Con_Printf("ALSA: desired rates not supported\n");
|
||||
goto error_2;
|
||||
}
|
||||
if (cinfo.formats & SND_PCM_FMT_S16_LE) {
|
||||
if ((format==-1 || format==SND_PCM_SFMT_S16_LE) && cinfo.formats & SND_PCM_FMT_S16_LE) {
|
||||
format=SND_PCM_SFMT_S16_LE;
|
||||
bps=16;
|
||||
frag_size*=2;
|
||||
} else if (cinfo.formats & SND_PCM_FMT_U8) {
|
||||
} else if ((format==-1 || format==SND_PCM_SFMT_U8) && cinfo.formats & SND_PCM_FMT_U8) {
|
||||
format=SND_PCM_SFMT_U8;
|
||||
bps=8;
|
||||
} else {
|
||||
Con_Printf("ALSA: desired formats not supported\n");
|
||||
goto error_2;
|
||||
}
|
||||
if (cinfo.max_voices>=2) {
|
||||
if (stereo && cinfo.max_voices>=2) {
|
||||
stereo=1;
|
||||
} else {
|
||||
stereo=0;
|
||||
|
|
|
@ -116,7 +116,7 @@ qboolean SNDDMA_Init(void)
|
|||
{
|
||||
int rc=0,i;
|
||||
char *err_msg="";
|
||||
int rate,format,bps,stereo,frag_size,frame_size;
|
||||
int rate=-1,format=-1,bps,stereo=-1,frag_size,frame_size;
|
||||
unsigned int mask;
|
||||
|
||||
mask = snd_cards_mask();
|
||||
|
@ -130,6 +130,27 @@ qboolean SNDDMA_Init(void)
|
|||
if ((i=COM_CheckParm("-snddev"))!=0) {
|
||||
dev=atoi(com_argv[i+1]);
|
||||
}
|
||||
if ((i=COM_CheckParm("-sndbits")) != 0) {
|
||||
i = atoi(com_argv[i+1]);
|
||||
if (i==16) {
|
||||
format = SND_PCM_SFMT_S16_LE;
|
||||
} else if (i==8) {
|
||||
format = SND_PCM_SFMT_U8;
|
||||
} else {
|
||||
Con_Printf("Error: invalid sample bits: %d\n", i);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if ((i=COM_CheckParm("-sndspeed")) != 0) {
|
||||
rate = atoi(com_argv[i+1]);
|
||||
if (rate!=44100 && rate!=22050 && rate!=11025) {
|
||||
Con_Printf("Error: invalid sample rate: %d\n", rate);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if ((i=COM_CheckParm("-sndmono")) != 0) {
|
||||
stereo=0;
|
||||
}
|
||||
if (card==-1) {
|
||||
for (card=0; card<SND_CARDS; card++) {
|
||||
if (!(mask & (1<<card)))
|
||||
|
@ -167,24 +188,24 @@ qboolean SNDDMA_Init(void)
|
|||
memset(&cpinfo, 0, sizeof(cpinfo));
|
||||
snd_pcm_params_info(pcm_handle, &cpinfo);
|
||||
Con_Printf("%08x %08x %08x\n",cinfo.flags,cpinfo.formats,cpinfo.rates);
|
||||
if (cpinfo.rates & SND_PCM_RATE_44100) {
|
||||
if ((rate==-1 || rate==44100) && cpinfo.rates & SND_PCM_RATE_44100) {
|
||||
rate=44100;
|
||||
frag_size=256; /* assuming stereo 8 bit */
|
||||
} else if (cpinfo.rates & SND_PCM_RATE_22050) {
|
||||
} else if ((rate==-1 || rate==22050) && cpinfo.rates & SND_PCM_RATE_22050) {
|
||||
rate=22050;
|
||||
frag_size=128; /* assuming stereo 8 bit */
|
||||
} else if (cpinfo.rates & SND_PCM_RATE_11025) {
|
||||
} else if ((rate==-1 || rate==11025) && cpinfo.rates & SND_PCM_RATE_11025) {
|
||||
rate=11025;
|
||||
frag_size=64; /* assuming stereo 8 bit */
|
||||
} else {
|
||||
Con_Printf("ALSA: desired rates not supported\n");
|
||||
goto error_2;
|
||||
}
|
||||
if (cpinfo.formats & SND_PCM_FMT_S16_LE) {
|
||||
if ((format==-1 || format==SND_PCM_SFMT_S16_LE) && cpinfo.formats & SND_PCM_FMT_S16_LE) {
|
||||
format=SND_PCM_SFMT_S16_LE;
|
||||
bps=16;
|
||||
frame_size=2;
|
||||
} else if (cpinfo.formats & SND_PCM_FMT_U8) {
|
||||
} else if ((format==-1 || format==SND_PCM_SFMT_U8) && cpinfo.formats & SND_PCM_FMT_U8) {
|
||||
format=SND_PCM_SFMT_U8;
|
||||
bps=8;
|
||||
frame_size=1;
|
||||
|
@ -192,7 +213,8 @@ qboolean SNDDMA_Init(void)
|
|||
Con_Printf("ALSA: desired formats not supported\n");
|
||||
goto error_2;
|
||||
}
|
||||
if (cpinfo.max_channels>=2) {
|
||||
//XXX can't support non-interleaved stereo
|
||||
if (stereo && (cinfo.flags & SND_PCM_INFO_INTERLEAVE) && cpinfo.max_channels>=2) {
|
||||
stereo=1;
|
||||
frame_size*=2;
|
||||
} else {
|
||||
|
@ -201,7 +223,7 @@ qboolean SNDDMA_Init(void)
|
|||
|
||||
memset(¶ms, 0, sizeof(params));
|
||||
params.mode = SND_PCM_MODE_FRAME;
|
||||
params.format.interleave=1;
|
||||
params.format.interleave=stereo;//XXX can't support non-interleaved stereo
|
||||
params.format.format=format;
|
||||
params.format.rate=rate;
|
||||
params.format.channels=stereo+1;
|
||||
|
@ -218,9 +240,19 @@ qboolean SNDDMA_Init(void)
|
|||
params.fill_max = 1024;
|
||||
params.boundary = params.buffer_size;
|
||||
|
||||
err_msg="audio params";
|
||||
if ((rc=snd_pcm_params(pcm_handle, ¶ms))<0)
|
||||
goto error;
|
||||
while (1) {
|
||||
err_msg="audio params";
|
||||
if ((rc=snd_pcm_params(pcm_handle, ¶ms))<0)
|
||||
goto error;
|
||||
|
||||
memset(&setup, 0, sizeof(setup));
|
||||
err_msg="audio setup";
|
||||
if ((rc=snd_pcm_setup(pcm_handle, &setup))<0)
|
||||
goto error;
|
||||
if (setup.buffer_size == params.buffer_size)
|
||||
break;
|
||||
params.boundary = params.buffer_size = setup.buffer_size;
|
||||
}
|
||||
|
||||
err_msg="audio mmap";
|
||||
if ((rc=snd_pcm_mmap(pcm_handle, &mmap_status, &mmap_control, (void **)&mmap_data))<0)
|
||||
|
@ -229,11 +261,6 @@ qboolean SNDDMA_Init(void)
|
|||
if ((rc=snd_pcm_prepare(pcm_handle))<0)
|
||||
goto error;
|
||||
|
||||
memset(&setup, 0, sizeof(setup));
|
||||
err_msg="audio setup";
|
||||
if ((rc=snd_pcm_setup(pcm_handle, &setup))<0)
|
||||
goto error;
|
||||
|
||||
shm=&sn;
|
||||
memset((dma_t*)shm,0,sizeof(*shm));
|
||||
shm->splitbuffer = 0;
|
||||
|
|
Loading…
Reference in a new issue