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
994c86fc
Commit
994c86fc
authored
Apr 29, 2018
by
David Reid
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add initial support for dithering.
parent
d50c5d22
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
409 additions
and
52 deletions
+409
-52
mini_al.h
mini_al.h
+261
-46
tests/mal_dithering.c
tests/mal_dithering.c
+138
-0
tests/mal_test_0.vcxproj
tests/mal_test_0.vcxproj
+7
-6
tests/mal_test_0.vcxproj.filters
tests/mal_test_0.vcxproj.filters
+3
-0
No files found.
mini_al.h
View file @
994c86fc
This diff is collapsed.
Click to expand it.
tests/mal_dithering.c
0 → 100644
View file @
994c86fc
#define MAL_USE_REFERENCE_CONVERSION_APIS
#define MAL_IMPLEMENTATION
#include "../mini_al.h"
// Two converters are needed here. One for converting f32 samples from the sine wave generator to the input format,
// and another for converting the input format to the output format for device output.
mal_sine_wave
sineWave
;
mal_format_converter
converterIn
;
mal_format_converter
converterOut
;
mal_uint32
on_convert_samples_in
(
mal_format_converter
*
pConverter
,
mal_uint32
frameCount
,
void
*
pFrames
,
void
*
pUserData
)
{
(
void
)
pUserData
;
mal_assert
(
pConverter
->
config
.
formatIn
==
mal_format_f32
);
mal_sine_wave
*
pSineWave
=
(
mal_sine_wave
*
)
pConverter
->
config
.
pUserData
;
mal_assert
(
pSineWave
);
return
(
mal_uint32
)
mal_sine_wave_read
(
pSineWave
,
frameCount
,
pFrames
);
}
mal_uint32
on_convert_samples_out
(
mal_format_converter
*
pConverter
,
mal_uint32
frameCount
,
void
*
pFrames
,
void
*
pUserData
)
{
(
void
)
pUserData
;
mal_format_converter
*
pConverterIn
=
(
mal_format_converter
*
)
pConverter
->
config
.
pUserData
;
mal_assert
(
pConverterIn
!=
NULL
);
return
(
mal_uint32
)
mal_format_converter_read
(
pConverterIn
,
frameCount
,
pFrames
,
NULL
);
}
mal_uint32
on_send_to_device__original
(
mal_device
*
pDevice
,
mal_uint32
frameCount
,
void
*
pFrames
)
{
(
void
)
pDevice
;
mal_assert
(
pDevice
->
format
==
mal_format_f32
);
mal_assert
(
pDevice
->
channels
==
1
);
return
(
mal_uint32
)
mal_sine_wave_read
(
&
sineWave
,
frameCount
,
pFrames
);
}
mal_uint32
on_send_to_device__dithered
(
mal_device
*
pDevice
,
mal_uint32
frameCount
,
void
*
pFrames
)
{
mal_assert
(
pDevice
->
channels
==
1
);
mal_format_converter
*
pConverter
=
(
mal_format_converter
*
)
pDevice
->
pUserData
;
mal_assert
(
pConverter
!=
NULL
);
mal_assert
(
pDevice
->
format
==
pConverter
->
config
.
formatOut
);
return
(
mal_uint32
)
mal_format_converter_read
(
pConverter
,
frameCount
,
pFrames
,
NULL
);
}
int
do_dithering_test
()
{
mal_sine_wave_init
(
0
.
5
,
400
,
48000
,
&
sineWave
);
mal_device_config
config
=
mal_device_config_init_playback
(
mal_format_f32
,
1
,
0
,
on_send_to_device__original
);
mal_device
device
;
mal_result
result
;
// We first play the sound the way it's meant to be played.
result
=
mal_device_init
(
NULL
,
mal_device_type_playback
,
NULL
,
&
config
,
NULL
,
&
device
);
if
(
result
!=
MAL_SUCCESS
)
{
return
-
1
;
}
result
=
mal_device_start
(
&
device
);
if
(
result
!=
MAL_SUCCESS
)
{
return
-
2
;
}
printf
(
"Press Enter to play enable dithering.
\n
"
);
getchar
();
mal_device_uninit
(
&
device
);
// Now we play the sound after it's run through a dithered format converter.
mal_sine_wave_init
(
0
.
5
,
400
,
48000
,
&
sineWave
);
mal_format
srcFormat
=
mal_format_s24
;
mal_format
dstFormat
=
mal_format_s16
;
mal_dither_mode
ditherMode
=
mal_dither_mode_triangle
;
mal_format_converter_config
converterInConfig
;
mal_zero_object
(
&
converterInConfig
);
converterInConfig
.
formatIn
=
mal_format_f32
;
// <-- From the sine wave generator.
converterInConfig
.
formatOut
=
srcFormat
;
converterInConfig
.
channels
=
config
.
channels
;
converterInConfig
.
ditherMode
=
mal_dither_mode_none
;
converterInConfig
.
onRead
=
on_convert_samples_in
;
converterInConfig
.
pUserData
=
&
sineWave
;
result
=
mal_format_converter_init
(
&
converterInConfig
,
&
converterIn
);
if
(
result
!=
MAL_SUCCESS
)
{
return
-
3
;
}
mal_format_converter_config
converterOutConfig
;
mal_zero_object
(
&
converterInConfig
);
converterOutConfig
.
formatIn
=
srcFormat
;
converterOutConfig
.
formatOut
=
dstFormat
;
converterOutConfig
.
channels
=
config
.
channels
;
converterOutConfig
.
ditherMode
=
ditherMode
;
converterOutConfig
.
onRead
=
on_convert_samples_out
;
converterOutConfig
.
pUserData
=
&
converterIn
;
result
=
mal_format_converter_init
(
&
converterOutConfig
,
&
converterOut
);
if
(
result
!=
MAL_SUCCESS
)
{
return
-
3
;
}
config
=
mal_device_config_init_playback
(
converterOutConfig
.
formatOut
,
1
,
0
,
on_send_to_device__dithered
);
result
=
mal_device_init
(
NULL
,
mal_device_type_playback
,
NULL
,
&
config
,
&
converterOut
,
&
device
);
if
(
result
!=
MAL_SUCCESS
)
{
return
-
1
;
}
result
=
mal_device_start
(
&
device
);
if
(
result
!=
MAL_SUCCESS
)
{
return
-
2
;
}
printf
(
"Press Enter to stop.
\n
"
);
getchar
();
return
0
;
}
int
main
(
int
argc
,
char
**
argv
)
{
(
void
)
argc
;
(
void
)
argv
;
do_dithering_test
();
return
0
;
}
\ No newline at end of file
tests/mal_test_0.vcxproj
View file @
994c86fc
...
...
@@ -260,6 +260,7 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile
Include=
"mal_dithering.c"
/>
<ClCompile
Include=
"mal_profiling.c"
>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
true
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
true
</ExcludedFromBuild>
...
...
@@ -269,12 +270,12 @@
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
true
</ExcludedFromBuild>
</ClCompile>
<ClCompile
Include=
"mal_test_0.c"
>
<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>
<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>
</ClCompile>
<ClCompile
Include=
"mal_test_0.cpp"
>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
true
</ExcludedFromBuild>
...
...
tests/mal_test_0.vcxproj.filters
View file @
994c86fc
...
...
@@ -24,6 +24,9 @@
<ClCompile
Include=
"mal_profiling.c"
>
<Filter>
Source Files
</Filter>
</ClCompile>
<ClCompile
Include=
"mal_dithering.c"
>
<Filter>
Source Files
</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude
Include=
"..\mini_al.h"
>
...
...
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