Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
pcm_decoder.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Roc 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/pcm_decoder.h
10 //! @brief PCM decoder.
11 
12 #ifndef ROC_AUDIO_PCM_DECODER_H_
13 #define ROC_AUDIO_PCM_DECODER_H_
14 
16 #include "roc_audio/pcm_funcs.h"
17 #include "roc_core/noncopyable.h"
18 
19 namespace roc {
20 namespace audio {
21 
22 //! PCM decoder.
23 class PCMDecoder : public IFrameDecoder, public core::NonCopyable<> {
24 public:
25  //! Initialize.
26  explicit PCMDecoder(const PCMFuncs& funcs);
27 
28  //! Get current stream position.
29  virtual packet::timestamp_t position() const;
30 
31  //! Get number of samples available for decoding.
32  virtual packet::timestamp_t available() const;
33 
34  //! Start decoding a new frame.
35  virtual void
36  begin(packet::timestamp_t frame_position, const void* frame_data, size_t frame_size);
37 
38  //! Read samples from current frame.
39  virtual size_t
40  read(sample_t* samples, size_t n_samples, packet::channel_mask_t channels);
41 
42  //! Shift samples from current frame.
43  virtual size_t shift(size_t n_samples);
44 
45  //! Finish decoding current frame.
46  virtual void end();
47 
48 private:
49  const PCMFuncs& funcs_;
50 
51  packet::timestamp_t stream_pos_;
52  packet::timestamp_t stream_avail_;
53 
54  const void* frame_data_;
55  size_t frame_size_;
56  size_t frame_pos_;
57 };
58 
59 } // namespace audio
60 } // namespace roc
61 
62 #endif // ROC_AUDIO_PCM_DECODER_H_
virtual void begin(packet::timestamp_t frame_position, const void *frame_data, size_t frame_size)
Start decoding a new frame.
Root namespace.
virtual void end()
Finish decoding current frame.
float sample_t
Audio sample.
Definition: units.h:21
Audio frame decoder interface.
virtual size_t read(sample_t *samples, size_t n_samples, packet::channel_mask_t channels)
Read samples from current frame.
PCMDecoder(const PCMFuncs &funcs)
Initialize.
uint32_t channel_mask_t
Bitmask of channels present in audio packet.
Definition: units.h:77
uint32_t timestamp_t
Audio packet timestamp.
Definition: units.h:46
PCM function table.
Definition: pcm_funcs.h:23
virtual size_t shift(size_t n_samples)
Shift samples from current frame.
Base class for non-copyable objects.
Definition: noncopyable.h:23
virtual packet::timestamp_t available() const
Get number of samples available for decoding.
virtual packet::timestamp_t position() const
Get current stream position.
Non-copyable object.
Audio frame decoder interface.
RTP PCM functions.