Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
miniaudio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
miniaudio
Commits
cc685b88
Commit
cc685b88
authored
Aug 31, 2019
by
David Reid
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Experimental optimzations to mono/stereo channel conversion.
parent
a04780f8
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
286 additions
and
18 deletions
+286
-18
miniaudio.h
miniaudio.h
+58
-6
tests/ma_test_0.c
tests/ma_test_0.c
+216
-0
tests/ma_test_0.vcxproj
tests/ma_test_0.vcxproj
+12
-12
No files found.
miniaudio.h
View file @
cc685b88
...
...
@@ -864,6 +864,8 @@ struct ma_channel_router
ma_channel_router_config config;
ma_bool32 isPassthrough : 1;
ma_bool32 isSimpleShuffle : 1;
ma_bool32 isSimpleMonoExpansion : 1;
ma_bool32 isStereoToMono : 1;
ma_bool32 useSSE2 : 1;
ma_bool32 useAVX2 : 1;
ma_bool32 useAVX512 : 1;
...
...
@@ -29605,6 +29607,31 @@ ma_result ma_channel_router_init(const ma_channel_router_config* pConfig, ma_cha
}
}
/*
We can use a simple case for expanding the mono channel. This will when expanding a mono input into any output so long
as no LFE is present in the output.
*/
if (!pRouter->isPassthrough) {
if (pRouter->config.channelsIn == 1 && pRouter->config.channelMapIn[0] == MA_CHANNEL_MONO) {
/* Optimal case if no LFE is in the output channel map. */
pRouter->isSimpleMonoExpansion = MA_TRUE;
if (ma_channel_map_contains_channel_position(pRouter->config.channelsOut, pRouter->config.channelMapOut, MA_CHANNEL_LFE)) {
pRouter->isSimpleMonoExpansion = MA_FALSE;
}
}
}
/* Another optimized case is stereo to mono. */
if (!pRouter->isPassthrough) {
if (pRouter->config.channelsOut == 1 && pRouter->config.channelMapOut[0] == MA_CHANNEL_MONO && pRouter->config.channelsIn == 2) {
/* Optimal case if no LFE is in the input channel map. */
pRouter->isStereoToMono = MA_TRUE;
if (ma_channel_map_contains_channel_position(pRouter->config.channelsIn, pRouter->config.channelMapIn, MA_CHANNEL_LFE)) {
pRouter->isStereoToMono = MA_FALSE;
}
}
}
/*
Here is where we do a bit of pre-processing to know how each channel should be combined to make up the output. Rules:
...
...
@@ -29824,6 +29851,31 @@ void ma_channel_router__do_routing(ma_channel_router* pRouter, ma_uint64 frameCo
iChannelOut = pRouter->shuffleTable[iChannelIn];
ma_copy_memory_64(ppSamplesOut[iChannelOut], ppSamplesIn[iChannelIn], frameCount * sizeof(float));
}
} else if (pRouter->isSimpleMonoExpansion) {
/* Simple case for expanding from mono. */
if (pRouter->config.channelsOut == 2) {
ma_uint64 iFrame;
for (iFrame = 0; iFrame < frameCount; ++iFrame) {
ppSamplesOut[0][iFrame] = ppSamplesIn[0][iFrame];
ppSamplesOut[1][iFrame] = ppSamplesIn[0][iFrame];
}
} else {
for (iChannelOut = 0; iChannelOut < pRouter->config.channelsOut; ++iChannelOut) {
ma_uint64 iFrame;
for (iFrame = 0; iFrame < frameCount; ++iFrame) {
ppSamplesOut[iChannelOut][iFrame] = ppSamplesIn[0][iFrame];
}
}
}
} else if (pRouter->isStereoToMono) {
/* Simple case for going from stereo to mono. */
ma_assert(pRouter->config.channelsIn == 2);
ma_assert(pRouter->config.channelsOut == 1);
ma_uint64 iFrame;
for (iFrame = 0; iFrame < frameCount; ++iFrame) {
ppSamplesOut[0][iFrame] = (ppSamplesIn[0][iFrame] + ppSamplesIn[1][iFrame]) * 0.5f;
}
} else {
/* This is the more complicated case. Each of the output channels is accumulated with 0 or more input channels. */
tests/ma_test_0.c
View file @
cc685b88
...
...
@@ -1672,6 +1672,222 @@ int do_channel_routing_tests()
}
}
printf
(
"Simple Mono Expansion (Mono -> Stereo)... "
);
{
// The simple mono expansion case will be activated when a mono channel map is converted to anything without an LFE.
ma_channel_router_config
routerConfig
;
ma_zero_object
(
&
routerConfig
);
routerConfig
.
onReadDeinterleaved
=
channel_router_callback__passthrough_test
;
routerConfig
.
pUserData
=
NULL
;
routerConfig
.
mixingMode
=
ma_channel_mix_mode_planar_blend
;
routerConfig
.
channelsIn
=
1
;
routerConfig
.
channelsOut
=
2
;
routerConfig
.
noSSE2
=
MA_TRUE
;
routerConfig
.
noAVX2
=
MA_TRUE
;
routerConfig
.
noAVX512
=
MA_TRUE
;
routerConfig
.
noNEON
=
MA_TRUE
;
ma_get_standard_channel_map
(
ma_standard_channel_map_microsoft
,
routerConfig
.
channelsIn
,
routerConfig
.
channelMapIn
);
ma_get_standard_channel_map
(
ma_standard_channel_map_microsoft
,
routerConfig
.
channelsOut
,
routerConfig
.
channelMapOut
);
ma_channel_router
router
;
ma_result
result
=
ma_channel_router_init
(
&
routerConfig
,
&
router
);
if
(
result
==
MA_SUCCESS
)
{
if
(
router
.
isPassthrough
)
{
printf
(
"Router incorrectly configured as a passthrough.
\n
"
);
hasError
=
MA_TRUE
;
}
if
(
router
.
isSimpleShuffle
)
{
printf
(
"Router incorrectly configured as a simple shuffle.
\n
"
);
hasError
=
MA_TRUE
;
}
if
(
!
router
.
isSimpleMonoExpansion
)
{
printf
(
"Router not configured as simple mono expansion.
\n
"
);
hasError
=
MA_TRUE
;
}
// Expecting the weights to all be equal to 1 for each channel.
for
(
ma_uint32
iChannelIn
=
0
;
iChannelIn
<
routerConfig
.
channelsIn
;
++
iChannelIn
)
{
for
(
ma_uint32
iChannelOut
=
0
;
iChannelOut
<
routerConfig
.
channelsOut
;
++
iChannelOut
)
{
float
expectedWeight
=
1
;
if
(
router
.
config
.
weights
[
iChannelIn
][
iChannelOut
]
!=
expectedWeight
)
{
printf
(
"Failed. Channel weight incorrect: %f
\n
"
,
expectedWeight
);
hasError
=
MA_TRUE
;
}
}
}
}
else
{
printf
(
"Failed to init router.
\n
"
);
hasError
=
MA_TRUE
;
}
// Here is where we check that the shuffle optimization works correctly. What we do is compare the output of the shuffle
// optimization with the non-shuffle output. We don't use a real sound here, but instead use values that makes it easier
// for us to check results. Each channel is given a value equal to it's index, plus 1.
float
testData
[
MA_MAX_CHANNELS
][
100
];
float
*
ppTestData
[
MA_MAX_CHANNELS
];
for
(
ma_uint32
iChannel
=
0
;
iChannel
<
routerConfig
.
channelsIn
;
++
iChannel
)
{
ppTestData
[
iChannel
]
=
testData
[
iChannel
];
for
(
ma_uint32
iFrame
=
0
;
iFrame
<
100
;
++
iFrame
)
{
ppTestData
[
iChannel
][
iFrame
]
=
(
float
)(
iChannel
+
1
);
}
}
routerConfig
.
pUserData
=
ppTestData
;
ma_channel_router_init
(
&
routerConfig
,
&
router
);
float
outputA
[
MA_MAX_CHANNELS
][
100
];
float
outputB
[
MA_MAX_CHANNELS
][
100
];
float
*
ppOutputA
[
MA_MAX_CHANNELS
];
float
*
ppOutputB
[
MA_MAX_CHANNELS
];
for
(
ma_uint32
iChannel
=
0
;
iChannel
<
routerConfig
.
channelsOut
;
++
iChannel
)
{
ppOutputA
[
iChannel
]
=
outputA
[
iChannel
];
ppOutputB
[
iChannel
]
=
outputB
[
iChannel
];
}
// With optimizations.
ma_uint64
framesRead
=
ma_channel_router_read_deinterleaved
(
&
router
,
100
,
(
void
**
)
ppOutputA
,
router
.
config
.
pUserData
);
if
(
framesRead
!=
100
)
{
printf
(
"Returned frame count for optimized incorrect."
);
hasError
=
MA_TRUE
;
}
// Without optimizations.
router
.
isPassthrough
=
MA_FALSE
;
router
.
isSimpleShuffle
=
MA_FALSE
;
framesRead
=
ma_channel_router_read_deinterleaved
(
&
router
,
100
,
(
void
**
)
ppOutputB
,
router
.
config
.
pUserData
);
if
(
framesRead
!=
100
)
{
printf
(
"Returned frame count for unoptimized path incorrect."
);
hasError
=
MA_TRUE
;
}
// Compare.
for
(
ma_uint32
iChannel
=
0
;
iChannel
<
routerConfig
.
channelsOut
;
++
iChannel
)
{
for
(
ma_uint32
iFrame
=
0
;
iFrame
<
100
;
++
iFrame
)
{
if
(
ppOutputA
[
iChannel
][
iFrame
]
!=
ppOutputB
[
iChannel
][
iFrame
])
{
printf
(
"Sample incorrect [%d][%d]
\n
"
,
iChannel
,
iFrame
);
hasError
=
MA_TRUE
;
}
}
}
if
(
!
hasError
)
{
printf
(
"PASSED
\n
"
);
}
}
printf
(
"Simple Stereo to Mono... "
);
{
// The simple mono expansion case will be activated when a mono channel map is converted to anything without an LFE.
ma_channel_router_config
routerConfig
;
ma_zero_object
(
&
routerConfig
);
routerConfig
.
onReadDeinterleaved
=
channel_router_callback__passthrough_test
;
routerConfig
.
pUserData
=
NULL
;
routerConfig
.
mixingMode
=
ma_channel_mix_mode_planar_blend
;
routerConfig
.
channelsIn
=
2
;
routerConfig
.
channelsOut
=
1
;
routerConfig
.
noSSE2
=
MA_TRUE
;
routerConfig
.
noAVX2
=
MA_TRUE
;
routerConfig
.
noAVX512
=
MA_TRUE
;
routerConfig
.
noNEON
=
MA_TRUE
;
ma_get_standard_channel_map
(
ma_standard_channel_map_microsoft
,
routerConfig
.
channelsIn
,
routerConfig
.
channelMapIn
);
ma_get_standard_channel_map
(
ma_standard_channel_map_microsoft
,
routerConfig
.
channelsOut
,
routerConfig
.
channelMapOut
);
ma_channel_router
router
;
ma_result
result
=
ma_channel_router_init
(
&
routerConfig
,
&
router
);
if
(
result
==
MA_SUCCESS
)
{
if
(
router
.
isPassthrough
)
{
printf
(
"Router incorrectly configured as a passthrough.
\n
"
);
hasError
=
MA_TRUE
;
}
if
(
router
.
isSimpleShuffle
)
{
printf
(
"Router incorrectly configured as a simple shuffle.
\n
"
);
hasError
=
MA_TRUE
;
}
if
(
router
.
isSimpleMonoExpansion
)
{
printf
(
"Router incorrectly configured as simple mono expansion.
\n
"
);
hasError
=
MA_TRUE
;
}
if
(
!
router
.
isStereoToMono
)
{
printf
(
"Router not configured as stereo to mono.
\n
"
);
hasError
=
MA_TRUE
;
}
// Expecting the weights to all be equal to 1 for each channel.
for
(
ma_uint32
iChannelIn
=
0
;
iChannelIn
<
routerConfig
.
channelsIn
;
++
iChannelIn
)
{
for
(
ma_uint32
iChannelOut
=
0
;
iChannelOut
<
routerConfig
.
channelsOut
;
++
iChannelOut
)
{
float
expectedWeight
=
0
.
5
f
;
if
(
router
.
config
.
weights
[
iChannelIn
][
iChannelOut
]
!=
expectedWeight
)
{
printf
(
"Failed. Channel weight incorrect: %f
\n
"
,
expectedWeight
);
hasError
=
MA_TRUE
;
}
}
}
}
else
{
printf
(
"Failed to init router.
\n
"
);
hasError
=
MA_TRUE
;
}
// Here is where we check that the shuffle optimization works correctly. What we do is compare the output of the shuffle
// optimization with the non-shuffle output. We don't use a real sound here, but instead use values that makes it easier
// for us to check results. Each channel is given a value equal to it's index, plus 1.
float
testData
[
MA_MAX_CHANNELS
][
100
];
float
*
ppTestData
[
MA_MAX_CHANNELS
];
for
(
ma_uint32
iChannel
=
0
;
iChannel
<
routerConfig
.
channelsIn
;
++
iChannel
)
{
ppTestData
[
iChannel
]
=
testData
[
iChannel
];
for
(
ma_uint32
iFrame
=
0
;
iFrame
<
100
;
++
iFrame
)
{
ppTestData
[
iChannel
][
iFrame
]
=
(
float
)(
iChannel
+
1
);
}
}
routerConfig
.
pUserData
=
ppTestData
;
ma_channel_router_init
(
&
routerConfig
,
&
router
);
float
outputA
[
MA_MAX_CHANNELS
][
100
];
float
outputB
[
MA_MAX_CHANNELS
][
100
];
float
*
ppOutputA
[
MA_MAX_CHANNELS
];
float
*
ppOutputB
[
MA_MAX_CHANNELS
];
for
(
ma_uint32
iChannel
=
0
;
iChannel
<
routerConfig
.
channelsOut
;
++
iChannel
)
{
ppOutputA
[
iChannel
]
=
outputA
[
iChannel
];
ppOutputB
[
iChannel
]
=
outputB
[
iChannel
];
}
// With optimizations.
ma_uint64
framesRead
=
ma_channel_router_read_deinterleaved
(
&
router
,
100
,
(
void
**
)
ppOutputA
,
router
.
config
.
pUserData
);
if
(
framesRead
!=
100
)
{
printf
(
"Returned frame count for optimized incorrect."
);
hasError
=
MA_TRUE
;
}
// Without optimizations.
router
.
isPassthrough
=
MA_FALSE
;
router
.
isSimpleShuffle
=
MA_FALSE
;
framesRead
=
ma_channel_router_read_deinterleaved
(
&
router
,
100
,
(
void
**
)
ppOutputB
,
router
.
config
.
pUserData
);
if
(
framesRead
!=
100
)
{
printf
(
"Returned frame count for unoptimized path incorrect."
);
hasError
=
MA_TRUE
;
}
// Compare.
for
(
ma_uint32
iChannel
=
0
;
iChannel
<
routerConfig
.
channelsOut
;
++
iChannel
)
{
for
(
ma_uint32
iFrame
=
0
;
iFrame
<
100
;
++
iFrame
)
{
if
(
ppOutputA
[
iChannel
][
iFrame
]
!=
ppOutputB
[
iChannel
][
iFrame
])
{
printf
(
"Sample incorrect [%d][%d]
\n
"
,
iChannel
,
iFrame
);
hasError
=
MA_TRUE
;
}
}
}
if
(
!
hasError
)
{
printf
(
"PASSED
\n
"
);
}
}
printf
(
"Simple Conversion (Stereo -> 5.1)... "
);
{
// This tests takes a Stereo to 5.1 conversion using the simple mixing mode. We should expect 0 and 1 (front/left, front/right) to have
...
...
tests/ma_test_0.vcxproj
View file @
cc685b88
...
...
@@ -295,12 +295,12 @@
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
true
</ExcludedFromBuild>
</ClCompile>
<ClCompile
Include=
"..\examples\simple_loopback.c"
>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
fals
e
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
fals
e
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|ARM'"
>
fals
e
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|ARM'"
>
fals
e
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
fals
e
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
fals
e
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
tru
e
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
tru
e
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|ARM'"
>
tru
e
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|ARM'"
>
tru
e
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
tru
e
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
tru
e
</ExcludedFromBuild>
</ClCompile>
<ClCompile
Include=
"..\examples\simple_mixing.c"
>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
true
</ExcludedFromBuild>
...
...
@@ -383,12 +383,12 @@
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
true
</ExcludedFromBuild>
</ClCompile>
<ClCompile
Include=
"ma_test_0.c"
>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
tru
e
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|ARM'"
>
tru
e
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
tru
e
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|ARM'"
>
tru
e
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
tru
e
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
tru
e
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
fals
e
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|ARM'"
>
fals
e
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
fals
e
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|ARM'"
>
fals
e
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
fals
e
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
fals
e
</ExcludedFromBuild>
</ClCompile>
<ClCompile
Include=
"ma_test_0.cpp"
>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
true
</ExcludedFromBuild>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment