Commit 82b3d108 authored by David Reid's avatar David Reid

Make sure cmap is mono for relevant channel masks.

parent 223727cf
...@@ -819,6 +819,7 @@ struct mal_dsp ...@@ -819,6 +819,7 @@ struct mal_dsp
void* pUserDataForOnRead; void* pUserDataForOnRead;
mal_format_converter formatConverterIn; // For converting data to f32 in preparation for further processing. mal_format_converter formatConverterIn; // For converting data to f32 in preparation for further processing.
mal_format_converter formatConverterOut; // For converting data to the requested output format. Used as the final step in the processing pipeline. mal_format_converter formatConverterOut; // For converting data to the requested output format. Used as the final step in the processing pipeline.
mal_channel_router channelRouter; // For channel conversion.
mal_src src; // For sample rate conversion. mal_src src; // For sample rate conversion.
mal_channel channelMapInPostMix[MAL_MAX_CHANNELS]; // <-- When mixing, new channels may need to be created. This represents the channel map after mixing. mal_channel channelMapInPostMix[MAL_MAX_CHANNELS]; // <-- When mixing, new channels may need to be created. This represents the channel map after mixing.
mal_channel channelShuffleTable[MAL_MAX_CHANNELS]; mal_channel channelShuffleTable[MAL_MAX_CHANNELS];
...@@ -3867,14 +3868,18 @@ void mal_channel_mask_to_channel_map__win32(DWORD dwChannelMask, mal_uint32 chan ...@@ -3867,14 +3868,18 @@ void mal_channel_mask_to_channel_map__win32(DWORD dwChannelMask, mal_uint32 chan
channelMap[0] = MAL_CHANNEL_FRONT_LEFT; channelMap[0] = MAL_CHANNEL_FRONT_LEFT;
channelMap[1] = MAL_CHANNEL_FRONT_RIGHT; channelMap[1] = MAL_CHANNEL_FRONT_RIGHT;
} else { } else {
// Just iterate over each bit. if (channels == 1 && (dwChannelMask & SPEAKER_FRONT_CENTER) != 0) {
mal_uint32 iChannel = 0; channelMap[0] = MAL_CHANNEL_MONO;
for (mal_uint32 iBit = 0; iBit < 32; ++iBit) { } else {
DWORD bitValue = (dwChannelMask & (1UL << iBit)); // Just iterate over each bit.
if (bitValue != 0) { mal_uint32 iChannel = 0;
// The bit is set. for (mal_uint32 iBit = 0; iBit < 32; ++iBit) {
channelMap[iChannel] = mal_channel_id_to_mal__win32(bitValue); DWORD bitValue = (dwChannelMask & (1UL << iBit));
iChannel += 1; if (bitValue != 0) {
// The bit is set.
channelMap[iChannel] = mal_channel_id_to_mal__win32(bitValue);
iChannel += 1;
}
} }
} }
} }
...@@ -11413,6 +11418,7 @@ SLuint32 mal_channel_id_to_opensl(mal_uint8 id) ...@@ -11413,6 +11418,7 @@ SLuint32 mal_channel_id_to_opensl(mal_uint8 id)
{ {
switch (id) switch (id)
{ {
case MAL_CHANNEL_MONO: return SL_SPEAKER_FRONT_CENTER;
case MAL_CHANNEL_FRONT_LEFT: return SL_SPEAKER_FRONT_LEFT; case MAL_CHANNEL_FRONT_LEFT: return SL_SPEAKER_FRONT_LEFT;
case MAL_CHANNEL_FRONT_RIGHT: return SL_SPEAKER_FRONT_RIGHT; case MAL_CHANNEL_FRONT_RIGHT: return SL_SPEAKER_FRONT_RIGHT;
case MAL_CHANNEL_FRONT_CENTER: return SL_SPEAKER_FRONT_CENTER; case MAL_CHANNEL_FRONT_CENTER: return SL_SPEAKER_FRONT_CENTER;
...@@ -11449,18 +11455,24 @@ SLuint32 mal_channel_map_to_channel_mask__opensl(const mal_channel channelMap[MA ...@@ -11449,18 +11455,24 @@ SLuint32 mal_channel_map_to_channel_mask__opensl(const mal_channel channelMap[MA
// Converts an OpenSL-style channel mask to a mini_al channel map. // Converts an OpenSL-style channel mask to a mini_al channel map.
void mal_channel_mask_to_channel_map__opensl(SLuint32 channelMask, mal_uint32 channels, mal_channel channelMap[MAL_MAX_CHANNELS]) void mal_channel_mask_to_channel_map__opensl(SLuint32 channelMask, mal_uint32 channels, mal_channel channelMap[MAL_MAX_CHANNELS])
{ {
if (channels == 2 && channelMask == 0) { if (channels == 1 && channelMask == 0) {
channelMap[0] = MAL_CHANNEL_MONO;
} else if (channels == 2 && channelMask == 0) {
channelMap[0] = MAL_CHANNEL_FRONT_LEFT; channelMap[0] = MAL_CHANNEL_FRONT_LEFT;
channelMap[1] = MAL_CHANNEL_FRONT_RIGHT; channelMap[1] = MAL_CHANNEL_FRONT_RIGHT;
} else { } else {
// Just iterate over each bit. if (channels == 1 && (channelMask & SL_SPEAKER_FRONT_CENTER) != 0) {
mal_uint32 iChannel = 0; channelMap[0] = MAL_CHANNEL_MONO;
for (mal_uint32 iBit = 0; iBit < 32; ++iBit) { } else {
SLuint32 bitValue = (channelMask & (1UL << iBit)); // Just iterate over each bit.
if (bitValue != 0) { mal_uint32 iChannel = 0;
// The bit is set. for (mal_uint32 iBit = 0; iBit < 32; ++iBit) {
channelMap[iChannel] = mal_channel_id_to_mal__opensl(bitValue); SLuint32 bitValue = (channelMask & (1UL << iBit));
iChannel += 1; if (bitValue != 0) {
// The bit is set.
channelMap[iChannel] = mal_channel_id_to_mal__opensl(bitValue);
iChannel += 1;
}
} }
} }
} }
...@@ -17751,7 +17763,7 @@ mal_uint64 mal_channel_router_read_frames_separated(mal_channel_router* pRouter, ...@@ -17751,7 +17763,7 @@ mal_uint64 mal_channel_router_read_frames_separated(mal_channel_router* pRouter,
break; break;
} }
mal_channel_router__do_routing(pRouter, framesJustRead, (float**)ppSamplesOut, ppTemp); // <-- Real work is done here. mal_channel_router__do_routing(pRouter, framesJustRead, (float**)ppSamplesOut, (const float**)ppTemp); // <-- Real work is done here.
totalFramesRead += framesJustRead; totalFramesRead += framesJustRead;
if (totalFramesRead < frameCount) { if (totalFramesRead < frameCount) {
......
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