Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Toggle main menu visibility
Loading...
Searching...
No Matches
speex_resampler.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2019 Roc Streaming authors
3
*
4
* This Source Code Form is subject to the terms of the Mozilla Public
5
* License, v. 2.0. If a copy of the MPL was not distributed with this
6
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
*/
8
9
//! @file roc_audio/target_speexdsp/roc_audio/speex_resampler.h
10
//! @brief Speex resampler.
11
12
#ifndef ROC_AUDIO_SPEEX_RESAMPLER_H_
13
#define ROC_AUDIO_SPEEX_RESAMPLER_H_
14
15
#include "
roc_audio/frame.h
"
16
#include "
roc_audio/frame_factory.h
"
17
#include "
roc_audio/iframe_reader.h
"
18
#include "
roc_audio/iresampler.h
"
19
#include "
roc_audio/resampler_config.h
"
20
#include "
roc_audio/sample.h
"
21
#include "
roc_audio/sample_spec.h
"
22
#include "
roc_core/array.h
"
23
#include "
roc_core/noncopyable.h
"
24
#include "
roc_core/rate_limiter.h
"
25
#include "
roc_core/slice.h
"
26
#include "
roc_core/stddefs.h
"
27
#include "
roc_packet/units.h
"
28
29
#include <speex/speex_resampler.h>
30
31
namespace
roc
{
32
namespace
audio
{
33
34
//! Speex resampler.
35
//!
36
//! Resamples audio stream using SpeexDSP library.
37
//!
38
//! This backend is very fast even on weak CPUs, and provides good quality,
39
//! but it can't apply requested scaling very precisely.
40
class
SpeexResampler
:
public
IResampler
,
public
core::NonCopyable
<> {
41
public
:
42
//! Initialize.
43
SpeexResampler
(
core::IArena
&
arena
,
44
FrameFactory
& frame_factory,
45
ResamplerProfile
profile,
46
const
SampleSpec
& in_spec,
47
const
SampleSpec
& out_spec);
48
49
~SpeexResampler
();
50
51
//! Check if object is successfully constructed.
52
virtual
bool
is_valid
()
const
;
53
54
//! Set new resample factor.
55
virtual
bool
set_scaling
(
size_t
input_rate,
size_t
output_rate,
float
multiplier);
56
57
//! Get buffer to be filled with input data.
58
virtual
const
core::Slice<sample_t>
&
begin_push_input
();
59
60
//! Commit buffer with input data.
61
virtual
void
end_push_input
();
62
63
//! Read samples from input frame and fill output frame.
64
virtual
size_t
pop_output
(
sample_t
* out_data,
size_t
out_size);
65
66
//! How many samples were pushed but not processed yet.
67
virtual
float
n_left_to_process
()
const
;
68
69
private
:
70
void
report_stats_();
71
72
SpeexResamplerState* speex_state_;
73
74
// Channel count.
75
const
spx_uint32_t num_ch_;
76
77
// Frame with input samples.
78
core::Slice<sample_t>
in_frame_;
79
spx_uint32_t in_frame_size_;
80
spx_uint32_t in_frame_pos_;
81
82
// Counts how many output samples to throw away in order to
83
// compensate resampler's inner latency.
84
size_t
initial_out_countdown_;
85
86
// Stores initial latency in order to track its further changes.
87
size_t
initial_in_latency_;
88
89
// Stores how much speex resampler latency changed from the start, in order to
90
// reflect it in n_left_to_process() for better precision in capture timestamp
91
// calculations.
92
ssize_t in_latency_diff_;
93
94
core::RateLimiter
rate_limiter_;
95
96
bool
valid_;
97
};
98
99
}
// namespace audio
100
}
// namespace roc
101
102
#endif
// ROC_AUDIO_SPEEX_RESAMPLER_H_
array.h
Dynamic array.
roc::audio::FrameFactory
Frame factory.
Definition
frame_factory.h:38
roc::audio::IResampler::IResampler
IResampler(core::IArena &arena)
Initialization.
roc::audio::SampleSpec
Sample specification. Describes sample rate and channels.
Definition
sample_spec.h:30
roc::audio::SpeexResampler::end_push_input
virtual void end_push_input()
Commit buffer with input data.
roc::audio::SpeexResampler::is_valid
virtual bool is_valid() const
Check if object is successfully constructed.
roc::audio::SpeexResampler::set_scaling
virtual bool set_scaling(size_t input_rate, size_t output_rate, float multiplier)
Set new resample factor.
roc::audio::SpeexResampler::begin_push_input
virtual const core::Slice< sample_t > & begin_push_input()
Get buffer to be filled with input data.
roc::audio::SpeexResampler::pop_output
virtual size_t pop_output(sample_t *out_data, size_t out_size)
Read samples from input frame and fill output frame.
roc::audio::SpeexResampler::SpeexResampler
SpeexResampler(core::IArena &arena, FrameFactory &frame_factory, ResamplerProfile profile, const SampleSpec &in_spec, const SampleSpec &out_spec)
Initialize.
roc::audio::SpeexResampler::n_left_to_process
virtual float n_left_to_process() const
How many samples were pushed but not processed yet.
roc::core::ArenaAllocation::arena
IArena & arena() const
Get arena.
Definition
allocation_policy.h:37
roc::core::IArena
Memory arena interface.
Definition
iarena.h:23
roc::core::NonCopyable
Base class for non-copyable objects.
Definition
noncopyable.h:23
roc::core::RateLimiter
Rate limiter.
Definition
rate_limiter.h:22
roc::core::Slice
Slice.
Definition
slice.h:55
frame.h
Audio frame.
frame_factory.h
Frame factory.
iframe_reader.h
Frame reader interface.
iresampler.h
Audio resampler interface.
roc::audio
Audio frames and audio processing.
roc::audio::sample_t
float sample_t
Raw audio sample.
Definition
sample.h:22
roc::audio::ResamplerProfile
ResamplerProfile
Resampler parameters presets.
Definition
resampler_config.h:43
roc
Root namespace.
noncopyable.h
Non-copyable object.
rate_limiter.h
Rate limiter.
resampler_config.h
Resampler config.
sample.h
Audio sample.
sample_spec.h
Sample specifications.
slice.h
Slice.
stddefs.h
Commonly used types and functions.
units.h
Various units used in packets.
roc_audio
target_speexdsp
roc_audio
speex_resampler.h
Generated by
1.17.0