X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=snd_alsa.c;h=3f4292c84e7f73edf2a2f49a7f36707c0980a374;hb=ff0a7f475d95e5180b85d1c574b0b9a3156aa525;hp=59c85edfcacb9ac79ae3b6aa21e81c4d99b575fb;hpb=65f6c04779aa58c69929e0d22967bf152dac17c1;p=xonotic%2Fdarkplaces.git diff --git a/snd_alsa.c b/snd_alsa.c index 59c85edf..3f4292c8 100644 --- a/snd_alsa.c +++ b/snd_alsa.c @@ -30,7 +30,7 @@ #include "snd_main.h" -#define NB_PERIODS 2 +#define NB_PERIODS 4 static snd_pcm_t* pcm_handle = NULL; static snd_pcm_sframes_t expected_delay = 0; @@ -57,6 +57,7 @@ qboolean SndSys_Init (const snd_format_t* requested, snd_format_t* suggested) Con_Print ("SndSys_Init: using the ALSA module\n"); seq_name = NULL; +// COMMANDLINEOPTION: Linux ALSA Sound: -sndseqin : selects which sequencer port to use for input, by default no sequencer port is used (MIDI note events from that port get mapped to MIDINOTE keys that can be bound) i = COM_CheckParm ("-sndseqin"); // TODO turn this into a cvar, maybe if (i != 0 && i < com_argc - 1) seq_name = com_argv[i + 1]; @@ -150,7 +151,7 @@ seqdone: pcm_name = "default"; break; } -// COMMANDLINEOPTION: Linux ALSA Sound: -sndpcm selects which pcm device to us, default is "default" +// COMMANDLINEOPTION: Linux ALSA Sound: -sndpcm selects which pcm device to use, default is "default" i = COM_CheckParm ("-sndpcm"); if (i != 0 && i < com_argc - 1) pcm_name = com_argv[i + 1]; @@ -221,7 +222,14 @@ seqdone: goto init_error; } - buffer_size = requested->speed / 5; + // pick a buffer size that is a power of 2 (by masking off low bits) + buffer_size = i = (int)(requested->speed * 0.15f); + while (buffer_size & (buffer_size-1)) + buffer_size &= (buffer_size-1); + // then check if it is the nearest power of 2 and bump it up if not + if (i - buffer_size >= buffer_size >> 1) + buffer_size *= 2; + err = snd_pcm_hw_params_set_buffer_size_near (pcm_handle, hw_params, &buffer_size); if (err < 0) { @@ -230,6 +238,8 @@ seqdone: goto init_error; } + // pick a period size near the buffer_size we got from ALSA + snd_pcm_hw_params_get_buffer_size (hw_params, &buffer_size); buffer_size /= NB_PERIODS; err = snd_pcm_hw_params_set_period_size_near(pcm_handle, hw_params, &buffer_size, 0); if (err < 0) @@ -343,8 +353,8 @@ static snd_pcm_sframes_t SndSys_Write (const unsigned char* buffer, unsigned int written = snd_pcm_writei (pcm_handle, buffer, nbframes); if (written < 0) { - if (developer.integer >= 1000 && vid_activewindow) - Con_Printf ("SndSys_Write: audio write returned %ld (%s)!\n", + if (developer_insane.integer && vid_activewindow) + Con_DPrintf ("SndSys_Write: audio write returned %ld (%s)!\n", written, snd_strerror (written)); if (SndSys_Recover (written)) @@ -421,7 +431,7 @@ unsigned int SndSys_GetSoundTime (void) err = snd_pcm_delay (pcm_handle, &delay); if (err < 0) { - if (developer.integer >= 1000 && vid_activewindow) + if (developer_insane.integer && vid_activewindow) Con_DPrintf ("SndSys_GetSoundTime: can't get playback delay (%s)\n", snd_strerror (err));