Skip to content
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

Merged
merged 3 commits into from Sep 28, 2016
Merged

Conversation

mic-
Copy link
Contributor

@mic- mic- commented Sep 26, 2016

No description provided.

Copy link
Owner

@DragonMinded DragonMinded left a 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)
Copy link
Owner

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?

Copy link
Contributor Author

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)
Copy link
Owner

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.

Copy link
Contributor Author

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).

Copy link
Owner

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;
Copy link
Owner

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.

@DragonMinded DragonMinded merged commit a144470 into DragonMinded:master Sep 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants