Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Toggle main menu visibility
Loading...
Searching...
No Matches
wav_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/wav_sink.h
10
//! @brief WAV sink.
11
12
#ifndef ROC_SNDIO_WAV_SINK_H_
13
#define ROC_SNDIO_WAV_SINK_H_
14
15
#include "
roc_audio/sample_spec.h
"
16
#include "
roc_core/array.h
"
17
#include "
roc_core/iarena.h
"
18
#include "
roc_core/noncopyable.h
"
19
#include "
roc_core/optional.h
"
20
#include "
roc_core/stddefs.h
"
21
#include "
roc_packet/units.h
"
22
#include "
roc_sndio/config.h
"
23
#include "
roc_sndio/isink.h
"
24
25
#include "
wav_header.h
"
26
27
namespace
roc
{
28
namespace
sndio
{
29
30
//! WAV sink.
31
//! @remarks
32
//! Writes samples to output file.
33
class
WavSink
:
public
ISink
,
public
core::NonCopyable
<> {
34
public
:
35
//! Initialize.
36
WavSink
(
core::IArena
& arena,
const
Config
& config);
37
38
virtual
~WavSink
();
39
40
//! Check if the object was successfully constructed.
41
bool
is_valid
()
const
;
42
43
//! Open output file.
44
//!
45
//! @b Parameters
46
//! - @p path is output file or device name, "-" for stdout.
47
//!
48
//! @remarks
49
//! If @p path is NULL, defaults are used.
50
bool
open
(
const
char
* path);
51
52
//! Cast IDevice to ISink.
53
virtual
ISink
*
to_sink
();
54
55
//! Cast IDevice to ISink.
56
virtual
ISource
*
to_source
();
57
58
//! Get device type.
59
virtual
DeviceType
type
()
const
;
60
61
//! Get device state.
62
virtual
DeviceState
state
()
const
;
63
64
//! Pause reading.
65
virtual
void
pause
();
66
67
//! Resume paused reading.
68
virtual
bool
resume
();
69
70
//! Restart reading from the beginning.
71
virtual
bool
restart
();
72
73
//! Get sample specification of the sink.
74
virtual
audio::SampleSpec
sample_spec
()
const
;
75
76
//! Get latency of the sink.
77
virtual
core::nanoseconds_t
latency
()
const
;
78
79
//! Check if the sink supports latency reports.
80
virtual
bool
has_latency
()
const
;
81
82
//! Check if the sink has own clock.
83
virtual
bool
has_clock
()
const
;
84
85
//! Write audio frame.
86
virtual
void
write
(
audio::Frame
& frame);
87
88
private
:
89
bool
open_(
const
char
* path);
90
void
close_();
91
92
audio::SampleSpec
sample_spec_;
93
94
FILE* output_file_;
95
core::Optional<WavHeader>
header_;
96
97
bool
valid_;
98
};
99
100
}
// namespace sndio
101
}
// namespace roc
102
103
#endif
// ROC_SNDIO_WAV_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::core::Optional
Optionally constructed object.
Definition
optional.h:25
roc::sndio::ISink
Sink interface.
Definition
isink.h:22
roc::sndio::ISource
Source interface.
Definition
isource.h:23
roc::sndio::WavSink::open
bool open(const char *path)
Open output file.
roc::sndio::WavSink::write
virtual void write(audio::Frame &frame)
Write audio frame.
roc::sndio::WavSink::sample_spec
virtual audio::SampleSpec sample_spec() const
Get sample specification of the sink.
roc::sndio::WavSink::has_latency
virtual bool has_latency() const
Check if the sink supports latency reports.
roc::sndio::WavSink::has_clock
virtual bool has_clock() const
Check if the sink has own clock.
roc::sndio::WavSink::state
virtual DeviceState state() const
Get device state.
roc::sndio::WavSink::resume
virtual bool resume()
Resume paused reading.
roc::sndio::WavSink::WavSink
WavSink(core::IArena &arena, const Config &config)
Initialize.
roc::sndio::WavSink::to_sink
virtual ISink * to_sink()
Cast IDevice to ISink.
roc::sndio::WavSink::pause
virtual void pause()
Pause reading.
roc::sndio::WavSink::latency
virtual core::nanoseconds_t latency() const
Get latency of the sink.
roc::sndio::WavSink::restart
virtual bool restart()
Restart reading from the beginning.
roc::sndio::WavSink::is_valid
bool is_valid() const
Check if the object was successfully constructed.
roc::sndio::WavSink::to_source
virtual ISource * to_source()
Cast IDevice to ISink.
roc::sndio::WavSink::type
virtual DeviceType type() const
Get device type.
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.
optional.h
Optionally constructed 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.
wav_header.h
WAV header.
roc_sndio
wav_sink.h
Generated by
1.17.0