openframeworks / openFrameworks

openFrameworks is a community-developed cross platform toolkit for creative coding in C++.
http://openframeworks.cc
Other
9.9k stars 2.55k forks source link

Android SoundPlayer: setSpeed(), getPosition() #1714

Open thiagohersan opened 11 years ago

thiagohersan commented 11 years ago

This is what I found while running the androidSoundPlayerExample: for each of the 3 audio players, at any given time, either setSpeed( ) works, or getPosition( ) works, but never both.

I think it has to do with the stream variable and multiplay functionality. And whether the sound is beng played with the MediaPlayer object, or the SoundPool.

Looking at getPosition() you can see that if stream is not true, and we're using a SoundPool, it always returns zero for the position.

And in setSpeed(...), if stream is true, and we're using a MediaPlayer, it doesn't really use the speed variable anywhere.

Is this some limitation of Android? MediaPlayer doesn't seem to have a setSpeed method, and SoundPool doesn't have a getPosition...

arturoc commented 11 years ago

yes android sound is super limited, there's things that are ridiculous like you can only setSpeed to x2 max or .5 min and depending if you are using soundpool or mediaplayer you have some other limitations like you can't get the position or set the speed.

there's a c api using openSL it's only supported from 2.3 but i think it could be ok to move to that now since most phones have newer operating systems. but haven't really tested yet and don't know if it would be as limited as the current one anyway. for some devices you can use openMAX which should have more options but i think it's only really a few devices that support it

thiagohersan commented 11 years ago

yeah...

and thinking about it, when you have many samples being played at the same time in one SoundPool, at different speeds, what would getPosition mean? Position of the last sample triggered? position of the sample that will finish last? It's not clear.

But getIsPlaying() could work (right now it also doesn't work with SoundPool, it always returns true).

Would keeping track of duration and time ourselves, and making getIsPlaying() work a little better for SoundPool be interesting? Or is it too much of a hack?

arturoc commented 11 years ago

yes in the desktop gePosition on multiplay returns the position of the last one i think. I don't think trying to implement getIsPlaying is a good idea, it'll be really hacky and not very reliable for long samples. the basicsoundplayer we are implementing here: https://github.com/openframeworks/openFrameworks/pull/1626 solves all this but it's still too slow for mobile platforms. i think the best solution would be to try openSL.