# Sound card sampling rate question

**URL:** <https://www.ruby-forum.com/t/sound-card-sampling-rate-question/230590>\
**Category:** GNU Radio\
**Created:** [June 25, 2014, 10:43am UTC](https://www.ruby-forum.com/t/sound-card-sampling-rate-question/230590 "2014-06-25T10:43:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jason\_sam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7993a0/32.png) [@jason\_sam](https://www.ruby-forum.com/u/jason_sam)\
**Post date:** [June 25, 2014, 10:43am UTC](https://www.ruby-forum.com/t/sound-card-sampling-rate-question/230590/1 "2014-06-25T10:43:40Z")

</div>

I am facing a funny issue: I want to use the sound card for analyzing  
the spectral response  
of a quartz tuning fork at 32768 Hz. I just happened to discover that my  
laptop (Panasonic CF-19)  
has a sound card able to sample a signal at 192 kHz. I checked with  
audacity (Generate -\> Tone at  
32768 Hz and a frequency counter gives the right output frequency while  
an oscilloscope displays  
a clean sine wave).  
Now I want to do the same with gnuradio-companion: Signal Source sampled  
at 192 kHz, output frequency  
at 32768 Hz, directly connected to the audio sink manually set to 192  
kHz. To make a long story short:  
at low frequency (\<20 kHz output) the output is at the right frequency,  
so the sampling rate is  
properly understood. Above 24 kHz I get a clean sine wave output at f-24  
kHz, so it looks like an  
aliasing effect with a sampling frequency of 48 kHz, which is not  
consistent with my first observation.  
And setting an output frequency of 24.xx kHz (xx=300 or 400 Hz)  
generates on the oscilloscope a funny  
low frequency beat signal which must be related to the antialiasing  
filters of the card.

What I cannot understand is where gnuradio fails to initialize the sound  
card the way audacity does.  
Reading the source code, I find in gr-audio/lib/alsa/alsa\_sink.cc the  
following intialization

```
  // sampling rate
  unsigned int orig_sampling_rate = d_sampling_rate;
  if((error = snd_pcm_hw_params_set_rate_near(d_pcm_handle, 

```

d\_hw\_params,  
&d\_sampling\_rate, 0))  
\< 0)  
bail(“failed to set rate near”, error);

```
  if(orig_sampling_rate != d_sampling_rate) {
    fprintf(stderr, "audio_alsa_sink[%s]: unable to support sampling 

```

rate %d\n",  
snd\_pcm\_name(d\_pcm\_handle), orig\_sampling\_rate);  
fprintf(stderr, " card requested %d instead.\n",  
d\_sampling\_rate);  
}

which does not seem to test whether the sampling rate is above or below  
48 kHz (as found in the  
pull down menu of the Audio Sink block of gnuradio-companion), and I get  
no error message when  
running my application.  
Any idea what could be going wrong ?

Thanks, JM

–  
JM Friedt, FEMTO-ST Time & Frequency/SENSeOR, 32 av. observatoire, 25044  
Besancon, France

---

<div class="post-metadata">

**Author:** ![jmfriedt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7feea3/32.png) [@jmfriedt](https://www.ruby-forum.com/u/jmfriedt)\
**Post date:** [June 25, 2014, 10:49am UTC](https://www.ruby-forum.com/t/sound-card-sampling-rate-question/230590/2 "2014-06-25T10:49:02Z")

</div>

Hi JM,

guessing in the dark: You are likely running a modern linux  
distribution. Many of these tend to emulate an Alsa device, which in  
fact is but an Pulseaudio server, which in turn speaks to the real  
device. They set that as the default audio device in the system.  
Have you tried using the explicit device name (aplay -L) of your  
physical device in the audio sink?

Greetings,  
Marcus

---

<div class="post-metadata">

**Author:** ![jmfriedt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7feea3/32.png) [@jmfriedt](https://www.ruby-forum.com/u/jmfriedt)\
**Post date:** [June 25, 2014, 8:04pm UTC](https://www.ruby-forum.com/t/sound-card-sampling-rate-question/230590/3 "2014-06-25T20:04:01Z")

</div>

that was it indeed: selecting out of the aplay -L options the default  
setup  
yields the behaviour I described in my email, while selecting hw as  
shown in  
the output of aplay -L

hw:CARD=PCH,DEV=0  
HDA Intel PCH, ALC269VC Analog  
Direct hardware device without any conversions

allows me to generate a clean 32768 Hz sine wave.

Thanks, JM

> On 25.06.2014 10:40, jmfriedt wrote:
> 
> > And setting an output frequency of 24.xx kHz (xx=300 or 400 Hz) generates on  
> > the oscilloscope a funny
> > 
> > Thanks, JM
> 
> * * *
> 
> Discuss-gnuradio mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [Discuss-gnuradio Info Page](https://lists.gnu.org/mailman/listinfo/discuss-gnuradio)

–  
JM Friedt, FEMTO-ST Time & Frequency/SENSeOR, 32 av. observatoire, 25044  
Besancon, France
