Re: [AD] audio recording

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On Fri, Jan 6, 2012 at 5:48 PM, Peter Wang <novalazy@xxxxxxxxxx> wrote:
> The Windows waveIn API works by queueing up buffers to be filled with
> waveInAddBuffer[2].  Once a buffer is filled the application gets a
> notification.  If there is no buffer available then data is dropped.
> I suggest that al_update_audio_recorder_buffer is changed to queue up
> additional buffers.
>
I implemented a DirectSound8 recorder and revised things a bit.
Haven't committed it because now the PulseAudio version is outdated.

With DirectSound8 you are exposed directly to a circular buffer of
whatever size you want. But the buffer must be created and destroyed
with Windows API calls so it's impossible for the user to manage them
directly. So in essence, it's the same thing as PulseAudio in that you
have to copy from some large driver buffer into another buffer.

The API now looks like:

ALLEGRO_AUDIO_RECORDER *al_create_audio_recorder (size_t
fragment_count, unsigned int samples, unsigned int freq,
ALLEGRO_AUDIO_DEPTH depth, ALLEGRO_CHANNEL_CONF chan_conf);
bool al_start_audio_recorder (ALLEGRO_AUDIO_RECORDER *r);
void al_stop_audio_recorder (ALLEGRO_AUDIO_RECORDER *r);
bool al_is_audio_recorder_recording (ALLEGRO_AUDIO_RECORDER *r);
void al_destroy_audio_recorder (ALLEGRO_AUDIO_RECORDER *r);

When you create a recorder, you tell it:

a) The number of samples per fragment event. (i.e., the size of a buffer)
b) The number of fragments

So as of now, Allegro manages the memory and sends an event every time
a fragment is ready. (It would be trivial to add an optional void*
parameter to the create or start function to allow the user to take
control of the buffer.)

It's on the programmer to keep ahead, but if the drivers provide at
least a few seconds of buffering, then there shouldn't be any
problems. And if you cannot consistently keep up with real time
recording, then you should just save your processing for after the
recording is finished...

Lastly, is there any (preferred) way to make events in add-ons look
less like they are hacked on as an after thought via the user event?

--
Matthew Leverton




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/