Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
pcm_encoder.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_encoder.h
10 //! @brief PCM encoder.
11 
12 #ifndef ROC_AUDIO_PCM_ENCODER_H_
13 #define ROC_AUDIO_PCM_ENCODER_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 encoder.
24 class PcmEncoder : public IFrameEncoder, public core::NonCopyable<> {
25 public:
26  //! Construction function.
27  static IFrameEncoder* construct(core::IArena& arena, const SampleSpec& sample_spec);
28 
29  //! Initialize.
30  PcmEncoder(const SampleSpec& sample_spec);
31 
32  //! Get encoded frame size in bytes for given number of samples per channel.
33  virtual size_t encoded_byte_count(size_t num_samples) const;
34 
35  //! Start encoding a new frame.
36  virtual void begin(void* frame, size_t frame_size);
37 
38  //! Encode samples.
39  virtual size_t write(const sample_t* samples, size_t n_samples);
40 
41  //! Finish encoding frame.
42  virtual void end();
43 
44 private:
45  PcmMapper pcm_mapper_;
46  const size_t n_chans_;
47 
48  void* frame_data_;
49  size_t frame_byte_size_;
50  size_t frame_bit_off_;
51 };
52 
53 } // namespace audio
54 } // namespace roc
55 
56 #endif // ROC_AUDIO_PCM_ENCODER_H_
Audio frame encoder interface.
PcmEncoder(const SampleSpec &sample_spec)
Initialize.
virtual size_t write(const sample_t *samples, size_t n_samples)
Encode samples.
virtual size_t encoded_byte_count(size_t num_samples) const
Get encoded frame size in bytes for given number of samples per channel.
virtual void begin(void *frame, size_t frame_size)
Start encoding a new frame.
virtual void end()
Finish encoding frame.
static IFrameEncoder * construct(core::IArena &arena, const SampleSpec &sample_spec)
Construction function.
PCM format mapper. Convert between PCM formats.
Definition: pcm_mapper.h:24
Sample specification. Describes sample rate and channels.
Definition: sample_spec.h:30
Memory arena interface.
Definition: iarena.h:23
Base class for non-copyable objects.
Definition: noncopyable.h:23
Audio frame encoder interface.
float sample_t
Raw audio sample.
Definition: sample.h:22
Root namespace.
Non-copyable object.
PCM format mapper.
Sample specifications.