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 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/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_mapper.h"
17 #include "roc_audio/sample_spec.h"
18 #include "roc_core/noncopyable.h"
19 
20 namespace roc {
21 namespace audio {
22 
23 //! PCM decoder.
24 class PcmDecoder : public IFrameDecoder, public core::NonCopyable<> {
25 public:
26  //! Construction function.
28  const PcmFormat& pcm_format,
29  const SampleSpec& sample_spec);
30 
31  //! Initialize.
32  PcmDecoder(const PcmFormat& pcm_format, const SampleSpec& sample_spec);
33 
34  //! Get current stream position.
36 
37  //! Get number of samples available for decoding.
39 
40  //! Get number of samples per channel, that can be decoded from given frame.
41  virtual size_t decoded_sample_count(const void* frame_data, size_t frame_size) const;
42 
43  //! Start decoding a new frame.
44  virtual void begin(packet::stream_timestamp_t frame_position,
45  const void* frame_data,
46  size_t frame_size);
47 
48  //! Read samples from current frame.
49  virtual size_t read(sample_t* samples, size_t n_samples);
50 
51  //! Shift samples from current frame.
52  virtual size_t shift(size_t n_samples);
53 
54  //! Finish decoding current frame.
55  virtual void end();
56 
57 private:
58  PcmMapper pcm_mapper_;
59  const size_t n_chans_;
60 
61  packet::stream_timestamp_t stream_pos_;
62  packet::stream_timestamp_t stream_avail_;
63 
64  const void* frame_data_;
65  size_t frame_byte_size_;
66  size_t frame_bit_off_;
67 };
68 
69 } // namespace audio
70 } // namespace roc
71 
72 #endif // ROC_AUDIO_PCM_DECODER_H_
Audio frame decoder interface.
virtual packet::stream_timestamp_t available() const
Get number of samples available for decoding.
static IFrameDecoder * construct(core::IArena &arena, const PcmFormat &pcm_format, const SampleSpec &sample_spec)
Construction function.
virtual size_t shift(size_t n_samples)
Shift samples from current frame.
virtual size_t read(sample_t *samples, size_t n_samples)
Read samples from current frame.
virtual void begin(packet::stream_timestamp_t frame_position, const void *frame_data, size_t frame_size)
Start decoding a new frame.
virtual packet::stream_timestamp_t position() const
Get current stream position.
virtual void end()
Finish decoding current frame.
virtual size_t decoded_sample_count(const void *frame_data, size_t frame_size) const
Get number of samples per channel, that can be decoded from given frame.
PcmDecoder(const PcmFormat &pcm_format, const SampleSpec &sample_spec)
Initialize.
PCM format mapper. Convert between PCM formats.
Definition: pcm_mapper.h:24
Sample specification. Describes sample rate and channels.
Definition: sample_spec.h:26
Memory arena interface.
Definition: iarena.h:23
Base class for non-copyable objects.
Definition: noncopyable.h:23
Audio frame decoder interface.
float sample_t
Audio sample.
Definition: sample.h:22
uint32_t stream_timestamp_t
Packet stream timestamp.
Definition: units.h:36
Root namespace.
Non-copyable object.
PCM format mapper.
Sample specifications.
PCM format description.
Definition: pcm_format.h:61