extern
porcupine
demo
c
dr_libs
tests
external
miniaudio
extras
speex_resampler
porcupine/demo/c/dr_libs/tests/external/miniaudio/extras/speex_resampler/ma_speex_resampler.h
Go to the documentation of this file.
1
2
#ifndef ma_speex_resampler_h
3
#define ma_speex_resampler_h
4
5
#define OUTSIDE_SPEEX
6
#define RANDOM_PREFIX ma_speex
7
#include "thirdparty/speex_resampler.h"
8
9
#ifdef _MSC_VER
10
#if defined(__clang__)
11
#pragma GCC diagnostic push
12
#pragma GCC diagnostic ignored "-Wlanguage-extension-token"
13
#pragma GCC diagnostic ignored "-Wlong-long"
14
#pragma GCC diagnostic ignored "-Wc++11-long-long"
15
#endif
16
#define spx_uint64_t unsigned __int64
17
#if defined(__clang__)
18
#pragma GCC diagnostic pop
19
#endif
20
#else
21
#define MA_HAS_STDINT
22
#include <stdint.h>
23
#define spx_uint64_t uint64_t
24
#endif
25
26
int
ma_speex_resampler_get_required_input_frame_count
(
SpeexResamplerState
* st,
spx_uint64_t
out_len,
spx_uint64_t
* in_len);
27
int
ma_speex_resampler_get_expected_output_frame_count
(
SpeexResamplerState
* st,
spx_uint64_t
in_len,
spx_uint64_t
* out_len);
28
29
#endif
/* ma_speex_resampler_h */
30
31
#if defined(MINIAUDIO_SPEEX_RESAMPLER_IMPLEMENTATION)
32
/* The Speex resampler uses "inline", which is not defined for C89. We need to define it here. */
33
#if defined(__GNUC__) && !defined(_MSC_VER)
34
#if defined(__STRICT_ANSI__)
35
#if !defined(inline)
36
#define inline __inline__ __attribute__((always_inline))
37
#define MA_SPEEX_INLINE_DEFINED
38
#endif
39
#endif
40
#endif
41
42
#if defined(_MSC_VER) && !defined(__clang__)
43
#pragma warning(push)
44
#pragma warning(disable:4244)
/* conversion from 'x' to 'y', possible loss of data */
45
#pragma warning(disable:4018)
/* signed/unsigned mismatch */
46
#pragma warning(disable:4706)
/* assignment within conditional expression */
47
#else
48
#pragma GCC diagnostic push
49
#pragma GCC diagnostic ignored "-Wsign-compare"
/* comparison between signed and unsigned integer expressions */
50
#endif
51
#include "thirdparty/resample.c"
52
#if defined(_MSC_VER) && !defined(__clang__)
53
#pragma warning(pop)
54
#else
55
#pragma GCC diagnostic pop
56
#endif
57
58
#if defined(MA_SPEEX_INLINE_DEFINED)
59
#undef inline
60
#undef MA_SPEEX_INLINE_DEFINED
61
#endif
62
63
EXPORT
int
ma_speex_resampler_get_required_input_frame_count
(
SpeexResamplerState
* st,
spx_uint64_t
out_len,
spx_uint64_t
* in_len)
64
{
65
spx_uint64_t
count
;
66
67
if
(st ==
NULL
|| in_len ==
NULL
) {
68
return
RESAMPLER_ERR_INVALID_ARG
;
69
}
70
71
*in_len = 0;
72
73
if
(out_len == 0) {
74
return
RESAMPLER_ERR_SUCCESS
;
/* Nothing to do. */
75
}
76
77
/* miniaudio only uses interleaved APIs so we can safely just use channel index 0 for the calculations. */
78
if
(st->
nb_channels
== 0) {
79
return
RESAMPLER_ERR_BAD_STATE
;
80
}
81
82
count
= out_len * st->
int_advance
;
83
count
+= (st->
samp_frac_num
[0] + (out_len * st->
frac_advance
)) / st->
den_rate
;
84
85
*in_len =
count
;
86
87
return
RESAMPLER_ERR_SUCCESS
;
88
}
89
90
EXPORT
int
ma_speex_resampler_get_expected_output_frame_count
(
SpeexResamplerState
* st,
spx_uint64_t
in_len,
spx_uint64_t
* out_len)
91
{
92
spx_uint64_t
count
;
93
spx_uint64_t
last_sample;
94
spx_uint32_t samp_frac_num;
95
96
if
(st ==
NULL
|| out_len ==
NULL
) {
97
return
RESAMPLER_ERR_INVALID_ARG
;
98
}
99
100
*out_len = 0;
101
102
if
(out_len == 0) {
103
return
RESAMPLER_ERR_SUCCESS
;
/* Nothing to do. */
104
}
105
106
/* miniaudio only uses interleaved APIs so we can safely just use channel index 0 for the calculations. */
107
if
(st->
nb_channels
== 0) {
108
return
RESAMPLER_ERR_BAD_STATE
;
109
}
110
111
count
= 0;
112
last_sample = st->
last_sample
[0];
113
samp_frac_num = st->
samp_frac_num
[0];
114
115
while
(!(last_sample >= in_len)) {
116
count
+= 1;
117
118
last_sample += st->
int_advance
;
119
samp_frac_num += st->
frac_advance
;
120
if
(samp_frac_num >= st->
den_rate
) {
121
samp_frac_num -= st->
den_rate
;
122
last_sample += 1;
123
}
124
}
125
126
*out_len =
count
;
127
128
return
RESAMPLER_ERR_SUCCESS
;
129
}
130
#endif
SpeexResamplerState_::frac_advance
int frac_advance
Definition:
porcupine/demo/c/dr_libs/tests/external/miniaudio/extras/speex_resampler/thirdparty/resample.c:128
SpeexResamplerState_::den_rate
spx_uint32_t den_rate
Definition:
porcupine/demo/c/dr_libs/tests/external/miniaudio/extras/speex_resampler/thirdparty/resample.c:120
SpeexResamplerState_::last_sample
spx_int32_t * last_sample
Definition:
porcupine/demo/c/dr_libs/tests/external/miniaudio/extras/speex_resampler/thirdparty/resample.c:135
NULL
#define NULL
Definition:
porcupine/demo/c/dr_libs/tests/external/miniaudio/extras/speex_resampler/thirdparty/resample.c:92
ma_speex_resampler_get_expected_output_frame_count
int ma_speex_resampler_get_expected_output_frame_count(SpeexResamplerState *st, spx_uint64_t in_len, spx_uint64_t *out_len)
SpeexResamplerState_::nb_channels
spx_uint32_t nb_channels
Definition:
porcupine/demo/c/dr_libs/tests/external/miniaudio/extras/speex_resampler/thirdparty/resample.c:123
SpeexResamplerState_
Definition:
porcupine/demo/c/dr_libs/tests/external/miniaudio/extras/speex_resampler/thirdparty/resample.c:116
count
size_t count
Definition:
porcupine/demo/c/dr_libs/tests/external/miniaudio/tests/test_common/ma_test_common.c:31
RESAMPLER_ERR_BAD_STATE
@ RESAMPLER_ERR_BAD_STATE
Definition:
porcupine/demo/c/dr_libs/tests/external/miniaudio/extras/speex_resampler/thirdparty/speex_resampler.h:106
SpeexResamplerState_::samp_frac_num
spx_uint32_t * samp_frac_num
Definition:
porcupine/demo/c/dr_libs/tests/external/miniaudio/extras/speex_resampler/thirdparty/resample.c:136
RESAMPLER_ERR_SUCCESS
@ RESAMPLER_ERR_SUCCESS
Definition:
porcupine/demo/c/dr_libs/tests/external/miniaudio/extras/speex_resampler/thirdparty/speex_resampler.h:104
RESAMPLER_ERR_INVALID_ARG
@ RESAMPLER_ERR_INVALID_ARG
Definition:
porcupine/demo/c/dr_libs/tests/external/miniaudio/extras/speex_resampler/thirdparty/speex_resampler.h:107
SpeexResamplerState_::int_advance
int int_advance
Definition:
porcupine/demo/c/dr_libs/tests/external/miniaudio/extras/speex_resampler/thirdparty/resample.c:127
spx_uint64_t
unsigned long long spx_uint64_t
Definition:
porcupine/demo/c/pvrecorder/src/miniaudio/extras/speex_resampler/ma_speex_resampler.h:19
ma_speex_resampler_get_required_input_frame_count
int ma_speex_resampler_get_required_input_frame_count(SpeexResamplerState *st, spx_uint64_t out_len, spx_uint64_t *in_len)
picovoice_driver
Author(s):
autogenerated on Fri Apr 1 2022 02:13:56