ofSoundPlayer hangs on linux


#1

hi friends,
I need to play some audio files on linux (mp3 at the moment) and I am using ofSoundPlayer. If the load() method is called with streaming == false (the default) everything works but there is a noticeable delay while the song loads, may be a second or more, that causes the program to freeze for a while.

The obvious solution would be to set the streaming option to true, but unfortunately this causes the application to hang badly, it stops responding and has to be killed.

This can be reproduced easily with the soundPlayerExample in examples directory, just adding “, true” to the load call in setup()

Any hint on how to solve this? I’d like to avoid loading the song in a thread if possible (and that would not fix the delay).

OS is Ubuntu 18.04, OF version 0.10.0

thank you!
Davide


#2

This sounds like a bug, can you open an issue on github?


#3

Done. #6154


#4

Hi @davidemania
Are you trying to load large files? theoretically, mp3 streaming should work but there might be some issues with the libraries being used. I will take a look at it.
Are you seeing this same issue if you try to load wav files? or small mp3s?
cheers.


#5

I did not try wav (will do tomorrow) but the size of mp3 files is quite small (one regular song, may be 3 - 4 MB or little more) and the one included with the OF examples is tiny.

I will also try on a different machine to see if the problem is someway related to the hardware.


#6

Besides the problem with streaming it seems to me that ofSoundPlayer::load() is returning true even when the file does not exists, then play() crashes because of a division by zero.


#7

I believe I spotted the problem, in file ofOpenALSoundPlayer.cpp and method

void ofOpenALSoundPlayer::play()

the mutex is locked at the beginning and then again (inside ofThread) when calling startThread in line 908. Inserting a lock.unlock() right before the startThread() call makes it work, or so it seems.

I’m afraid I cannot tell if this is a valid fix for the bug or if it breaks something else, @roymacdonald can you please have a look at it?


#8

that sounds like a good fix, can you send a PR with it?


#9

if arturo says its fine, it must be then :slight_smile:
and @davidemania yes, please PR.
Cheers