Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Toggle main menu visibility
Loading...
Searching...
No Matches
sndfile_sink.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2023 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_sndfile/roc_sndio/sndfile_sink.h
10
//! @brief SndFile sink.
11
12
#ifndef ROC_SNDIO_SNDFILE_SINK_H_
13
#define ROC_SNDIO_SNDFILE_SINK_H_
14
15
#include <sndfile.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/isink.h
"
25
26
namespace
roc
{
27
namespace
sndio
{
28
29
//! Sndfile sink.
30
//! @remarks
31
//! Writes samples to output file.
32
//! Supports multiple drivers for different file types.
33
class
SndfileSink
:
public
ISink
,
public
core::NonCopyable
<> {
34
public
:
35
//! Initialize.
36
SndfileSink
(
core::IArena
& arena,
const
Config
& config);
37
38
virtual
~SndfileSink
();
39
40
//! Check if the object was successfully constructed.
41
bool
is_valid
()
const
;
42
43
//! Open output file or device.
44
//!
45
//! @b Parameters
46
//! - @p driver is output format name;
47
//! - @p path is output file name, "-" for stdout.
48
//!
49
//! @remarks
50
//! If @p driver is NULL, default is used.
51
bool
open
(
const
char
* driver,
const
char
* path);
52
53
//! Cast IDevice to ISink.
54
virtual
ISink
*
to_sink
();
55
56
//! Cast IDevice to ISink.
57
virtual
ISource
*
to_source
();
58
59
//! Get device type.
60
virtual
DeviceType
type
()
const
;
61
62
//! Get device state.
63
virtual
DeviceState
state
()
const
;
64
65
//! Pause reading.
66
virtual
void
pause
();
67
68
//! Resume paused reading.
69
virtual
bool
resume
();
70
71
//! Restart reading from the beginning.
72
virtual
bool
restart
();
73
74
//! Get sample specification of the sink.
75
virtual
audio::SampleSpec
sample_spec
()
const
;
76
77
//! Get latency of the sink.
78
virtual
core::nanoseconds_t
latency
()
const
;
79
80
//! Check if the sink supports latency reports.
81
virtual
bool
has_latency
()
const
;
82
83
//! Check if the sink has own clock.
84
virtual
bool
has_clock
()
const
;
85
86
//! Write audio frame.
87
virtual
void
write
(
audio::Frame
& frame);
88
89
private
:
90
bool
open_(
const
char
* driver,
const
char
* path);
91
void
close_();
92
93
SNDFILE* file_;
94
SF_INFO file_info_;
95
96
audio::SampleSpec
sample_spec_;
97
bool
valid_;
98
};
99
100
}
// namespace sndio
101
}
// namespace roc
102
103
#endif
// ROC_SNDIO_SNDFILE_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::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::SndfileSink::SndfileSink
SndfileSink(core::IArena &arena, const Config &config)
Initialize.
roc::sndio::SndfileSink::has_clock
virtual bool has_clock() const
Check if the sink has own clock.
roc::sndio::SndfileSink::restart
virtual bool restart()
Restart reading from the beginning.
roc::sndio::SndfileSink::to_sink
virtual ISink * to_sink()
Cast IDevice to ISink.
roc::sndio::SndfileSink::to_source
virtual ISource * to_source()
Cast IDevice to ISink.
roc::sndio::SndfileSink::resume
virtual bool resume()
Resume paused reading.
roc::sndio::SndfileSink::is_valid
bool is_valid() const
Check if the object was successfully constructed.
roc::sndio::SndfileSink::state
virtual DeviceState state() const
Get device state.
roc::sndio::SndfileSink::open
bool open(const char *driver, const char *path)
Open output file or device.
roc::sndio::SndfileSink::latency
virtual core::nanoseconds_t latency() const
Get latency of the sink.
roc::sndio::SndfileSink::type
virtual DeviceType type() const
Get device type.
roc::sndio::SndfileSink::write
virtual void write(audio::Frame &frame)
Write audio frame.
roc::sndio::SndfileSink::has_latency
virtual bool has_latency() const
Check if the sink supports latency reports.
roc::sndio::SndfileSink::sample_spec
virtual audio::SampleSpec sample_spec() const
Get sample specification of the sink.
roc::sndio::SndfileSink::pause
virtual void pause()
Pause reading.
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::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_sndfile
roc_sndio
sndfile_sink.h
Generated by
1.17.0