Sync AudioOutBuffer comments with wiki. Updated audoutPlayBuffer() comments. Moved the waiting/post-append code from audoutPlayBuffer() into new func audoutWaitPlayFinish(). Removed '&' from code setting audoutAppendAudioOutBuffer() raw->tag.

This commit is contained in:
yellows8 2018-02-28 19:37:17 -05:00
parent 517c76c05c
commit 6dd76f6288
2 changed files with 32 additions and 18 deletions

View File

@ -28,11 +28,11 @@ typedef struct AudioOutBuffer AudioOutBuffer;
struct AudioOutBuffer
{
AudioOutBuffer* next; ///< Next buffer.
AudioOutBuffer* next; ///< Next buffer. (Unused)
void* buffer; ///< Sample buffer (aligned to 0x1000 bytes).
u64 buffer_size; ///< Sample buffer size.
u64 data_size; ///< Size of data inside the buffer.
u64 data_offset; ///< Offset of data inside the buffer.
u64 data_offset; ///< Offset of data inside the buffer. (Unused?)
};
Result audoutInitialize(void);
@ -48,12 +48,20 @@ Result audoutGetReleasedAudioOutBuffer(AudioOutBuffer *Buffer, u32 *ReleasedBuff
Result audoutContainsAudioOutBuffer(AudioOutBuffer *Buffer, bool *ContainsBuffer);
/**
* @brief Submits an audio sample data buffer for playing.
* @brief Submits an audio sample data buffer for playing and waits for it to finish playing.
* @brief Uses \ref audoutAppendAudioOutBuffer and \ref audoutWaitPlayFinish internally.
* @param source AudioOutBuffer containing the source sample data to be played.
* @param released AudioOutBuffer to receive the last played buffer.
*/
Result audoutPlayBuffer(AudioOutBuffer *source, AudioOutBuffer *released);
/**
* @brief Waits for audio playback to finish.
* @param released AudioOutBuffer to receive the last played buffer.
* @param timeout Timeout value, use U64_MAX to wait until all finished.
*/
Result audoutWaitPlayFinish(AudioOutBuffer *released, u64 timeout);
/// These return the state associated with the currently active audio output device.
u32 audoutGetSampleRate(void); ///< Supported sample rate (48000Hz).
u32 audoutGetChannelCount(void); ///< Supported channel count (2 channels).

View File

@ -82,14 +82,9 @@ AudioOutState audoutGetDeviceState(void) {
return g_deviceState;
}
Result audoutPlayBuffer(AudioOutBuffer *source, AudioOutBuffer *released) {
// Try to push the supplied buffer to the audio output device
Result do_append = audoutAppendAudioOutBuffer(source);
if (R_SUCCEEDED(do_append))
{
Result audoutWaitPlayFinish(AudioOutBuffer *released, u64 timeout) {
// Wait on the buffer event handle
Result do_wait = svcWaitSynchronizationSingle(g_audoutBufferEventHandle, U64_MAX);
Result do_wait = svcWaitSynchronizationSingle(g_audoutBufferEventHandle, timeout);
if (R_SUCCEEDED(do_wait))
{
@ -102,6 +97,17 @@ Result audoutPlayBuffer(AudioOutBuffer *source, AudioOutBuffer *released) {
while (R_SUCCEEDED(do_release) && (released_count > 0))
do_release = audoutGetReleasedAudioOutBuffer(released, &released_count);
}
return do_wait;
}
Result audoutPlayBuffer(AudioOutBuffer *source, AudioOutBuffer *released) {
// Try to push the supplied buffer to the audio output device
Result do_append = audoutAppendAudioOutBuffer(source);
if (R_SUCCEEDED(do_append))
{
audoutWaitPlayFinish(released, U64_MAX);
}
return do_append;
@ -319,7 +325,7 @@ Result audoutAppendAudioOutBuffer(AudioOutBuffer *Buffer) {
raw->magic = SFCI_MAGIC;
raw->cmd_id = 3;
raw->tag = (u64)&Buffer;
raw->tag = (u64)Buffer;
Result rc = serviceIpcDispatch(&g_audoutIAudioOut);