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
f7ff9ee1
Commit
f7ff9ee1
authored
Jan 19, 2020
by
David Reid
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SRC: Fix linear ma_resampler_get_expected_output_frame_count().
parent
959885a3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
35 deletions
+34
-35
extras/speex_resampler/ma_speex_resampler.h
extras/speex_resampler/ma_speex_resampler.h
+5
-3
research/ma_resampler.h
research/ma_resampler.h
+29
-32
No files found.
extras/speex_resampler/ma_speex_resampler.h
View file @
f7ff9ee1
...
@@ -6,7 +6,9 @@
...
@@ -6,7 +6,9 @@
#define RANDOM_PREFIX ma_speex
#define RANDOM_PREFIX ma_speex
#include "thirdparty/speex_resampler.h"
#include "thirdparty/speex_resampler.h"
int
ma_speex_resampler_get_required_input_frame_count
(
SpeexResamplerState
*
st
,
spx_uint32_t
out_len
,
spx_uint32_t
*
in_len
);
#define spx_uint64_t unsigned long long
int
ma_speex_resampler_get_required_input_frame_count
(
SpeexResamplerState
*
st
,
spx_uint64_t
out_len
,
spx_uint64_t
*
in_len
);
#endif
/* ma_speex_resampler_h */
#endif
/* ma_speex_resampler_h */
...
@@ -26,9 +28,9 @@ int ma_speex_resampler_get_required_input_frame_count(SpeexResamplerState* st, s
...
@@ -26,9 +28,9 @@ int ma_speex_resampler_get_required_input_frame_count(SpeexResamplerState* st, s
#pragma GCC diagnostic pop
#pragma GCC diagnostic pop
#endif
#endif
EXPORT
int
ma_speex_resampler_get_required_input_frame_count
(
SpeexResamplerState
*
st
,
spx_uint
32_t
out_len
,
spx_uint32
_t
*
in_len
)
EXPORT
int
ma_speex_resampler_get_required_input_frame_count
(
SpeexResamplerState
*
st
,
spx_uint
64_t
out_len
,
spx_uint64
_t
*
in_len
)
{
{
spx_uint
32
_t
count
;
spx_uint
64
_t
count
;
if
(
st
==
NULL
||
in_len
==
NULL
)
{
if
(
st
==
NULL
||
in_len
==
NULL
)
{
return
RESAMPLER_ERR_INVALID_ARG
;
return
RESAMPLER_ERR_INVALID_ARG
;
...
...
research/ma_resampler.h
View file @
f7ff9ee1
...
@@ -59,9 +59,6 @@ typedef struct
...
@@ -59,9 +59,6 @@ typedef struct
struct
struct
{
{
void
*
pSpeexResamplerState
;
/* SpeexResamplerState* */
void
*
pSpeexResamplerState
;
/* SpeexResamplerState* */
ma_uint64
runningTimeIn
;
ma_uint64
runningTimeOut
;
double
t
;
/* For tracking the input time so we can query required input and expected output frame counts. */
}
speex
;
}
speex
;
}
state
;
}
state
;
}
ma_resampler
;
}
ma_resampler
;
...
@@ -505,8 +502,7 @@ static ma_result ma_resampler_process__read__speex(ma_resampler* pResampler, con
...
@@ -505,8 +502,7 @@ static ma_result ma_resampler_process__read__speex(ma_resampler* pResampler, con
ma_uint64
frameCountIn
;
ma_uint64
frameCountIn
;
ma_uint64
framesProcessedOut
;
ma_uint64
framesProcessedOut
;
ma_uint64
framesProcessedIn
;
ma_uint64
framesProcessedIn
;
unsigned
int
framesPerIteration
=
32768
;
unsigned
int
framesPerIteration
=
UINT_MAX
;
double
ratioInOut
;
MA_ASSERT
(
pResampler
!=
NULL
);
MA_ASSERT
(
pResampler
!=
NULL
);
MA_ASSERT
(
pFramesOut
!=
NULL
);
MA_ASSERT
(
pFramesOut
!=
NULL
);
...
@@ -524,8 +520,6 @@ static ma_result ma_resampler_process__read__speex(ma_resampler* pResampler, con
...
@@ -524,8 +520,6 @@ static ma_result ma_resampler_process__read__speex(ma_resampler* pResampler, con
framesProcessedOut
=
0
;
framesProcessedOut
=
0
;
framesProcessedIn
=
0
;
framesProcessedIn
=
0
;
ratioInOut
=
(
double
)
pResampler
->
config
.
sampleRateIn
/
(
double
)
pResampler
->
config
.
sampleRateOut
;
while
(
framesProcessedOut
<
frameCountOut
&&
framesProcessedIn
<
frameCountIn
)
{
while
(
framesProcessedOut
<
frameCountOut
&&
framesProcessedIn
<
frameCountIn
)
{
unsigned
int
frameCountInThisIteration
;
unsigned
int
frameCountInThisIteration
;
unsigned
int
frameCountOutThisIteration
;
unsigned
int
frameCountOutThisIteration
;
...
@@ -561,14 +555,8 @@ static ma_result ma_resampler_process__read__speex(ma_resampler* pResampler, con
...
@@ -561,14 +555,8 @@ static ma_result ma_resampler_process__read__speex(ma_resampler* pResampler, con
framesProcessedIn
+=
frameCountInThisIteration
;
framesProcessedIn
+=
frameCountInThisIteration
;
framesProcessedOut
+=
frameCountOutThisIteration
;
framesProcessedOut
+=
frameCountOutThisIteration
;
pResampler
->
state
.
speex
.
t
+=
frameCountOutThisIteration
*
ratioInOut
;
//pResampler->state.speex.t = pResampler->state.speex.t - floor(pResampler->state.speex.t);
}
}
pResampler
->
state
.
speex
.
runningTimeOut
+=
framesProcessedOut
;
pResampler
->
state
.
speex
.
runningTimeIn
+=
framesProcessedIn
;
*
pFrameCountOut
=
framesProcessedOut
;
*
pFrameCountOut
=
framesProcessedOut
;
*
pFrameCountIn
=
framesProcessedIn
;
*
pFrameCountIn
=
framesProcessedIn
;
...
@@ -743,20 +731,11 @@ ma_uint64 ma_resampler_get_required_input_frame_count(ma_resampler* pResampler,
...
@@ -743,20 +731,11 @@ ma_uint64 ma_resampler_get_required_input_frame_count(ma_resampler* pResampler,
case
ma_resample_algorithm_speex
:
case
ma_resample_algorithm_speex
:
{
{
#if defined(MA_HAS_SPEEX_RESAMPLER)
#if defined(MA_HAS_SPEEX_RESAMPLER)
#if 0
ma_uint64
count
;
ma_uint64
count
;
double t = pResampler->state.speex.t;
int
speexErr
=
ma_speex_resampler_get_required_input_frame_count
((
SpeexResamplerState
*
)
pResampler
->
state
.
speex
.
pSpeexResamplerState
,
outputFrameCount
,
&
count
);
if
(
speexErr
!=
RESAMPLER_ERR_SUCCESS
)
{
#if 0
return
0
;
count = (ma_uint64)floor(t + (outputFrameCount * ratioInOut) + 0.00000001);
}
#else
count = (ma_uint64)(floor(t + (outputFrameCount * ratioInOut)) - floor(t));
#endif
return
count
;
#endif
ma_uint32
count
;
ma_speex_resampler_get_required_input_frame_count
((
SpeexResamplerState
*
)
pResampler
->
state
.
speex
.
pSpeexResamplerState
,
(
unsigned
int
)
outputFrameCount
,
&
count
);
return
count
;
return
count
;
#else
#else
...
@@ -790,16 +769,34 @@ ma_uint64 ma_resampler_get_expected_output_frame_count(ma_resampler* pResampler,
...
@@ -790,16 +769,34 @@ ma_uint64 ma_resampler_get_expected_output_frame_count(ma_resampler* pResampler,
{
{
case
ma_resample_algorithm_linear
:
case
ma_resample_algorithm_linear
:
{
{
/*
ma_uint64
outputFrameCount
=
0
;
The linear backend initializes t to -1 at start up to trigger the initial load of the first sample. In this case we will always load at
least two whole input frames before outputting the first output frame.
*/
double
t
=
pResampler
->
state
.
linear
.
t
;
double
t
=
pResampler
->
state
.
linear
.
t
;
if
(
t
<
0
)
{
if
(
t
<
0
)
{
t
=
2
;
t
=
1
;
inputFrameCount
-=
1
;
}
for
(;;)
{
if
(
t
>
1
)
{
if
(
inputFrameCount
>
(
ma_uint64
)
t
)
{
inputFrameCount
-=
(
ma_uint64
)
t
;
t
-=
(
ma_uint64
)
t
;
}
else
{
inputFrameCount
=
0
;
break
;
}
}
t
+=
ratioInOut
;
outputFrameCount
+=
1
;
if
(
inputFrameCount
==
0
)
{
break
;
}
}
}
return
(
ma_uint64
)
ceil
((
t
+
inputFrameCount
)
/
ratioInOut
)
-
1
;
return
outputFrameCount
;
}
}
case
ma_resample_algorithm_speex
:
case
ma_resample_algorithm_speex
:
...
...
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