1

I'm trying to get started with programming a small synthesizer (wave generator) on my raspberry pi 3a+. To start off, I tried to use python's sounddevice module to play a stream from a numpy - array. However, my raspberry pi doesn't output any sound, which is weird, since the exact same code works perfectly fine on my laptop and produces a nice, steady sine - wave tone, like you'd expect.

The code I used is basically just a copied example code from the sounddevice documentation, it can be found here: https://python-sounddevice.readthedocs.io/en/0.4.1/examples.html#play-a-sine-signal

I think downloaded all required modules on my pi (portAudio etc.), as I have downloaded the same ones on my laptop, where the code works.

Could it be that sounddevice just can't handle some part of the pi's hardware, or that I messed up somewhere in the ALSA - settings (although I checked several times)?

Interestingly, the pi plays sound perfectly fine with the simpleaudio - module, which is sadly not versatile enough for what I'm planning to do, which is why I need sounddevice or something similar. I'd be very thankful if someone could help me here.

  • I'm having the same problem, so far ive gathered its a problem with ALSA and samplerate. Ill update you if I find anthing else – Tris Oct 25 '20 at 14:54
  • @Tris Thanks for the answer, at least I'm not alone with this problem. May I ask which Pi you are using? It would be interesting to know if this issue is specific to certain models. Hopefully you are more successful than me in figuring out the reasons for this problem (you might have a good chance at that, I'm neither very good at coding nor do I have experience with the Pi's audio output), but if I find some solution, I'll also post it here, of course. – Dönerspiess Oct 26 '20 at 14:46

1 Answers1

0

You need to set the samplerate in /etc/asounc.config to whatever samplerate you plan to use.

pcm.!default {
    rate 48000
    type hw
    card 0
    device 0
}

ctl.!default {
        type hw
        card 0
}
  • Do this by adding "rate" followed by the samplerate you plan to use

Your applications will need to use this samplerate to work corretly so ensure that it is set properly in you code.

Hopefully this solves your issue

Tris
  • 196
  • 1
  • 1
  • 6
  • Thanks, this worked. It was a little bit complicated, because asound.config doesn't exist on my pi, so I had to figure out that .asoundrc does more or less the same, but has a different structure, so I had to test where to put the code you provided (I'm not very intuitive with such things) but in the end, it all worked out somehow. – Dönerspiess Nov 29 '20 at 17:49