![]() |
python alsa: How to play smoothly?
Hi!
I'm working on a personal research project. What I need to do is to be able to play waves at will. I tried this morning to use alsa to have the output straight into the speakers but I just can't get to play waves smoothly without sound breakage. I tried with different PCM modes but none worked. I also tried with PCM_NORMAL using a separate thread to not block my wave calculations, but that didn't work either. So, to keep it simple, take a look at this two versions of the same file: Simple: http://bazaar.launchpad.net/~eantora.../WavePlayer.py With threads: http://bazaar.launchpad.net/~eantora.../WavePlayer.py You will need the Wave.py from the project too. http://bazaar.launchpad.net/~eantora...46/bin/Wave.py The way to call it is very simple: ./WavePlayer.py 440 That should play a simple A4 sine wave on both channels. Thanks for any help you could provide. |
I got only silence from your program. :confused:
Just looking at the code it seems that you call math.sin a whole lot which is unnecessary: just calculate one period and then repeat it. The following works for me without any breakage, though I use 8-bit samples because I didn't feel like bit-bashing. Code:
#!/usr/bin/env python |
| All times are GMT -5. The time now is 04:29 PM. |