mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-22 08:14:04 +02:00
Remove the loop parameter from ma_data_source_read_pcm_frames().
This commit is contained in:
@@ -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->channels = obtainedSpec.channels;
|
||||
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->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,
|
||||
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.
|
||||
*/
|
||||
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. */
|
||||
(void)pDevice;
|
||||
|
||||
@@ -100,7 +100,7 @@ int main(int argc, char** argv)
|
||||
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);
|
||||
if (result != MA_SUCCESS) {
|
||||
@@ -118,7 +118,7 @@ int main(int argc, char** argv)
|
||||
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);
|
||||
if (result != MA_SUCCESS) {
|
||||
|
||||
@@ -46,7 +46,7 @@ void main_loop__em(void* pUserData)
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -108,6 +108,7 @@ int main(int argc, char** argv)
|
||||
&resourceManager,
|
||||
argv[1],
|
||||
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. */
|
||||
&dataSource);
|
||||
if (result != MA_SUCCESS) {
|
||||
@@ -115,6 +116,9 @@ int main(int argc, char** argv)
|
||||
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. */
|
||||
result = ma_device_start(&device);
|
||||
|
||||
@@ -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()
|
||||
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
|
||||
@@ -37,7 +37,7 @@ static ma_result ma_data_source_read_pcm_frames_f32_ex(ma_data_source* pDataSour
|
||||
|
||||
if (dataSourceFormat == ma_format_f32) {
|
||||
/* 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 {
|
||||
/* Slow path. Conversion necessary. */
|
||||
ma_result result;
|
||||
@@ -53,7 +53,7 @@ static ma_result ma_data_source_read_pcm_frames_f32_ex(ma_data_source* pDataSour
|
||||
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);
|
||||
totalFramesRead += framesJustRead;
|
||||
@@ -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_format format;
|
||||
@@ -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 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_format format;
|
||||
@@ -111,7 +111,7 @@ MA_API ma_result ma_data_source_read_pcm_frames_and_mix_f32(ma_data_source* pDat
|
||||
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);
|
||||
totalFramesRead += framesJustRead;
|
||||
@@ -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 (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)
|
||||
&resourceManager,
|
||||
argv[iFile+1],
|
||||
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. */
|
||||
&g_dataSources[iFile]);
|
||||
|
||||
@@ -282,6 +283,9 @@ int main(int argc, char** argv)
|
||||
break;
|
||||
}
|
||||
|
||||
/* Use looping in this example. */
|
||||
ma_data_source_set_looping(&g_dataSources[iFile], MA_TRUE);
|
||||
|
||||
g_dataSourceCount += 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
ma_bool32 isLooping = MA_TRUE;
|
||||
|
||||
ma_decoder* pDecoder = (ma_decoder*)pDevice->pUserData;
|
||||
if (pDecoder == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
A decoder is a data source which means you can seemlessly plug it into the ma_data_source API. We can therefore take advantage
|
||||
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);
|
||||
/* Reading PCM frames will loop based on what we specified when called ma_data_source_set_looping(). */
|
||||
ma_data_source_read_pcm_frames(pDecoder, pOutput, frameCount, NULL);
|
||||
|
||||
(void)pInput;
|
||||
}
|
||||
@@ -45,6 +40,12 @@ int main(int argc, char** argv)
|
||||
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.playback.format = decoder.outputFormat;
|
||||
deviceConfig.playback.channels = decoder.outputChannels;
|
||||
|
||||
Reference in New Issue
Block a user