[alsa-devel] Increasing maximum sampling frequency?
I've got a USB microphone application that I want to sample at 256000 8 bit samples per second so I can listen to bats. I know that my device can get close to that rate, but alsa seems to restrict sampling rates to 192kHz.
Is it possible to push the maximum sampling frequency higher? If so, where should I start looking?
I tried hacking aplay.c so arecord would accept command line requests up to 256k, but it seems the alsa driver is also limiting the frequency to a maximum of 192k. However, the files generated by arecord *do* have the right number of samples in them.
$ arecord -v -Dplughw:1,0 test.wav -d 1 -r 256 Recording WAVE 'test.wav' : Unsigned 8 bit, Rate 256000 Hz, Mono Plug PCM: Linear conversion PCM (S8) Its setup is: stream : CAPTURE access : RW_INTERLEAVED format : U8 subformat : STD channels : 1 rate : 256000 exact rate : 256000 (256000/1) msbits : 8 buffer_size : 128000 period_size : 32000 period_time : 125000 tstamp_mode : NONE period_step : 1 avail_min : 32000 period_event : 0 start_threshold : 1 stop_threshold : 128000 silence_threshold: 0 silence_size : 0 boundary : 2097152000 Slave: Hardware PCM card 1 '8-Mic AVR Adaptor' device 0 subdevice 0 Its setup is: stream : CAPTURE access : MMAP_INTERLEAVED format : S8 subformat : STD channels : 1 rate : 256000 exact rate : 256000 (256000/1) msbits : 8 buffer_size : 128000 period_size : 32000 period_time : 125000 tstamp_mode : NONE period_step : 1 avail_min : 32000 period_event : 0 start_threshold : 1 stop_threshold : 128000 silence_threshold: 0 silence_size : 0 boundary : 2097152000 $ aplay -r 256 test.wav Playing WAVE 'test.wav' : Unsigned 8 bit, Rate 256000 Hz, Mono Warning: rate is not accurate (requested = 256000Hz, got = 192000Hz) please, try the plug plugin (-Dplug:default) $ ls -l test.wav -rw-r--r-- 1 camerons camerons 256044 2009-05-28 11:29 test.wav $ file test.wav test.wav: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 8 bit, mono 256000 Hz $
On Wed, May 27, 2009 at 9:47 PM, Cameron Stone camerons.lists@cse.unsw.edu.au wrote:
I've got a USB microphone application that I want to sample at 256000 8 bit samples per second so I can listen to bats. I know that my device can get close to that rate, but alsa seems to restrict sampling rates to 192kHz.
Is it possible to push the maximum sampling frequency higher? If so, where should I start looking?
For starters, try adding a 256K sample rate to include/sound/pcm.h:
118 #define SNDRV_PCM_RATE_176400 (1<<11) /* 176400Hz */ 119 #define SNDRV_PCM_RATE_192000 (1<<12) /* 192000Hz */ 120
and sound/core/pcm_native.c:
1762 1763 static unsigned int rates[] = { 5512, 8000, 11025, 16000, 22050, 32000, 44100, 1764 48000, 64000, 88200, 96000, 176400, 192000 }; 1765
Line numbers may vary, mine are from 2.6.27 kernel source.
Lee
Lee Revell wrote:
On Wed, May 27, 2009 at 9:47 PM, Cameron Stone camerons.lists@cse.unsw.edu.au wrote:
I've got a USB microphone application that I want to sample at 256000 8 bit samples per second so I can listen to bats. I know that my device can get close to that rate, but alsa seems to restrict sampling rates to 192kHz.
Is it possible to push the maximum sampling frequency higher? If so, where should I start looking?
For starters, try adding a 256K sample rate to include/sound/pcm.h: and sound/core/pcm_native.c:
This is not necessary; drivers can define whatever sample rate they want. 1,792,000 Hz works just fine with the Bt878 driver.
$ arecord -v -Dplughw:1,0 test.wav -d 1 -r 256 Recording WAVE 'test.wav' : Unsigned 8 bit, Rate 256000 Hz, Mono ... Slave: Hardware PCM card 1 '8-Mic AVR Adaptor' device 0 subdevice 0 Its setup is: ... rate : 256000
This indicates that the record PCM stream _does_ use the correct rate.
$ aplay -r 256 test.wav Playing WAVE 'test.wav' : Unsigned 8 bit, Rate 256000 Hz, Mono Warning: rate is not accurate (requested = 256000Hz, got = 192000Hz)
The automatic sample rate converter never uses a frequency higher than 192 kHz.
This maximum frequency is defined in alsa-lib/include/pcm_plugin.h, but you cannot change it without changing LINEAR_DIV and the algorithm in alsa-lib/src/pcm_pcm_rate_linear.c.
Try resampling the .wav file before with sox.
Best regards, Clemens
At Thu, 28 May 2009 08:52:44 +0200, Clemens Ladisch wrote:
Lee Revell wrote:
On Wed, May 27, 2009 at 9:47 PM, Cameron Stone camerons.lists@cse.unsw.edu.au wrote:
I've got a USB microphone application that I want to sample at 256000 8 bit samples per second so I can listen to bats. I know that my device can get close to that rate, but alsa seems to restrict sampling rates to 192kHz.
Is it possible to push the maximum sampling frequency higher? If so, where should I start looking?
For starters, try adding a 256K sample rate to include/sound/pcm.h: and sound/core/pcm_native.c:
This is not necessary; drivers can define whatever sample rate they want. 1,792,000 Hz works just fine with the Bt878 driver.
$ arecord -v -Dplughw:1,0 test.wav -d 1 -r 256 Recording WAVE 'test.wav' : Unsigned 8 bit, Rate 256000 Hz, Mono ... Slave: Hardware PCM card 1 '8-Mic AVR Adaptor' device 0 subdevice 0 Its setup is: ... rate : 256000
This indicates that the record PCM stream _does_ use the correct rate.
$ aplay -r 256 test.wav Playing WAVE 'test.wav' : Unsigned 8 bit, Rate 256000 Hz, Mono Warning: rate is not accurate (requested = 256000Hz, got = 192000Hz)
The automatic sample rate converter never uses a frequency higher than 192 kHz.
This maximum frequency is defined in alsa-lib/include/pcm_plugin.h, but you cannot change it without changing LINEAR_DIV and the algorithm in alsa-lib/src/pcm_pcm_rate_linear.c.
It's anyway better to user other resampler like pph or samplerate plugins. And these have no restriction, I guess.
It'd be nicer if the rate plugin itself provides the min/max rates optionally. It shouldn't be hard -- just extend the pcm_rate_info_t to contain the new info. A version check would be required to make the backward compatibility, though.
Takashi
At Thu, 28 May 2009 09:28:57 +0200, I wrote:
At Thu, 28 May 2009 08:52:44 +0200, Clemens Ladisch wrote:
Lee Revell wrote:
On Wed, May 27, 2009 at 9:47 PM, Cameron Stone camerons.lists@cse.unsw.edu.au wrote:
I've got a USB microphone application that I want to sample at 256000 8 bit samples per second so I can listen to bats. I know that my device can get close to that rate, but alsa seems to restrict sampling rates to 192kHz.
Is it possible to push the maximum sampling frequency higher? If so, where should I start looking?
For starters, try adding a 256K sample rate to include/sound/pcm.h: and sound/core/pcm_native.c:
This is not necessary; drivers can define whatever sample rate they want. 1,792,000 Hz works just fine with the Bt878 driver.
$ arecord -v -Dplughw:1,0 test.wav -d 1 -r 256 Recording WAVE 'test.wav' : Unsigned 8 bit, Rate 256000 Hz, Mono ... Slave: Hardware PCM card 1 '8-Mic AVR Adaptor' device 0 subdevice 0 Its setup is: ... rate : 256000
This indicates that the record PCM stream _does_ use the correct rate.
$ aplay -r 256 test.wav Playing WAVE 'test.wav' : Unsigned 8 bit, Rate 256000 Hz, Mono Warning: rate is not accurate (requested = 256000Hz, got = 192000Hz)
The automatic sample rate converter never uses a frequency higher than 192 kHz.
This maximum frequency is defined in alsa-lib/include/pcm_plugin.h, but you cannot change it without changing LINEAR_DIV and the algorithm in alsa-lib/src/pcm_pcm_rate_linear.c.
It's anyway better to user other resampler like pph or samplerate plugins. And these have no restriction, I guess.
It'd be nicer if the rate plugin itself provides the min/max rates optionally. It shouldn't be hard -- just extend the pcm_rate_info_t to contain the new info. A version check would be required to make the backward compatibility, though.
OK, here are two patches. One for alsa-lib and one for alsa-plugins. The linear plugin still limits the rate up to 192kHz. But other plugins should work (hopefully).
Takashi
---
Clemens Ladisch wrote:
$ aplay -r 256 test.wav Playing WAVE 'test.wav' : Unsigned 8 bit, Rate 256000 Hz, Mono Warning: rate is not accurate (requested = 256000Hz, got = 192000Hz)
The automatic sample rate converter never uses a frequency higher than 192 kHz.
This maximum frequency is defined in alsa-lib/include/pcm_plugin.h, but you cannot change it without changing LINEAR_DIV and the algorithm in alsa-lib/src/pcm_pcm_rate_linear.c.
Try resampling the .wav file before with sox.
This works. Likewise, playing with "/usr/bin/play" from the sox toolkit also works fine.
It seems that the only limiting going on is during playback, so I'm not terribly worried by this, as we're going to be looking at and processing these samples, not trying to listen to them. Humans can't hear above 20kHz anyway, right?
Thanks to everyone for their help on this.
Cameron.
On Thu, May 28, 2009 at 11:47:34AM +1000, Cameron Stone wrote:
I've got a USB microphone application that I want to sample at 256000 8 bit samples per second so I can listen to bats. I know that my device can get close to that rate, but alsa seems to restrict sampling rates to 192kHz.
Just out of curiosity - which microphone and what kind of codec are you using for such frequencies?
Daniel
Daniel Mack wrote:
On Thu, May 28, 2009 at 11:47:34AM +1000, Cameron Stone wrote:
I've got a USB microphone application that I want to sample at 256000 8 bit samples per second so I can listen to bats. I know that my device can get close to that rate, but alsa seems to restrict sampling rates to 192kHz.
Just out of curiosity - which microphone and what kind of codec are you using for such frequencies?
I don't know which microphone but I can find out if you're interested. I do know that its sensitivity starts at 10kHz, if that helps.
There is no codec used. I'm using Type I (uncompressed PCM) because it's being powered by an AVR running at 16MHz and there's not enough clock cycles to encode the samples.
Cameron.
participants (5)
-
Cameron Stone
-
Clemens Ladisch
-
Daniel Mack
-
Lee Revell
-
Takashi Iwai