Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Toggle main menu visibility
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
17
#include "
roc_audio/sample_spec.h
"
18
#include "
roc_core/array.h
"
19
#include "
roc_core/iarena.h
"
20
#include "
roc_core/noncopyable.h
"
21
#include "
roc_core/stddefs.h
"
22
#include "
roc_packet/units.h
"
23
#include "
roc_sndio/config.h
"
24
#include "
roc_sndio/driver.h
"
25
#include "
roc_sndio/isink.h
"
26
27
namespace
roc
{
28
namespace
sndio
{
29
30
//! SoX sink.
31
//! @remarks
32
//! Writes samples to output file or device.
33
//! Supports multiple drivers for different file types and audio systems.
34
class
SoxSink
:
public
ISink
,
public
core::NonCopyable
<> {
35
public
:
36
//! Initialize.
37
SoxSink
(
core::IArena
& arena,
const
Config
& config,
DriverType
type
);
38
39
virtual
~SoxSink
();
40
41
//! Check if the object was successfully constructed.
42
bool
is_valid
()
const
;
43
44
//! Open output file or device.
45
//!
46
//! @b Parameters
47
//! - @p driver is output driver name;
48
//! - @p path is output file or device name, "-" for stdout.
49
//!
50
//! @remarks
51
//! If @p driver or @p path are NULL, defaults are used.
52
bool
open
(
const
char
* driver,
const
char
* path);
53
54
//! Cast IDevice to ISink.
55
virtual
ISink
*
to_sink
();
56
57
//! Cast IDevice to ISink.
58
virtual
ISource
*
to_source
();
59
60
//! Get device type.
61
virtual
DeviceType
type
()
const
;
62
63
//! Get device state.
64
virtual
DeviceState
state
()
const
;
65
66
//! Pause reading.
67
virtual
void
pause
();
68
69
//! Resume paused reading.
70
virtual
bool
resume
();
71
72
//! Restart reading from the beginning.
73
virtual
bool
restart
();
74
75
//! Get sample specification of the sink.
76
virtual
audio::SampleSpec
sample_spec
()
const
;
77
78
//! Get latency of the sink.
79
virtual
core::nanoseconds_t
latency
()
const
;
80
81
//! Check if the sink supports latency reports.
82
virtual
bool
has_latency
()
const
;
83
84
//! Check if the sink has own clock.
85
virtual
bool
has_clock
()
const
;
86
87
//! Write audio frame.
88
virtual
void
write
(
audio::Frame
& frame);
89
90
private
:
91
bool
setup_buffer_();
92
bool
open_(
const
char
* driver,
const
char
* path);
93
void
write_(
const
sox_sample_t* samples,
size_t
n_samples);
94
void
close_();
95
96
sox_format_t* output_;
97
sox_signalinfo_t out_signal_;
98
99
core::Array<sox_sample_t>
buffer_;
100
size_t
buffer_size_;
101
core::nanoseconds_t
frame_length_;
102
audio::SampleSpec
sample_spec_;
103
104
bool
is_file_;
105
bool
valid_;
106
};
107
108
}
// namespace sndio
109
}
// namespace roc
110
111
#endif
// ROC_SNDIO_SOX_SINK_H_
array.h
Dynamic array.
roc::audio::Frame
Audio frame.
Definition
frame.h:25
roc::audio::SampleSpec
Sample specification. Describes sample rate and channels.
Definition
sample_spec.h:30
roc::core::Array
Dynamic array.
Definition
array.h:40
roc::core::IArena
Memory arena interface.
Definition
iarena.h:23
roc::core::NonCopyable
Base class for non-copyable objects.
Definition
noncopyable.h:23
roc::sndio::ISink
Sink interface.
Definition
isink.h:22
roc::sndio::ISource
Source interface.
Definition
isource.h:23
roc::sndio::SoxSink::resume
virtual bool resume()
Resume paused reading.
roc::sndio::SoxSink::sample_spec
virtual audio::SampleSpec sample_spec() const
Get sample specification of the sink.
roc::sndio::SoxSink::is_valid
bool is_valid() const
Check if the object was successfully constructed.
roc::sndio::SoxSink::write
virtual void write(audio::Frame &frame)
Write audio frame.
roc::sndio::SoxSink::state
virtual DeviceState state() const
Get device state.
roc::sndio::SoxSink::open
bool open(const char *driver, const char *path)
Open output file or device.
roc::sndio::SoxSink::has_latency
virtual bool has_latency() const
Check if the sink supports latency reports.
roc::sndio::SoxSink::pause
virtual void pause()
Pause reading.
roc::sndio::SoxSink::restart
virtual bool restart()
Restart reading from the beginning.
roc::sndio::SoxSink::type
virtual DeviceType type() const
Get device type.
roc::sndio::SoxSink::to_sink
virtual ISink * to_sink()
Cast IDevice to ISink.
roc::sndio::SoxSink::has_clock
virtual bool has_clock() const
Check if the sink has own clock.
roc::sndio::SoxSink::latency
virtual core::nanoseconds_t latency() const
Get latency of the sink.
roc::sndio::SoxSink::to_source
virtual ISource * to_source()
Cast IDevice to ISink.
roc::sndio::SoxSink::SoxSink
SoxSink(core::IArena &arena, const Config &config, DriverType type)
Initialize.
driver.h
Driver types.
iarena.h
Memory arena interface.
isink.h
Sink interface.
roc::core::nanoseconds_t
int64_t nanoseconds_t
Nanoseconds.
Definition
time.h:58
roc::sndio
Sound I/O.
roc::sndio::DeviceType
DeviceType
Device type.
Definition
device_type.h:19
roc::sndio::DriverType
DriverType
Driver type.
Definition
driver.h:27
roc::sndio::DeviceState
DeviceState
Device state.
Definition
device_state.h:19
roc
Root namespace.
noncopyable.h
Non-copyable object.
config.h
Sink and source config.
sample_spec.h
Sample specifications.
stddefs.h
Commonly used types and functions.
roc::sndio::Config
Sink and source config.
Definition
config.h:29
units.h
Various units used in packets.
roc_sndio
target_sox
roc_sndio
sox_sink.h
Generated by
1.17.0