New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for callback-driven audio #27
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, would love to see a link to what you're working on!
@@ -147,7 +152,7 @@ static void audio_callback() | |||
{ | |||
/* check if next buffer is full */ | |||
int next = (now_playing + 1) % _num_buf; | |||
if (!(buf_full & (1<<next))) | |||
if ((!(buf_full & (1<<next))) && !_fill_buffer_callback) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point, you verify that we don't have a callback, but what if somebody calls pause() without one? It looks like in that case the code below will set a pause callback anyway. Is that intended behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True. I should probably add && _fill_buffer_callback
to the first if
in audio_pause
.
*/ | ||
void audio_init(const int frequency, int numbuffers) | ||
void audio_init(const int frequency, int numbuffers, audio_fill_buffer_callback fill_buffer_callback) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any updates to the examples. I forget, did any of the examples show off audio? If so, they won't compile anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's the dfsdemo. So I guess I should update its call to audio_init
. Or possibly create a new function called audio_set_buffer_callback
or something like that. This is just the way I implemented it back when I originally made these changes, which was a while ago (when I had begun working on this: https://www.youtube.com/watch?v=EqrgPTFNXAA).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooh nice, I like!
Possibly setting the fill buffer in another function instead of the init would be backwards compatible and also less confusing for somebody trying to use, so I like that idea.
separate function rather than with audio_init. Only support pausing when a fill_buffer_callback has been set.
void audio_set_buffer_callback(audio_fill_buffer_callback fill_buffer_callback) | ||
{ | ||
disable_interrupts(); | ||
_fill_buffer_callback = _orig_fill_buffer_callback = fill_buffer_callback; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hate to nitpick, but setting this when paused would mean we would unpause, right? Probably low-pri but still nice to be correct.
if playback is paused.
No description provided.