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