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

Is it possible to "push" audio to a device, like SDL_QueueAudio? #744

Open
SomeGuyDoinWork opened this issue Sep 23, 2023 · 3 comments
Open

Comments

@SomeGuyDoinWork
Copy link

Trying to get audio data from another library (pl_mpeg) and it has a callback that pushes the audio to a device. Does miniaudio support anything similar?

@mackron
Copy link
Owner

mackron commented Sep 23, 2023

I'm not familiar with SDL_QueueAudio, but I suspect it's just the ability for you post a chunk of audio data to the device and it'll get played when the device get's to it. No, this is not currently supported directly (though of course you can do this yourself with a custom data source). This is something that a lot of people have asked for, and is something I want to support in some form. It's unlikely I'll support it directly with ma_device, such as ma_device_push_data() or whatever, but I might have a queue style data source where you can just push your audio to the data source, and then in the device callback you just read from the data source.

I'll keep this issue open as a feature request, but there is no timeline on when I'll get to this (probably won't be this year).

@foxtacles
Copy link
Sponsor

+1 from me. I also have a use case where I already have a callback that receives audio data, and if there was an API in miniaudio to directly push the the PCM data into a data source, that would be great.

@mackron
Copy link
Owner

mackron commented Jun 9, 2024

It should be feasible to have something like ma_audio_queue which is a type of data source, and then initialize a sound with ma_sound_init_from_data_source():

ma_audio_queue queue;
ma_audio_queue_init(..., &queue);

ma_sound_init_from_data_source(..., &queue, ..., &sound);

And then when new data needs to be pushed, do something like this:

// Push data directly to the underlying data source. The sound will pick it up at playback time.
ma_audio_queue_push(&queue, dataSize, pData);

So long as ma_audio_queue_push() is thread safe with ma_data_source_read_pcm_frames() I can't see why that couldn't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants