diff options
author | Luo Jinghua <sunmoon1997@gmail.com> | 2010-10-26 16:43:25 +0800 |
---|---|---|
committer | Luo Jinghua <sunmoon1997@gmail.com> | 2010-10-26 16:43:25 +0800 |
commit | 4c91f355e83c0091c05ddeea7a85788db6fe3ee3 (patch) | |
tree | 7cf65e554fd58cbab06d06b46fdbefae017bb8a9 /src | |
parent | 77530c5c158d1fbb45bc4f51198eb6b57a222e79 (diff) |
alsa: don't hardcode sample rate and buffer size
Diffstat (limited to 'src')
-rw-r--r-- | src/device_alsa.cpp | 20 | ||||
-rw-r--r-- | src/device_alsa.h | 8 |
2 files changed, 16 insertions, 12 deletions
diff --git a/src/device_alsa.cpp b/src/device_alsa.cpp index b727825..5a8652f 100644 --- a/src/device_alsa.cpp +++ b/src/device_alsa.cpp @@ -11,7 +11,8 @@ namespace audiere { static snd_pcm_t* openDevice(const std::string &name, - unsigned int rate) { + unsigned int &rate, + unsigned int &bufsz) { int status = 0; snd_pcm_t* pcm_handle = 0; @@ -148,6 +149,7 @@ namespace audiere { return 0; } + bufsz = period_size * channels * 2; return pcm_handle; } @@ -160,15 +162,15 @@ namespace audiere { if (default_device != devices[0]) devices[0] = default_device; - int i, rate; + unsigned int i, rate, buffer_size; snd_pcm_t* pcm_handle = 0; for (i = 0; devices[i].length() > 0; i++) { rate = 48000; - pcm_handle = openDevice(devices[i], rate); + pcm_handle = openDevice(devices[i], rate, buffer_size); if (!pcm_handle) { rate = 44100; - pcm_handle = openDevice(devices[i], rate); + pcm_handle = openDevice(devices[i], rate, buffer_size); } if (pcm_handle) break; @@ -178,14 +180,14 @@ namespace audiere { return 0; } - return new ALSAAudioDevice(pcm_handle, devices[i], rate, 4096); + return new ALSAAudioDevice(pcm_handle, devices[i], rate, buffer_size); } ALSAAudioDevice::ALSAAudioDevice(snd_pcm_t* pcm_handle, const std::string &name, - int rate, - int buffer_size) + unsigned int rate, + unsigned int buffer_size) : MixerDevice(rate), m_pcm_name(name), m_rate(rate) { m_pcm_handle = pcm_handle; @@ -214,11 +216,13 @@ namespace audiere { // reopen a pcm if (!m_pcm_handle) { - m_pcm_handle = openDevice(m_pcm_name, m_rate); + m_pcm_handle = openDevice(m_pcm_name, m_rate, m_buffer_size); if (!m_pcm_handle) { usleep(100); return; } + delete [] m_buffer; + m_buffer = new char [m_buffer_size]; } sample_buf = m_buffer; diff --git a/src/device_alsa.h b/src/device_alsa.h index b93383e..a4e3289 100644 --- a/src/device_alsa.h +++ b/src/device_alsa.h @@ -16,8 +16,8 @@ namespace audiere { private: ALSAAudioDevice(snd_pcm_t* pcm_handle, const std::string &name, - int rate, - int buffer_size); + unsigned int rate, + unsigned int buffer_size); ~ALSAAudioDevice(); public: @@ -26,10 +26,10 @@ namespace audiere { private: snd_pcm_t* m_pcm_handle; - int m_buffer_size; + unsigned int m_buffer_size; char* m_buffer; std::string m_pcm_name; - int m_rate; + unsigned int m_rate; }; } |