0

While working on a morse code play program, I'm finding sounddevice 0.3.7 will work intermittently, one time playing perfectly and then the next just making a bunch of clicking sounds.

I'm playing fairly short segments (a second up to several seconds) using this method:

sd.default.samplrate = 8000.0 # tried other sample rates as well
wav_wave = np.array(self.gain * w, dtype=np.int16)
sd.play(wav_wave, blocking=True)

Where w is an np.array with samples at the correct sample rate and are mostly dits and dahs of a tone. When working, it sounds great, when broken it sounds like a bunch of clicking.

I'm not sure why this is happening.

  • After each `sd.play()`, you should check for under-/overflows with [sd.get_status()](http://python-sounddevice.readthedocs.io/en/latest/#sounddevice.get_status). – Matthias May 09 '17 at 16:31
  • Thanx, sd.get_status() is returning "output underflow", when it doesn't work. Now to find a simple way to fix this issue. – dspmathguru May 09 '17 at 23:28
  • Tried the same code on three different machines. MacBook Pro 15", MacBook Pro 13" and a Ubuntu 16.04 box. It doesn't underflow on the 15" it does sometimes on the 13" and it underflows 90% on the Ubuntu box. The device is an ALSA device on Ubuntu. Maybe this is the issue? – dspmathguru May 10 '17 at 00:17
  • Tested on more computers and sound card arrangements. I found that only on the Ubuntu 16.04 box with a USB based low-end speaker system do I get this issue 90% of the time. (OSX about 5% which is still high). It would be good to not have this issue as I want to be able to eventually use cheap speakers in the field with a raspberry pi and a set of cheap usb based speakers. I also see that other PortAudio based programs work fine with these speaker (fldigi as an example). So if anyone has any ideas or pointers on where to look, thanx in advance. – dspmathguru May 10 '17 at 02:57
  • You should try to use a bigger block size, e.g. `blocksize=1024` or even `blocksize=2048`, but note that this will increase the latency and at a certain point, it may make the timing of your dits and dahs sound irregular. The smallest possible block size depends on the quality of the sound hardware (among other factors), you'll have to find it by trial and error. – Matthias May 10 '17 at 07:46

1 Answers1

0

Well, I found out that upgrading from Ubuntu 16.04 to 17.04 that everything started working. Not that this is the correct solution, but I think it is pointing to some bug in ALSA that my code exposed as easy as it is.

  • I still have the issue, but less often. I find that doing a sd.reset() is important and gets me to even less issues. I'll post when I completely get rid of this issue. – dspmathguru May 19 '17 at 01:22