diff --git a/desmume/src/mic_alsa.cpp b/desmume/src/mic_alsa.cpp index 965ad27c4..02f20cbdc 100644 --- a/desmume/src/mic_alsa.cpp +++ b/desmume/src/mic_alsa.cpp @@ -36,72 +36,67 @@ u8 Mic_WriteBuf; int MicButtonPressed; -// Handle for the PCM device +/* Alsa stuff */ static snd_pcm_t *pcm_handle; BOOL Mic_Init() { snd_pcm_hw_params_t *hwparams; + snd_pcm_uframes_t mic_bufsize, periods; int err; if (Mic_Inited) return TRUE; - // Open the default sound card in capture - if ((err = snd_pcm_open(&pcm_handle, "plughw:0,0", SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK)) < 0) { + if ((err = snd_pcm_open(&pcm_handle, "default", SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK)) < 0) { g_printerr("Failed to open device: %s\n", snd_strerror(err)); return FALSE; } - // Allocate the snd_pcm_hw_params_t structure and fill it. + /* Hardware params */ snd_pcm_hw_params_alloca(&hwparams); if ((err = snd_pcm_hw_params_any(pcm_handle, hwparams)) < 0) { g_printerr("Failed to setup hw parameters: %s\n", snd_strerror(err)); return FALSE; } - //Set the access if ((err = snd_pcm_hw_params_set_access(pcm_handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) { g_printerr("Failed to set access: %s\n", snd_strerror(err)); return FALSE; } - //dir 0 == exacte (Rate = 16K exacte) - if ((err = snd_pcm_hw_params_set_rate(pcm_handle, hwparams, 16000, 0)) < 0) { - g_printerr("Failed to set rate: %s\n", snd_strerror(err)); - return FALSE; - } - - /* Set sample format */ + /* 8bit signed, mono, 16000hz */ if ((err = snd_pcm_hw_params_set_format(pcm_handle, hwparams, SND_PCM_FORMAT_S8)) < 0) { g_printerr("Failed to set format: %s\n", snd_strerror(err)); return FALSE; } - // Set one channel (mono) if ((err = snd_pcm_hw_params_set_channels(pcm_handle, hwparams, 1)) < 0) { g_printerr("Failed to set channels: %s\n", snd_strerror(err)); return FALSE; } - // Set 2 periods - if ((err = snd_pcm_hw_params_set_periods(pcm_handle, hwparams, 2, 0)) < 0) { - g_printerr("Failed to set periods: %s\n", snd_strerror(err)); + if ((err = snd_pcm_hw_params_set_rate(pcm_handle, hwparams, 16000, 0)) < 0) { + g_printerr("Failed to set rate: %s\n", snd_strerror(err)); return FALSE; } - // Set the buffer sise - if ((err = snd_pcm_hw_params_set_buffer_size(pcm_handle, hwparams, MIC_BUFSIZE)) < 0) { - g_printerr("Failed to set buffer size: %s\n", snd_strerror(err)); - return FALSE; - } - - //Set the params if ((err = snd_pcm_hw_params(pcm_handle, hwparams)) < 0) { g_printerr("Failed to set hw parameters: %s\n", snd_strerror(err)); return FALSE; } + /* Query the driver for buffer and period sizes */ + if ((err = snd_pcm_hw_params_get_buffer_size(hwparams, &mic_bufsize)) < 0) { + g_printerr("Failed to get buffer size: %s\n", snd_strerror(err)); + return FALSE; + } + + if ((err = snd_pcm_hw_params_get_period_size(hwparams, &periods, 0)) < 0) { + g_printerr("Failed to get period size: %s\n", snd_strerror(err)); + return FALSE; + } + Mic_Inited = TRUE; Mic_Reset();