RustAudio / rodio

Rust audio playback library
Apache License 2.0
1.75k stars 227 forks source link

Output fails on raspberry pi #323

Open HalfVoxel opened 4 years ago

HalfVoxel commented 4 years ago

Hi

I'm been trying to get this running on a raspberry pi 1. It has worked reasonably well except for a tiiny patch I had to make to cpal (it assumed a 64-bit clong type, this seems to have already been fixed in the cpal master branch though) and that compilation takes literally 4 hours. However when I try to play a sound I encounter the error

thread '<unnamed>' panicked at 'build_output_stream failed with all supported formats: BackendSpecific { err: BackendSpecificError { description: "ALSA function \'snd_pcm_start\' failed with error \'EPIPE: Broken pipe\'" } }', /home/pi/.cargo/git/checkouts/rodio-6458f6e95b054746/3bc614f/src/stream.rs:184:22

Do you have any idea what this can mean and what I can do to solve it?

Playing sounds using e.g. the test-speaker command works fine and the program I'm using works fine on another computer.

deg0nz commented 3 years ago

I have the exact same problem. I wasn't able to find a fix, but a workaround for now: Migrate back to rodio version 0.11.0. This version is working on a Raspberry Pi 1.

Additionally: For the audio playback to work correctly, you need to compile to release. In debug, the Raspi is too slow and you get ALSA underrun errors as in #290

But since it definitely works with 0.11.0, this seems to actually be a problem with code changes in 0.12.0 (or changes in cpal).

pimdh commented 3 years ago

Thanks! On the Raspberry Pi Zero W, with rodio 0.12 I had the issue that the sound was playing too fast. Downgrading to 0.11 solved the issue.

HalfVoxel commented 3 years ago

Downgrading to 0.11 solved it for me too!

est31 commented 3 years ago

Can one of you folks try to do a git bisect? That'd help with nailing down the issue.

HalfVoxel commented 3 years ago

That would probably take days on my raspberry pi... It takes a couple of hours to compile things if many dependencies have changed. It's not a fast machine :p

est31 commented 3 years ago

Good point. It would already be helpful if it's broken as of 286d63d6b375c1afa475db28a1a0324c705a2fc3. Would help nail down the issue whether it's a cpal bug or not.

deg0nz commented 3 years ago

My code part for the pi is relatively small, so it compiles in about 15 minutes. I can try a build before that commit and with that commit. Maybe I find time tonight and give you feedback.

Another thing: Are we sure, this is Raspi 1 only? I could try a build on a newer Pi as well. The CPU architecture is different on newer ones.

joonazan commented 3 years ago

I am using Raspi 3B+, rodio 0.13 and getting an error occurred on output stream: A backend-specific error has occurred: ALSA function 'snd_pcm_prepare' failed with an error EBUSY: Device or resource busy with very high frequency. Sound plays just fine regardless.

RandomExplosion commented 3 years ago

I'm getting this output as well on Raspi 3 B+.

RandomExplosion commented 3 years ago

I am using Raspi 3B+, rodio 0.13 and getting an error occurred on output stream: A backend-specific error has occurred: ALSA function 'snd_pcm_prepare' failed with an error EBUSY: Device or resource busy with very high frequency. Sound plays just fine regardless. @joonazan try the solution from @deg0nz worked for me :)

joonazan commented 3 years ago

@RandomExplosion Thanks for pointing this out! I had tried downgrading cpal but not rodio.

I switched to rodio 0.11 and my audio quality improved dramatically. The API was nicer as well. Time to fork rodio?

I also had the problem that the audio stopped after a while. I don't have enough evidence yet to state that that is fixed but I have high hopes.

joonazan commented 3 years ago

After running seven tracks on repeat simultaneously for about three hours, my system started a short cycle of less than one second silence, then less than one second sound. Shortly after that, audio output completely stopped and I wasn't able to ssh into the system.

I suspect that this is some kind of memory leak. I will try to investigate it next week. It may be due to using ALSA incorrectly, though. See for example moc.daper.net/node/692#comment-5682

EDIT: What I suspected to be a memory leak was probably just high memory use due to rodio's repeat buffering the whole sound into RAM.

leosh64 commented 3 years ago

I'm getting the same error when trying to run https://github.com/DasEtwas/enginesound on a Raspberry Pi 4B:

thread '<unnamed>' panicked at 'Failed to build audio output stream: BackendSpecific { err: BackendSpecificError { description: "ALSA function \'snd_pcm_start\' failed with error \'EPIPE: Broken pipe\'" } }', src/audio.rs:73:14

Since the enginesound project doesn't use rodio but directly cpal, this issue could be caused by the cpal library. Do you have any ideas how to debug this further?

EDIT: There is an open issue about this at cpal: https://github.com/RustAudio/cpal/issues/460