View Full Version : Some important things to consider when doing playback

03-04-10, 09:36 AM
There are some important things to consider when doing audio playback.

the most important is to be careful not to free buffers when they are still held in Montecarlo. (for example, for debugging purposes if you remove freeing your audio buffers will the seg fault occur? This would be a good determinate to see if freeing buffers is the problem. Obviously this will cause a memory leak but it is solely for debugging and the free's should be put back.)
if playing from file, it is usually recommended to place the whole file to be played into a buffer and send it down to Montecarlo in a single buffer
if playing audio in buffered chunks (in other words not putting a complete file in one buffer), the applicaiton should have more than one audio buffer to avoid UNDERFLOW events while the driver is passing data/events back and forth.
making sure the lastbuffer flag for the last buffer to be played is set in the TBufferHeader. If the file plays to completion then there is no need to call AUDIO_Stop in this scenario.
waiting until receiving IDLE event before starting another play/record.
trying to stick to using PK_AUDIO_OutputAddBuffer () instead of PK_AUDIO_OutputPassBuffer () and PK_AUDIO_OutputWrite ()
if stopping a play, set a flag to ensure additional buffers are not re-passed into Montecarlo in the callback function/event handler
try to use a even multiple of the buffer size passed back by the function PK_AUDIO_GetBufferSize ()
avoid dynamically creating audio buffers outside of the initialization of the application if possible.