Get current position of audio engine
huantianad opened this issue · 4 comments
Hello, I'm looking to use this library for a simple terminal based rhythm game. Not looking for too much functionality, so this library seems great. However, one thing that would be very helpful is a way to query the current position of the audio engine as it plays a specific sound, potentially based off of the current number of samples played, something similar to Unity's AudioSettings.dspTime
. This would allow the game to be synced to a more accurate audio position.
Hi,
Do you need to query the global mixer sample count/time or you also would like to get the sample count/time for each sound?
mixerTime :: IO Double
soundTime :: Sound -> IO Double
or the same with sample position:
mixerSamplePosition :: IO Int
soundSamplePosition :: Sound -> IO Int
IMO a more generic approach would be to add info query functions like:
mixerInfo :: IO MixerInfo
sampleInfo :: Sample -> IO SampleInfo
soundInfo :: Sound -> IO SoundInfo
and include the necessary data in these Info
types, like: time, sample rate, volume, sample count, channel count, etc.
What do you think?
I think the last option is probably the best and most flexible, would also help with #15 as well.
For my use case, I think the most useful stat is the current position of a specific Sound
(which would be the currently playing music; the position would be used to sync to the music), but having the other info exposed is probably useful for others.
I don't need the raw sample count itself, but I mention it as it seems to be what other tools use to calculate audio position in seconds.
Hey just wanted to ask how much work this would be for you and how long it would take. I would like to use a feature like this, but might work with a separate timer for now.
I know this project isn't your main priority or anything, so I don't want you to feel like I'm pressuring you or anything. Perhaps I could take a try at doing something myself, though I'm very unfamiliar with this library's internals haha
Thanks again for working on this great library!
Hi, I'm quite busy at work currently. Probably I can work on this during the Christmas holidays. But IMO if you have some C experience then you could start developing this feature also. It's not that complicated and I can give support by answering your questions or giving feedback.
The proteaaudio and proteaaudio-sdl libraries share as much code as possible and the code structure is the following:
- shared code between proteaaudio and proteaaudio-sdl:
minimp3.h
,minimp3_ex.h
- mp3 decoderstb_vorbis.c
- ogg vorbis decoderproAudio.h
,proAudio.cpp
- wav reader, AudioSample classchs/Binding.chs
- Haskell API
it is the only Haskell module in the source code
it uses thecbits/proteaaudio_binding.h
C APIcbits/proteaaudio_binding.cpp
- C implementation for the Haskell API
proAudioRt.h
,proAudioRt.cpp
- proteaaudio backend which usesRtAudio.h
andRtAudio.cpp
proAudioSdl.h
,proAudioSdl.cpp
- proteaaudio-sdl backend which uses the installed SDL library
IMO the files that needs to be changed are:
chs/Binding.chs
cbits/proteaaudio_binding.cpp
proAudioRt.cpp
proAudioSdl.cpp