Commit ac4c1109 authored by David Reid's avatar David Reid

Make channel router API consistent with format converter.

parent 96815f43
...@@ -730,13 +730,13 @@ typedef struct ...@@ -730,13 +730,13 @@ typedef struct
mal_channel channelMapIn[MAL_MAX_CHANNELS]; mal_channel channelMapIn[MAL_MAX_CHANNELS];
mal_channel channelMapOut[MAL_MAX_CHANNELS]; mal_channel channelMapOut[MAL_MAX_CHANNELS];
mal_channel_mix_mode mixingMode; mal_channel_mix_mode mixingMode;
mal_channel_router_read_deinterleaved_proc onReadDeinterleaved;
void* pUserData;
} mal_channel_router_config; } mal_channel_router_config;
struct mal_channel_router struct mal_channel_router
{ {
mal_channel_router_config config; mal_channel_router_config config;
mal_channel_router_read_deinterleaved_proc onReadDeinterleaved;
void* pUserData;
mal_bool32 isPassthrough : 1; mal_bool32 isPassthrough : 1;
mal_bool32 isSimpleShuffle : 1; mal_bool32 isSimpleShuffle : 1;
mal_uint8 shuffleTable[MAL_MAX_CHANNELS]; mal_uint8 shuffleTable[MAL_MAX_CHANNELS];
...@@ -1856,13 +1856,13 @@ mal_uint64 mal_format_converter_read_deinterleaved(mal_format_converter* pConver ...@@ -1856,13 +1856,13 @@ mal_uint64 mal_format_converter_read_deinterleaved(mal_format_converter* pConver
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Initializes a channel router where it is assumed that the input data is non-interleaved. // Initializes a channel router where it is assumed that the input data is non-interleaved.
mal_result mal_channel_router_init_deinterleaved(const mal_channel_router_config* pConfig, mal_channel_router_read_deinterleaved_proc onRead, void* pUserData, mal_channel_router* pRouter); mal_result mal_channel_router_init_deinterleaved(const mal_channel_router_config* pConfig, mal_channel_router* pRouter);
// Reads data from the channel router as deinterleaved channels. // Reads data from the channel router as deinterleaved channels.
mal_uint64 mal_channel_router_read_deinterleaved(mal_channel_router* pRouter, mal_uint64 frameCount, void** ppSamplesOut, void* pUserData); mal_uint64 mal_channel_router_read_deinterleaved(mal_channel_router* pRouter, mal_uint64 frameCount, void** ppSamplesOut, void* pUserData);
// Helper for initializing a channel router config. // Helper for initializing a channel router config.
mal_channel_router_config mal_channel_router_config_init(mal_uint32 channelsIn, const mal_channel channelMapIn[MAL_MAX_CHANNELS], mal_uint32 channelsOut, const mal_channel channelMapOut[MAL_MAX_CHANNELS], mal_channel_mix_mode mixingMode); mal_channel_router_config mal_channel_router_config_init(mal_uint32 channelsIn, const mal_channel channelMapIn[MAL_MAX_CHANNELS], mal_uint32 channelsOut, const mal_channel channelMapOut[MAL_MAX_CHANNELS], mal_channel_mix_mode mixingMode, mal_channel_router_read_deinterleaved_proc onRead, void* pUserData);
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
...@@ -17421,7 +17421,7 @@ mal_bool32 mal_channel_router__is_spatial_channel_position(const mal_channel_rou ...@@ -17421,7 +17421,7 @@ mal_bool32 mal_channel_router__is_spatial_channel_position(const mal_channel_rou
return MAL_TRUE; return MAL_TRUE;
} }
mal_result mal_channel_router_init__common(const mal_channel_router_config* pConfig, void* pUserData, mal_channel_router* pRouter) mal_result mal_channel_router_init_deinterleaved(const mal_channel_router_config* pConfig, mal_channel_router* pRouter)
{ {
if (pRouter == NULL) { if (pRouter == NULL) {
return MAL_INVALID_ARGS; return MAL_INVALID_ARGS;
...@@ -17432,6 +17432,9 @@ mal_result mal_channel_router_init__common(const mal_channel_router_config* pCon ...@@ -17432,6 +17432,9 @@ mal_result mal_channel_router_init__common(const mal_channel_router_config* pCon
if (pConfig == NULL) { if (pConfig == NULL) {
return MAL_INVALID_ARGS; return MAL_INVALID_ARGS;
} }
if (pConfig->onReadDeinterleaved == NULL) {
return MAL_INVALID_ARGS;
}
if (!mal_channel_map_valid(pConfig->channelsIn, pConfig->channelMapIn)) { if (!mal_channel_map_valid(pConfig->channelsIn, pConfig->channelMapIn)) {
return MAL_INVALID_ARGS; // Invalid input channel map. return MAL_INVALID_ARGS; // Invalid input channel map.
...@@ -17441,7 +17444,6 @@ mal_result mal_channel_router_init__common(const mal_channel_router_config* pCon ...@@ -17441,7 +17444,6 @@ mal_result mal_channel_router_init__common(const mal_channel_router_config* pCon
} }
pRouter->config = *pConfig; pRouter->config = *pConfig;
pRouter->pUserData = pUserData;
// If the input and output channels and channel maps are the same we should use a passthrough. // If the input and output channels and channel maps are the same we should use a passthrough.
if (pRouter->config.channelsIn == pRouter->config.channelsOut) { if (pRouter->config.channelsIn == pRouter->config.channelsOut) {
...@@ -17628,23 +17630,6 @@ mal_result mal_channel_router_init__common(const mal_channel_router_config* pCon ...@@ -17628,23 +17630,6 @@ mal_result mal_channel_router_init__common(const mal_channel_router_config* pCon
} }
} }
return MAL_SUCCESS;
}
mal_result mal_channel_router_init_deinterleaved(const mal_channel_router_config* pConfig, mal_channel_router_read_deinterleaved_proc onRead, void* pUserData, mal_channel_router* pRouter)
{
mal_result result = mal_channel_router_init__common(pConfig, pUserData, pRouter);
if (result != MAL_SUCCESS) {
return result;
}
if (onRead == NULL) {
return MAL_INVALID_ARGS;
}
pRouter->onReadDeinterleaved = onRead;
return MAL_SUCCESS; return MAL_SUCCESS;
} }
...@@ -17688,7 +17673,7 @@ mal_uint64 mal_channel_router_read_deinterleaved(mal_channel_router* pRouter, ma ...@@ -17688,7 +17673,7 @@ mal_uint64 mal_channel_router_read_deinterleaved(mal_channel_router* pRouter, ma
// Fast path for a passthrough. // Fast path for a passthrough.
if (pRouter->isPassthrough) { if (pRouter->isPassthrough) {
if (frameCount <= 0xFFFFFFFF) { if (frameCount <= 0xFFFFFFFF) {
return (mal_uint32)pRouter->onReadDeinterleaved(pRouter, (mal_uint32)frameCount, ppSamplesOut, pUserData); return (mal_uint32)pRouter->config.onReadDeinterleaved(pRouter, (mal_uint32)frameCount, ppSamplesOut, pUserData);
} else { } else {
float* ppNextSamplesOut[MAL_MAX_CHANNELS]; float* ppNextSamplesOut[MAL_MAX_CHANNELS];
mal_copy_memory(ppNextSamplesOut, ppSamplesOut, sizeof(float*) * pRouter->config.channelsOut); mal_copy_memory(ppNextSamplesOut, ppSamplesOut, sizeof(float*) * pRouter->config.channelsOut);
...@@ -17701,7 +17686,7 @@ mal_uint64 mal_channel_router_read_deinterleaved(mal_channel_router* pRouter, ma ...@@ -17701,7 +17686,7 @@ mal_uint64 mal_channel_router_read_deinterleaved(mal_channel_router* pRouter, ma
framesToReadRightNow = 0xFFFFFFFF; framesToReadRightNow = 0xFFFFFFFF;
} }
mal_uint32 framesJustRead = (mal_uint32)pRouter->onReadDeinterleaved(pRouter, (mal_uint32)framesToReadRightNow, (void**)ppNextSamplesOut, pUserData); mal_uint32 framesJustRead = (mal_uint32)pRouter->config.onReadDeinterleaved(pRouter, (mal_uint32)framesToReadRightNow, (void**)ppNextSamplesOut, pUserData);
if (framesJustRead == 0) { if (framesJustRead == 0) {
break; break;
} }
...@@ -17736,7 +17721,7 @@ mal_uint64 mal_channel_router_read_deinterleaved(mal_channel_router* pRouter, ma ...@@ -17736,7 +17721,7 @@ mal_uint64 mal_channel_router_read_deinterleaved(mal_channel_router* pRouter, ma
framesToReadRightNow = maxFramesToReadEachIteration; framesToReadRightNow = maxFramesToReadEachIteration;
} }
mal_uint32 framesJustRead = pRouter->onReadDeinterleaved(pRouter, (mal_uint32)framesToReadRightNow, (void**)ppTemp, pUserData); mal_uint32 framesJustRead = pRouter->config.onReadDeinterleaved(pRouter, (mal_uint32)framesToReadRightNow, (void**)ppTemp, pUserData);
if (framesJustRead == 0) { if (framesJustRead == 0) {
break; break;
} }
...@@ -17754,7 +17739,7 @@ mal_uint64 mal_channel_router_read_deinterleaved(mal_channel_router* pRouter, ma ...@@ -17754,7 +17739,7 @@ mal_uint64 mal_channel_router_read_deinterleaved(mal_channel_router* pRouter, ma
return totalFramesRead; return totalFramesRead;
} }
mal_channel_router_config mal_channel_router_config_init(mal_uint32 channelsIn, const mal_channel channelMapIn[MAL_MAX_CHANNELS], mal_uint32 channelsOut, const mal_channel channelMapOut[MAL_MAX_CHANNELS], mal_channel_mix_mode mixingMode) mal_channel_router_config mal_channel_router_config_init(mal_uint32 channelsIn, const mal_channel channelMapIn[MAL_MAX_CHANNELS], mal_uint32 channelsOut, const mal_channel channelMapOut[MAL_MAX_CHANNELS], mal_channel_mix_mode mixingMode, mal_channel_router_read_deinterleaved_proc onRead, void* pUserData)
{ {
mal_channel_router_config config; mal_channel_router_config config;
mal_zero_object(&config); mal_zero_object(&config);
...@@ -17770,6 +17755,8 @@ mal_channel_router_config mal_channel_router_config_init(mal_uint32 channelsIn, ...@@ -17770,6 +17755,8 @@ mal_channel_router_config mal_channel_router_config_init(mal_uint32 channelsIn,
} }
config.mixingMode = mixingMode; config.mixingMode = mixingMode;
config.onReadDeinterleaved = onRead;
config.pUserData = pUserData;
return config; return config;
} }
...@@ -18905,8 +18892,8 @@ mal_result mal_dsp_init(const mal_dsp_config* pConfig, mal_dsp_read_proc onRead, ...@@ -18905,8 +18892,8 @@ mal_result mal_dsp_init(const mal_dsp_config* pConfig, mal_dsp_read_proc onRead,
// Channel conversion // Channel conversion
mal_channel_router_config routerConfig = mal_channel_router_config_init(pConfig->channelsIn, pConfig->channelMapIn, pConfig->channelsOut, pConfig->channelMapOut, pConfig->channelMixMode); mal_channel_router_config routerConfig = mal_channel_router_config_init(pConfig->channelsIn, pConfig->channelMapIn, pConfig->channelsOut, pConfig->channelMapOut, pConfig->channelMixMode, mal_dsp__channel_router_on_read, pDSP);
result = mal_channel_router_init_deinterleaved(&routerConfig, mal_dsp__channel_router_on_read, pDSP, &pDSP->channelRouter); result = mal_channel_router_init_deinterleaved(&routerConfig, &pDSP->channelRouter);
if (result != MAL_SUCCESS) { if (result != MAL_SUCCESS) {
return result; return result;
} }
......
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