Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
iresampler.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/iresampler.h
10 //! @brief Audio resampler interface.
11 
12 #ifndef ROC_AUDIO_IRESAMPLER_H_
13 #define ROC_AUDIO_IRESAMPLER_H_
14 
15 #include "roc_audio/frame.h"
16 #include "roc_core/noncopyable.h"
17 #include "roc_core/ref_counted.h"
18 #include "roc_core/slice.h"
19 
20 namespace roc {
21 namespace audio {
22 
23 //! Audio writer interface.
24 class IResampler : public core::RefCounted<IResampler, core::ArenaAllocation> {
25 public:
26  //! Initialization.
28 
29  //! Deinitialization.
30  virtual ~IResampler();
31 
32  //! Check if object is successfully constructed.
33  virtual bool is_valid() const = 0;
34 
35  //! Set new resample factor.
36  //! @remarks
37  //! Returns false if the scaling is invalid or out of bounds.
38  virtual bool set_scaling(size_t input_rate, size_t output_rate, float multiplier) = 0;
39 
40  //! Get buffer to be filled with input data.
41  //! @remarks
42  //! After this call, the caller should fill returned buffer with input
43  //! data and invoke end_push_input().
45 
46  //! Commit buffer with input data.
47  //! @remarks
48  //! Should be called after begin_push_input() to commit the push operation.
49  virtual void end_push_input() = 0;
50 
51  //! Read samples from input buffer and fill output frame.
52  //! @remarks
53  //! May return lesser samples than requested if there are no more samples in
54  //! the input ring buffer. In this case the caller should provide resampler
55  //! with more input samples using begin_push_input() and end_push_input().
56  virtual size_t pop_output(sample_t* out_data, size_t out_size) = 0;
57 
58  //! How many samples were pushed but not processed yet.
59  //! @remarks
60  //! If last input sample pushed to resampler has number N, then last output sample
61  //! popped from resampler corresponds to input sample number N - n_left_to_process().
62  //! @note
63  //! It is float, as a resampler backend could possibly keep track of current
64  //! position from output stream perspective.
65  //! @returns
66  //! Number of samples multiplied by channel count.
67  virtual float n_left_to_process() const = 0;
68 };
69 
70 } // namespace audio
71 } // namespace roc
72 
73 #endif // ROC_AUDIO_IRESAMPLER_H_
Audio writer interface.
Definition: iresampler.h:24
virtual float n_left_to_process() const =0
How many samples were pushed but not processed yet.
virtual bool is_valid() const =0
Check if object is successfully constructed.
virtual ~IResampler()
Deinitialization.
virtual void end_push_input()=0
Commit buffer with input data.
virtual const core::Slice< sample_t > & begin_push_input()=0
Get buffer to be filled with input data.
IResampler(core::IArena &arena)
Initialization.
virtual size_t pop_output(sample_t *out_data, size_t out_size)=0
Read samples from input buffer and fill output frame.
virtual bool set_scaling(size_t input_rate, size_t output_rate, float multiplier)=0
Set new resample factor.
IArena & arena() const
Get arena.
Memory arena interface.
Definition: iarena.h:23
Base class for object with reference counter.
Definition: ref_counted.h:40
Audio frame.
float sample_t
Audio sample.
Definition: sample.h:22
Root namespace.
Non-copyable object.
Base class for object with reference counter.
Slice.