Commit efa95d99 authored by David Reid's avatar David Reid

Remove the loop parameter from ma_data_source_read_pcm_frames().

parent 80cdee58
...@@ -417,7 +417,7 @@ static ma_result ma_device_init_internal__sdl(ma_device_ex* pDeviceEx, const ma_ ...@@ -417,7 +417,7 @@ static ma_result ma_device_init_internal__sdl(ma_device_ex* pDeviceEx, const ma_
pDescriptor->format = ma_format_from_sdl(obtainedSpec.format); pDescriptor->format = ma_format_from_sdl(obtainedSpec.format);
pDescriptor->channels = obtainedSpec.channels; pDescriptor->channels = obtainedSpec.channels;
pDescriptor->sampleRate = (ma_uint32)obtainedSpec.freq; pDescriptor->sampleRate = (ma_uint32)obtainedSpec.freq;
ma_get_standard_channel_map(ma_standard_channel_map_default, pDescriptor->channelMap, ma_countof(pDescriptor->channelMap), pDescriptor->channels); ma_channel_map_init_standard(ma_standard_channel_map_default, pDescriptor->channelMap, ma_countof(pDescriptor->channelMap), pDescriptor->channels);
pDescriptor->periodSizeInFrames = obtainedSpec.samples; pDescriptor->periodSizeInFrames = obtainedSpec.samples;
pDescriptor->periodCount = 1; /* SDL doesn't use the notion of period counts, so just set to 1. */ pDescriptor->periodCount = 1; /* SDL doesn't use the notion of period counts, so just set to 1. */
......
...@@ -65,7 +65,7 @@ static void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ...@@ -65,7 +65,7 @@ static void data_callback(ma_device* pDevice, void* pOutput, const void* pInput,
if you want to loop the chain, like we're doing in this example, you need to set the `loop` if you want to loop the chain, like we're doing in this example, you need to set the `loop`
parameter to false, or else only the current data source will be looped. parameter to false, or else only the current data source will be looped.
*/ */
ma_data_source_read_pcm_frames(&g_pDecoders[0], pOutput, frameCount, NULL, MA_FALSE); ma_data_source_read_pcm_frames(&g_pDecoders[0], pOutput, frameCount, NULL);
/* Unused in this example. */ /* Unused in this example. */
(void)pDevice; (void)pDevice;
......
...@@ -100,7 +100,7 @@ int main(int argc, char** argv) ...@@ -100,7 +100,7 @@ int main(int argc, char** argv)
goto done3; goto done3;
} }
sourceNodeConfig = ma_data_source_node_config_init(&g_sourceData, MA_FALSE); sourceNodeConfig = ma_data_source_node_config_init(&g_sourceData);
result = ma_data_source_node_init(&g_nodeGraph, &sourceNodeConfig, NULL, &g_sourceNode); result = ma_data_source_node_init(&g_nodeGraph, &sourceNodeConfig, NULL, &g_sourceNode);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
...@@ -118,7 +118,7 @@ int main(int argc, char** argv) ...@@ -118,7 +118,7 @@ int main(int argc, char** argv)
goto done2; goto done2;
} }
exciteNodeConfig = ma_data_source_node_config_init(&g_exciteData, MA_FALSE); exciteNodeConfig = ma_data_source_node_config_init(&g_exciteData);
result = ma_data_source_node_init(&g_nodeGraph, &exciteNodeConfig, NULL, &g_exciteNode); result = ma_data_source_node_init(&g_nodeGraph, &exciteNodeConfig, NULL, &g_exciteNode);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
......
...@@ -46,7 +46,7 @@ void main_loop__em(void* pUserData) ...@@ -46,7 +46,7 @@ void main_loop__em(void* pUserData)
void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount) void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount)
{ {
ma_data_source_read_pcm_frames((ma_data_source*)pDevice->pUserData, pOutput, frameCount, NULL, MA_TRUE); ma_data_source_read_pcm_frames((ma_data_source*)pDevice->pUserData, pOutput, frameCount, NULL);
(void)pInput; (void)pInput;
} }
...@@ -108,6 +108,7 @@ int main(int argc, char** argv) ...@@ -108,6 +108,7 @@ int main(int argc, char** argv)
&resourceManager, &resourceManager,
argv[1], argv[1],
MA_RESOURCE_MANAGER_DATA_SOURCE_FLAG_DECODE | MA_RESOURCE_MANAGER_DATA_SOURCE_FLAG_ASYNC | MA_RESOURCE_MANAGER_DATA_SOURCE_FLAG_STREAM, MA_RESOURCE_MANAGER_DATA_SOURCE_FLAG_DECODE | MA_RESOURCE_MANAGER_DATA_SOURCE_FLAG_ASYNC | MA_RESOURCE_MANAGER_DATA_SOURCE_FLAG_STREAM,
0, /* Initial seek point. */
NULL, /* Async notification. */ NULL, /* Async notification. */
&dataSource); &dataSource);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
...@@ -115,6 +116,9 @@ int main(int argc, char** argv) ...@@ -115,6 +116,9 @@ int main(int argc, char** argv)
return -1; return -1;
} }
/* In this example we'll enable looping. */
ma_data_source_set_looping(&dataSource, MA_TRUE);
/* Now that we have a sound we can start the device. */ /* Now that we have a sound we can start the device. */
result = ma_device_start(&device); result = ma_device_start(&device);
......
...@@ -27,7 +27,7 @@ static ma_uint32 g_dataSourceCount; ...@@ -27,7 +27,7 @@ static ma_uint32 g_dataSourceCount;
TODO: Consider putting these public functions in miniaudio.h. Will depend on ma_mix_pcm_frames_f32() TODO: Consider putting these public functions in miniaudio.h. Will depend on ma_mix_pcm_frames_f32()
being merged into miniaudio.h (it's currently in miniaudio_engine.h). being merged into miniaudio.h (it's currently in miniaudio_engine.h).
*/ */
static ma_result ma_data_source_read_pcm_frames_f32_ex(ma_data_source* pDataSource, float* pFramesOut, ma_uint64 frameCount, ma_uint64* pFramesRead, ma_bool32 loop, ma_format dataSourceFormat, ma_uint32 dataSourceChannels) static ma_result ma_data_source_read_pcm_frames_f32_ex(ma_data_source* pDataSource, float* pFramesOut, ma_uint64 frameCount, ma_uint64* pFramesRead, ma_format dataSourceFormat, ma_uint32 dataSourceChannels)
{ {
/* /*
This function is intended to be used when the format and channel count of the data source is This function is intended to be used when the format and channel count of the data source is
...@@ -37,7 +37,7 @@ static ma_result ma_data_source_read_pcm_frames_f32_ex(ma_data_source* pDataSour ...@@ -37,7 +37,7 @@ static ma_result ma_data_source_read_pcm_frames_f32_ex(ma_data_source* pDataSour
if (dataSourceFormat == ma_format_f32) { if (dataSourceFormat == ma_format_f32) {
/* Fast path. No conversion necessary. */ /* Fast path. No conversion necessary. */
return ma_data_source_read_pcm_frames(pDataSource, pFramesOut, frameCount, pFramesRead, loop); return ma_data_source_read_pcm_frames(pDataSource, pFramesOut, frameCount, pFramesRead);
} else { } else {
/* Slow path. Conversion necessary. */ /* Slow path. Conversion necessary. */
ma_result result; ma_result result;
...@@ -53,7 +53,7 @@ static ma_result ma_data_source_read_pcm_frames_f32_ex(ma_data_source* pDataSour ...@@ -53,7 +53,7 @@ static ma_result ma_data_source_read_pcm_frames_f32_ex(ma_data_source* pDataSour
framesToRead = tempCapInFrames; framesToRead = tempCapInFrames;
} }
result = ma_data_source_read_pcm_frames(pDataSource, pFramesOut, framesToRead, &framesJustRead, loop); result = ma_data_source_read_pcm_frames(pDataSource, pFramesOut, framesToRead, &framesJustRead);
ma_convert_pcm_frames_format(ma_offset_pcm_frames_ptr_f32(pFramesOut, totalFramesRead, dataSourceChannels), ma_format_f32, temp, dataSourceFormat, framesJustRead, dataSourceChannels, ma_dither_mode_none); ma_convert_pcm_frames_format(ma_offset_pcm_frames_ptr_f32(pFramesOut, totalFramesRead, dataSourceChannels), ma_format_f32, temp, dataSourceFormat, framesJustRead, dataSourceChannels, ma_dither_mode_none);
totalFramesRead += framesJustRead; totalFramesRead += framesJustRead;
...@@ -67,7 +67,7 @@ static ma_result ma_data_source_read_pcm_frames_f32_ex(ma_data_source* pDataSour ...@@ -67,7 +67,7 @@ static ma_result ma_data_source_read_pcm_frames_f32_ex(ma_data_source* pDataSour
} }
} }
MA_API ma_result ma_data_source_read_pcm_frames_f32(ma_data_source* pDataSource, float* pFramesOut, ma_uint64 frameCount, ma_uint64* pFramesRead, ma_bool32 loop) MA_API ma_result ma_data_source_read_pcm_frames_f32(ma_data_source* pDataSource, float* pFramesOut, ma_uint64 frameCount, ma_uint64* pFramesRead)
{ {
ma_result result; ma_result result;
ma_format format; ma_format format;
...@@ -78,10 +78,10 @@ MA_API ma_result ma_data_source_read_pcm_frames_f32(ma_data_source* pDataSource, ...@@ -78,10 +78,10 @@ MA_API ma_result ma_data_source_read_pcm_frames_f32(ma_data_source* pDataSource,
return result; /* Failed to retrieve the data format of the data source. */ return result; /* Failed to retrieve the data format of the data source. */
} }
return ma_data_source_read_pcm_frames_f32_ex(pDataSource, pFramesOut, frameCount, pFramesRead, loop, format, channels); return ma_data_source_read_pcm_frames_f32_ex(pDataSource, pFramesOut, frameCount, pFramesRead, format, channels);
} }
MA_API ma_result ma_data_source_read_pcm_frames_and_mix_f32(ma_data_source* pDataSource, float* pFramesOut, ma_uint64 frameCount, ma_uint64* pFramesRead, ma_bool32 loop, float volume) MA_API ma_result ma_data_source_read_pcm_frames_and_mix_f32(ma_data_source* pDataSource, float* pFramesOut, ma_uint64 frameCount, ma_uint64* pFramesRead, float volume)
{ {
ma_result result; ma_result result;
ma_format format; ma_format format;
...@@ -111,7 +111,7 @@ MA_API ma_result ma_data_source_read_pcm_frames_and_mix_f32(ma_data_source* pDat ...@@ -111,7 +111,7 @@ MA_API ma_result ma_data_source_read_pcm_frames_and_mix_f32(ma_data_source* pDat
framesToRead = tempCapInFrames; framesToRead = tempCapInFrames;
} }
result = ma_data_source_read_pcm_frames_f32_ex(pDataSource, temp, framesToRead, &framesJustRead, loop, format, channels); result = ma_data_source_read_pcm_frames_f32_ex(pDataSource, temp, framesToRead, &framesJustRead, format, channels);
ma_mix_pcm_frames_f32(ma_offset_pcm_frames_ptr(pFramesOut, totalFramesRead, ma_format_f32, channels), temp, framesJustRead, channels, volume); ma_mix_pcm_frames_f32(ma_offset_pcm_frames_ptr(pFramesOut, totalFramesRead, ma_format_f32, channels), temp, framesJustRead, channels, volume);
totalFramesRead += framesJustRead; totalFramesRead += framesJustRead;
...@@ -149,7 +149,7 @@ void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uin ...@@ -149,7 +149,7 @@ void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uin
/* For each sound, mix as much data as we can. */ /* For each sound, mix as much data as we can. */
for (iDataSource = 0; iDataSource < g_dataSourceCount; iDataSource += 1) { for (iDataSource = 0; iDataSource < g_dataSourceCount; iDataSource += 1) {
ma_data_source_read_pcm_frames_and_mix_f32(&g_dataSources[iDataSource], (float*)pOutput, frameCount, NULL, MA_TRUE, /* volume = */1); ma_data_source_read_pcm_frames_and_mix_f32(&g_dataSources[iDataSource], (float*)pOutput, frameCount, NULL, /* volume = */1);
} }
} }
...@@ -275,6 +275,7 @@ int main(int argc, char** argv) ...@@ -275,6 +275,7 @@ int main(int argc, char** argv)
&resourceManager, &resourceManager,
argv[iFile+1], argv[iFile+1],
MA_RESOURCE_MANAGER_DATA_SOURCE_FLAG_DECODE | MA_RESOURCE_MANAGER_DATA_SOURCE_FLAG_ASYNC /*| MA_RESOURCE_MANAGER_DATA_SOURCE_FLAG_STREAM*/, MA_RESOURCE_MANAGER_DATA_SOURCE_FLAG_DECODE | MA_RESOURCE_MANAGER_DATA_SOURCE_FLAG_ASYNC /*| MA_RESOURCE_MANAGER_DATA_SOURCE_FLAG_STREAM*/,
0, /* Initial seek point. */
NULL, /* Async notification. */ NULL, /* Async notification. */
&g_dataSources[iFile]); &g_dataSources[iFile]);
...@@ -282,6 +283,9 @@ int main(int argc, char** argv) ...@@ -282,6 +283,9 @@ int main(int argc, char** argv)
break; break;
} }
/* Use looping in this example. */
ma_data_source_set_looping(&g_dataSources[iFile], MA_TRUE);
g_dataSourceCount += 1; g_dataSourceCount += 1;
} }
......
...@@ -12,18 +12,13 @@ decoder straight into `ma_data_source_read_pcm_frames()` and it will just work. ...@@ -12,18 +12,13 @@ decoder straight into `ma_data_source_read_pcm_frames()` and it will just work.
void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount) void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount)
{ {
ma_bool32 isLooping = MA_TRUE;
ma_decoder* pDecoder = (ma_decoder*)pDevice->pUserData; ma_decoder* pDecoder = (ma_decoder*)pDevice->pUserData;
if (pDecoder == NULL) { if (pDecoder == NULL) {
return; return;
} }
/* /* Reading PCM frames will loop based on what we specified when called ma_data_source_set_looping(). */
A decoder is a data source which means you can seemlessly plug it into the ma_data_source API. We can therefore take advantage ma_data_source_read_pcm_frames(pDecoder, pOutput, frameCount, NULL);
of the "loop" parameter of ma_data_source_read_pcm_frames() to handle looping for us.
*/
ma_data_source_read_pcm_frames(pDecoder, pOutput, frameCount, NULL, isLooping);
(void)pInput; (void)pInput;
} }
...@@ -45,6 +40,12 @@ int main(int argc, char** argv) ...@@ -45,6 +40,12 @@ int main(int argc, char** argv)
return -2; return -2;
} }
/*
A decoder is a data source which means we just use ma_data_source_set_looping() to set the
looping state. We will read data using ma_data_source_read_pcm_frames() in the data callback.
*/
ma_data_source_set_looping(&decoder, MA_TRUE);
deviceConfig = ma_device_config_init(ma_device_type_playback); deviceConfig = ma_device_config_init(ma_device_type_playback);
deviceConfig.playback.format = decoder.outputFormat; deviceConfig.playback.format = decoder.outputFormat;
deviceConfig.playback.channels = decoder.outputChannels; deviceConfig.playback.channels = decoder.outputChannels;
......
...@@ -115,7 +115,7 @@ int main(int argc, char** argv) ...@@ -115,7 +115,7 @@ int main(int argc, char** argv)
/* Data supply. Attached to input bus 0 of the reverb node. */ /* Data supply. Attached to input bus 0 of the reverb node. */
dataSupplyNodeConfig = ma_data_source_node_config_init(&g_decoder, MA_FALSE); dataSupplyNodeConfig = ma_data_source_node_config_init(&g_decoder);
result = ma_data_source_node_init(&g_nodeGraph, &dataSupplyNodeConfig, NULL, &g_dataSupplyNode); result = ma_data_source_node_init(&g_nodeGraph, &dataSupplyNodeConfig, NULL, &g_dataSupplyNode);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
......
...@@ -84,7 +84,7 @@ int main(int argc, char** argv) ...@@ -84,7 +84,7 @@ int main(int argc, char** argv)
goto done2; goto done2;
} }
dataSupplyNodeConfig = ma_data_source_node_config_init(&g_dataSupply, MA_FALSE); dataSupplyNodeConfig = ma_data_source_node_config_init(&g_dataSupply);
result = ma_data_source_node_init(&g_nodeGraph, &dataSupplyNodeConfig, NULL, &g_dataSupplyNode); result = ma_data_source_node_init(&g_nodeGraph, &dataSupplyNodeConfig, NULL, &g_dataSupplyNode);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
......
...@@ -85,7 +85,7 @@ int main(int argc, char** argv) ...@@ -85,7 +85,7 @@ int main(int argc, char** argv)
goto done2; goto done2;
} }
dataSupplyNodeConfig = ma_data_source_node_config_init(&g_dataSupply, MA_FALSE); dataSupplyNodeConfig = ma_data_source_node_config_init(&g_dataSupply);
result = ma_data_source_node_init(&g_nodeGraph, &dataSupplyNodeConfig, NULL, &g_dataSupplyNode); result = ma_data_source_node_init(&g_nodeGraph, &dataSupplyNodeConfig, NULL, &g_dataSupplyNode);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
......
...@@ -100,7 +100,7 @@ int main(int argc, char** argv) ...@@ -100,7 +100,7 @@ int main(int argc, char** argv)
goto done3; goto done3;
} }
sourceNodeConfig = ma_data_source_node_config_init(&g_sourceData, MA_FALSE); sourceNodeConfig = ma_data_source_node_config_init(&g_sourceData);
result = ma_data_source_node_init(&g_nodeGraph, &sourceNodeConfig, NULL, &g_sourceNode); result = ma_data_source_node_init(&g_nodeGraph, &sourceNodeConfig, NULL, &g_sourceNode);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
...@@ -118,7 +118,7 @@ int main(int argc, char** argv) ...@@ -118,7 +118,7 @@ int main(int argc, char** argv)
goto done2; goto done2;
} }
exciteNodeConfig = ma_data_source_node_config_init(&g_exciteData, MA_FALSE); exciteNodeConfig = ma_data_source_node_config_init(&g_exciteData);
result = ma_data_source_node_init(&g_nodeGraph, &exciteNodeConfig, NULL, &g_exciteNode); result = ma_data_source_node_init(&g_nodeGraph, &exciteNodeConfig, NULL, &g_exciteNode);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment