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
d289e5cf
Commit
d289e5cf
authored
May 09, 2019
by
David Reid
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Sketch out an API idea for the new resampler.
parent
2a0e16c5
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
109 additions
and
11 deletions
+109
-11
research/ma_resampler.h
research/ma_resampler.h
+100
-2
tests/ma_test_0.vcxproj
tests/ma_test_0.vcxproj
+9
-9
No files found.
research/ma_resampler.h
View file @
d289e5cf
...
@@ -136,12 +136,35 @@ The ratio is in/out.
...
@@ -136,12 +136,35 @@ The ratio is in/out.
*/
*/
ma_result
ma_resampler_set_rate_ratio
(
ma_resampler
*
pResampler
,
double
ratio
);
ma_result
ma_resampler_set_rate_ratio
(
ma_resampler
*
pResampler
,
double
ratio
);
/*
Converts the given input data.
On input, [pFrameCountOut] contains the number of output frames to process. On output it contains the number of output frames that
were actually processed, which may be less than the requested amount which will happen if there's not enough input data. You can use
ma_resampler_get_expected_output_frame_count() to know how many output frames will be processed for a given number of input frames.
On input, [pFrameCountIn] contains the number of input frames contained in [ppFramesIn]. On output it contains the number of whole
input frames that were actually processed. You can use ma_resampler_get_required_input_frame_count() to know how many input frames
you should provide for a given number of output frames.
You can pass NULL to [ppFramesOut], in which case a seek will be performed. When [pFrameCountOut] is not NULL, it will seek past that
number of output frames. Otherwise, if [pFrameCountOut] is NULL and [pFrameCountIn] is not NULL, it will seek by the specified number
of input frames. When seeking, [ppFramesIn] is allowed to NULL, in which case the internal timing state will be updated, but not input
will be processed.
It is an error for both [pFrameCountOut] and [pFrameCountIn] to be NULL.
*/
ma_result
ma_resampler_process
(
ma_resampler
*
pResampler
,
ma_uint64
*
pFrameCountOut
,
void
**
ppFramesOut
,
ma_uint64
*
pFrameCountIn
,
void
**
ppFramesIn
);
ma_result
ma_resampler_process_callback
(
ma_resampler
*
pResampler
,
ma_uint64
*
pFrameCountOut
,
void
**
ppFramesOut
,
ma_resampler_read_from_client_proc
onRead
,
void
*
pUserData
);
/*
/*
Reads a number of PCM frames from the resampler.
Reads a number of PCM frames from the resampler.
Passing in NULL for ppFrames is equivalent to calling ma_resampler_seek(pResampler, frameCount, 0).
Passing in NULL for ppFrames is equivalent to calling ma_resampler_seek(pResampler, frameCount, 0).
*/
*/
ma_uint64
ma_resampler_read
(
ma_resampler
*
pResampler
,
ma_uint64
frameCount
,
void
**
ppFrames
);
ma_uint64
ma_resampler_read
(
ma_resampler
*
pResampler
,
ma_uint64
frameCount
,
void
**
ppFrames
);
ma_uint64
ma_resampler_read_callbacks
(
ma_resampler
*
pResampler
,
ma_uint64
frameCount
,
void
**
pFrames
,
ma_resampler_read_from_client_proc
onRead
,
void
*
pUserData
);
/*
/*
Seeks forward by the specified number of PCM frames.
Seeks forward by the specified number of PCM frames.
...
@@ -530,6 +553,8 @@ void ma_resampler_uninit(ma_resampler* pResampler)
...
@@ -530,6 +553,8 @@ void ma_resampler_uninit(ma_resampler* pResampler)
ma_result
ma_resampler_set_rate
(
ma_resampler
*
pResampler
,
ma_uint32
sampleRateIn
,
ma_uint32
sampleRateOut
)
ma_result
ma_resampler_set_rate
(
ma_resampler
*
pResampler
,
ma_uint32
sampleRateIn
,
ma_uint32
sampleRateOut
)
{
{
double
ratio
;
if
(
pResampler
==
NULL
)
{
if
(
pResampler
==
NULL
)
{
return
MA_INVALID_ARGS
;
return
MA_INVALID_ARGS
;
}
}
...
@@ -538,7 +563,7 @@ ma_result ma_resampler_set_rate(ma_resampler* pResampler, ma_uint32 sampleRateIn
...
@@ -538,7 +563,7 @@ ma_result ma_resampler_set_rate(ma_resampler* pResampler, ma_uint32 sampleRateIn
return
MA_INVALID_ARGS
;
return
MA_INVALID_ARGS
;
}
}
double
ratio
=
(
double
)
pResampler
->
config
.
sampleRateIn
/
(
double
)
pResampler
->
config
.
sampleRateOut
;
ratio
=
(
double
)
pResampler
->
config
.
sampleRateIn
/
(
double
)
pResampler
->
config
.
sampleRateOut
;
if
(
ratio
<
MA_RESAMPLER_MIN_RATIO
||
ratio
>
MA_RESAMPLER_MAX_RATIO
)
{
if
(
ratio
<
MA_RESAMPLER_MIN_RATIO
||
ratio
>
MA_RESAMPLER_MAX_RATIO
)
{
return
MA_INVALID_ARGS
;
/* Ratio is too extreme. */
return
MA_INVALID_ARGS
;
/* Ratio is too extreme. */
}
}
...
@@ -565,6 +590,79 @@ ma_result ma_resampler_set_rate_ratio(ma_resampler* pResampler, double ratio)
...
@@ -565,6 +590,79 @@ ma_result ma_resampler_set_rate_ratio(ma_resampler* pResampler, double ratio)
return
MA_SUCCESS
;
return
MA_SUCCESS
;
}
}
ma_result
ma_resampler_process
(
ma_resampler
*
pResampler
,
ma_uint64
*
pFrameCountOut
,
void
**
ppFramesOut
,
ma_uint64
*
pFrameCountIn
,
void
**
ppFramesIn
)
{
if
(
pResampler
==
NULL
)
{
return
MA_INVALID_ARGS
;
}
if
(
ppFramesOut
!=
NULL
)
{
/* Normal processing. */
if
(
pFrameCountOut
==
NULL
)
{
return
MA_INVALID_ARGS
;
/* Don't have any output frames to process. */
}
if
(
pFrameCountIn
==
NULL
||
ppFramesIn
==
NULL
)
{
return
MA_INVALID_ARGS
;
/* Cannot process without any input data. */
}
}
else
{
/* Seeking. */
if
(
pFrameCountOut
!=
NULL
)
{
/* Seeking by output frames. */
}
else
{
/* Seeking by input frames. */
if
(
pFrameCountIn
==
NULL
)
{
return
MA_INVALID_ARGS
;
/* Don't have any input frames to process. */
}
}
}
return
MA_SUCCESS
;
}
ma_result
ma_resampler_process_callback
(
ma_resampler
*
pResampler
,
ma_uint64
*
pFrameCountOut
,
void
**
ppFramesOut
,
ma_resampler_read_from_client_proc
onRead
,
void
*
pUserData
)
{
union
{
float
f32
[
1024
];
ma_int16
s16
[
2048
];
}
buffer
;
ma_uint64
bufferSizeInFrames
;
ma_uint64
outputFramesRemaining
;
if
(
onRead
==
NULL
)
{
return
MA_INVALID_ARGS
;
/* Does not make sense to call this API without a callback... */
}
/* This API always requires an output frame count. */
if
(
pFrameCountOut
==
NULL
)
{
return
MA_INVALID_ARGS
;
}
bufferSizeInFrames
=
sizeof
(
buffer
)
/
ma_get_bytes_per_frame
(
pResampler
->
config
.
format
,
pResampler
->
config
.
channels
);
outputFramesRemaining
=
*
pFrameCountOut
;
/* Keep reading until every output frame has been processed. */
for
(;;)
{
ma_uint64
inputFrameCount
=
ma_resampler_get_required_input_frame_count
(
pResampler
,
outputFramesRemaining
);
if
(
inputFrameCount
>
bufferSizeInFrames
)
{
inputFrameCount
=
bufferSizeInFrames
;
}
}
return
MA_SUCCESS
;
}
ma_uint64
ma_resampler_read
(
ma_resampler
*
pResampler
,
ma_uint64
frameCount
,
void
**
ppFrames
)
ma_uint64
ma_resampler_read
(
ma_resampler
*
pResampler
,
ma_uint64
frameCount
,
void
**
ppFrames
)
{
{
ma_result
result
;
ma_result
result
;
...
...
tests/ma_test_0.vcxproj
View file @
d289e5cf
...
@@ -295,14 +295,6 @@
...
@@ -295,14 +295,6 @@
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
true
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
true
</ExcludedFromBuild>
</ClCompile>
</ClCompile>
<ClCompile
Include=
"..\examples\simple_mixing.c"
>
<ClCompile
Include=
"..\examples\simple_mixing.c"
>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
false
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
false
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|ARM'"
>
false
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|ARM'"
>
false
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
false
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
false
</ExcludedFromBuild>
</ClCompile>
<ClCompile
Include=
"..\examples\simple_playback.c"
>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
true
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
true
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
true
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
true
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|ARM'"
>
true
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|ARM'"
>
true
</ExcludedFromBuild>
...
@@ -310,7 +302,7 @@
...
@@ -310,7 +302,7 @@
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
true
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
true
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
true
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
true
</ExcludedFromBuild>
</ClCompile>
</ClCompile>
<ClCompile
Include=
"..\
research\tests\ma_resampler_test_0
.c"
>
<ClCompile
Include=
"..\
examples\simple_playback
.c"
>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
true
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
true
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
true
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
true
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|ARM'"
>
true
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|ARM'"
>
true
</ExcludedFromBuild>
...
@@ -318,6 +310,14 @@
...
@@ -318,6 +310,14 @@
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
true
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
true
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
true
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
true
</ExcludedFromBuild>
</ClCompile>
</ClCompile>
<ClCompile
Include=
"..\research\tests\ma_resampler_test_0.c"
>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
false
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
false
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|ARM'"
>
false
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|ARM'"
>
false
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
false
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
false
</ExcludedFromBuild>
</ClCompile>
<ClCompile
Include=
"ma_dithering.c"
>
<ClCompile
Include=
"ma_dithering.c"
>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
true
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
true
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
true
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|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