Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Loading...
Searching...
No Matches
sox_sink.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_sndio/target_sox/roc_sndio/sox_sink.h
10//! @brief SoX sink.
11
12#ifndef ROC_SNDIO_SOX_SINK_H_
13#define ROC_SNDIO_SOX_SINK_H_
14
15#include <sox.h>
16
18#include "roc_core/array.h"
19#include "roc_core/iallocator.h"
21#include "roc_core/stddefs.h"
22#include "roc_packet/units.h"
23#include "roc_sndio/config.h"
24#include "roc_sndio/isink.h"
25
26namespace roc {
27namespace sndio {
28
29//! SoX sink.
30//! @remarks
31//! Writes samples to output file or device.
32//! Supports multiple drivers for different file types and audio systems.
33class SoxSink : public ISink, public core::NonCopyable<> {
34public:
35 //! Initialize.
36 SoxSink(core::IAllocator& allocator, const Config& config);
37
38 virtual ~SoxSink();
39
40 //! Check if the object was successfully constructed.
41 bool valid() const;
42
43 //! Open output file or device.
44 //!
45 //! @b Parameters
46 //! - @p driver is output driver name;
47 //! - @p path is output file or device name, "-" for stdout.
48 //!
49 //! @remarks
50 //! If @p driver or @p path are NULL, defaults are used.
51 bool open(const char* driver, const char* path);
52
53 //! Get sample specification of the sink.
55
56 //! Get latency of the sink.
58
59 //! Check if the sink has own clock.
60 virtual bool has_clock() const;
61
62 //! Write audio frame.
63 virtual void write(audio::Frame& frame);
64
65private:
66 bool setup_buffer_();
67 bool open_(const char* driver, const char* path);
68 void write_(const sox_sample_t* samples, size_t n_samples);
69 void close_();
70
71 sox_format_t* output_;
72 sox_signalinfo_t out_signal_;
73
75 size_t buffer_size_;
76 core::nanoseconds_t frame_length_;
77 audio::SampleSpec sample_spec_;
78
79 bool is_file_;
80 bool valid_;
81};
82
83} // namespace sndio
84} // namespace roc
85
86#endif // ROC_SNDIO_SOX_SINK_H_
Dynamic array.
Audio frame.
Definition frame.h:22
Sample stream specification. Defines sample rate and channel layout.
Definition sample_spec.h:24
Dynamic array.
Definition array.h:38
Memory allocator interface.
Definition iallocator.h:23
Base class for non-copyable objects.
Definition noncopyable.h:23
Sink interface.
Definition isink.h:22
virtual audio::SampleSpec sample_spec() const
Get sample specification of the sink.
virtual void write(audio::Frame &frame)
Write audio frame.
bool open(const char *driver, const char *path)
Open output file or device.
virtual bool has_clock() const
Check if the sink has own clock.
SoxSink(core::IAllocator &allocator, const Config &config)
Initialize.
virtual core::nanoseconds_t latency() const
Get latency of the sink.
bool valid() const
Check if the object was successfully constructed.
Memory allocator interface.
Sink interface.
int64_t nanoseconds_t
Nanoseconds.
Definition time.h:58
Root namespace.
Non-copyable object.
Sink and source config.
Sample specifications.
Commonly used types and functions.
Sink and source config.
Definition config.h:23
Various units used in packets.