Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Toggle main menu visibility
Loading...
Searching...
No Matches
sox_source.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2019 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_source.h
10
//! @brief SoX source.
11
12
#ifndef ROC_SNDIO_SOX_SOURCE_H_
13
#define ROC_SNDIO_SOX_SOURCE_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_core/string_buffer.h
"
23
#include "
roc_packet/units.h
"
24
#include "
roc_sndio/config.h
"
25
#include "
roc_sndio/driver.h
"
26
#include "
roc_sndio/isource.h
"
27
28
namespace
roc
{
29
namespace
sndio
{
30
31
//! SoX source.
32
//! @remarks
33
//! Reads samples from input file or device.
34
//! Supports multiple drivers for different file types and audio systems.
35
class
SoxSource
:
public
ISource
,
private
core::NonCopyable
<> {
36
public
:
37
//! Initialize.
38
SoxSource
(
core::IArena
& arena,
const
Config
& config,
DriverType
type
);
39
40
virtual
~SoxSource
();
41
42
//! Check if the object was successfully constructed.
43
bool
is_valid
()
const
;
44
45
//! Open input file or device.
46
//!
47
//! @b Parameters
48
//! - @p driver is input driver name;
49
//! - @p path is input file or device name, "-" for stdin.
50
//!
51
//! @remarks
52
//! If @p driver or @p path are NULL, defaults are used.
53
bool
open
(
const
char
* driver,
const
char
* path);
54
55
//! Cast IDevice to ISink.
56
virtual
ISink
*
to_sink
();
57
58
//! Cast IDevice to ISink.
59
virtual
ISource
*
to_source
();
60
61
//! Get device type.
62
virtual
DeviceType
type
()
const
;
63
64
//! Get device state.
65
virtual
DeviceState
state
()
const
;
66
67
//! Pause reading.
68
virtual
void
pause
();
69
70
//! Resume paused reading.
71
virtual
bool
resume
();
72
73
//! Restart reading from the beginning.
74
virtual
bool
restart
();
75
76
//! Get sample specification of the source.
77
virtual
audio::SampleSpec
sample_spec
()
const
;
78
79
//! Get latency of the source.
80
virtual
core::nanoseconds_t
latency
()
const
;
81
82
//! Check if the source supports latency reports.
83
virtual
bool
has_latency
()
const
;
84
85
//! Check if the source has own clock.
86
virtual
bool
has_clock
()
const
;
87
88
//! Adjust source clock to match consumer clock.
89
virtual
void
reclock
(
core::nanoseconds_t
timestamp);
90
91
//! Read frame.
92
virtual
bool
read
(
audio::Frame
&);
93
94
private
:
95
bool
setup_names_(
const
char
* driver,
const
char
* path);
96
bool
setup_buffer_();
97
98
bool
open_();
99
void
close_();
100
101
bool
seek_(uint64_t offset);
102
103
core::StringBuffer
driver_name_;
104
core::StringBuffer
input_name_;
105
106
core::Array<sox_sample_t>
buffer_;
107
size_t
buffer_size_;
108
core::nanoseconds_t
frame_length_;
109
audio::SampleSpec
sample_spec_;
110
111
sox_format_t* input_;
112
sox_signalinfo_t in_signal_;
113
114
bool
is_file_;
115
bool
eof_;
116
bool
paused_;
117
bool
valid_;
118
};
119
120
}
// namespace sndio
121
}
// namespace roc
122
123
#endif
// ROC_SNDIO_SOX_SOURCE_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::core::StringBuffer
String buffer.
Definition
string_buffer.h:30
roc::sndio::ISink
Sink interface.
Definition
isink.h:22
roc::sndio::ISource
Source interface.
Definition
isource.h:23
roc::sndio::SoxSource::to_sink
virtual ISink * to_sink()
Cast IDevice to ISink.
roc::sndio::SoxSource::open
bool open(const char *driver, const char *path)
Open input file or device.
roc::sndio::SoxSource::pause
virtual void pause()
Pause reading.
roc::sndio::SoxSource::type
virtual DeviceType type() const
Get device type.
roc::sndio::SoxSource::to_source
virtual ISource * to_source()
Cast IDevice to ISink.
roc::sndio::SoxSource::state
virtual DeviceState state() const
Get device state.
roc::sndio::SoxSource::SoxSource
SoxSource(core::IArena &arena, const Config &config, DriverType type)
Initialize.
roc::sndio::SoxSource::is_valid
bool is_valid() const
Check if the object was successfully constructed.
roc::sndio::SoxSource::has_clock
virtual bool has_clock() const
Check if the source has own clock.
roc::sndio::SoxSource::restart
virtual bool restart()
Restart reading from the beginning.
roc::sndio::SoxSource::sample_spec
virtual audio::SampleSpec sample_spec() const
Get sample specification of the source.
roc::sndio::SoxSource::latency
virtual core::nanoseconds_t latency() const
Get latency of the source.
roc::sndio::SoxSource::read
virtual bool read(audio::Frame &)
Read frame.
roc::sndio::SoxSource::has_latency
virtual bool has_latency() const
Check if the source supports latency reports.
roc::sndio::SoxSource::reclock
virtual void reclock(core::nanoseconds_t timestamp)
Adjust source clock to match consumer clock.
roc::sndio::SoxSource::resume
virtual bool resume()
Resume paused reading.
driver.h
Driver types.
iarena.h
Memory arena interface.
isource.h
Source 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.
string_buffer.h
String buffer.
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_source.h
Generated by
1.17.0