Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Toggle main menu visibility
Loading...
Searching...
No Matches
wav_source.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_source.h
10
//! @brief WAV source.
11
12
#ifndef ROC_SNDIO_WAV_SOURCE_H_
13
#define ROC_SNDIO_WAV_SOURCE_H_
14
15
#include <dr_wav.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/isource.h
"
26
27
namespace
roc
{
28
namespace
sndio
{
29
30
//! WAV source.
31
class
WavSource
:
public
ISource
,
private
core::NonCopyable
<> {
32
public
:
33
//! Initialize.
34
WavSource
(
core::IArena
& arena,
const
Config
& config);
35
36
virtual
~WavSource
();
37
38
//! Check if the object was successfully constructed.
39
bool
is_valid
()
const
;
40
41
//! Open input file or device.
42
//!
43
//! @b Parameters
44
//! - @p path is input file or device name, "-" for stdin.
45
//!
46
//! @remarks
47
//! If @p path is NULL, defaults are used.
48
bool
open
(
const
char
* path);
49
50
//! Cast IDevice to ISink.
51
virtual
ISink
*
to_sink
();
52
53
//! Cast IDevice to ISink.
54
virtual
ISource
*
to_source
();
55
56
//! Get device type.
57
virtual
DeviceType
type
()
const
;
58
59
//! Get device state.
60
virtual
DeviceState
state
()
const
;
61
62
//! Pause reading.
63
virtual
void
pause
();
64
65
//! Resume paused reading.
66
virtual
bool
resume
();
67
68
//! Restart reading from the beginning.
69
virtual
bool
restart
();
70
71
//! Get sample specification of the source.
72
virtual
audio::SampleSpec
sample_spec
()
const
;
73
74
//! Get latency of the source.
75
virtual
core::nanoseconds_t
latency
()
const
;
76
77
//! Check if the source supports latency reports.
78
virtual
bool
has_latency
()
const
;
79
80
//! Check if the source has own clock.
81
virtual
bool
has_clock
()
const
;
82
83
//! Adjust source clock to match consumer clock.
84
virtual
void
reclock
(
core::nanoseconds_t
timestamp);
85
86
//! Read frame.
87
virtual
bool
read
(
audio::Frame
& frame);
88
89
private
:
90
bool
open_(
const
char
* path);
91
void
close_();
92
93
drwav wav_;
94
bool
file_opened_;
95
bool
eof_;
96
97
bool
valid_;
98
};
99
100
}
// namespace sndio
101
}
// namespace roc
102
103
#endif
// ROC_SNDIO_WAV_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::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::WavSource::state
virtual DeviceState state() const
Get device state.
roc::sndio::WavSource::sample_spec
virtual audio::SampleSpec sample_spec() const
Get sample specification of the source.
roc::sndio::WavSource::pause
virtual void pause()
Pause reading.
roc::sndio::WavSource::latency
virtual core::nanoseconds_t latency() const
Get latency of the source.
roc::sndio::WavSource::restart
virtual bool restart()
Restart reading from the beginning.
roc::sndio::WavSource::has_latency
virtual bool has_latency() const
Check if the source supports latency reports.
roc::sndio::WavSource::is_valid
bool is_valid() const
Check if the object was successfully constructed.
roc::sndio::WavSource::type
virtual DeviceType type() const
Get device type.
roc::sndio::WavSource::WavSource
WavSource(core::IArena &arena, const Config &config)
Initialize.
roc::sndio::WavSource::resume
virtual bool resume()
Resume paused reading.
roc::sndio::WavSource::to_source
virtual ISource * to_source()
Cast IDevice to ISink.
roc::sndio::WavSource::reclock
virtual void reclock(core::nanoseconds_t timestamp)
Adjust source clock to match consumer clock.
roc::sndio::WavSource::to_sink
virtual ISink * to_sink()
Cast IDevice to ISink.
roc::sndio::WavSource::read
virtual bool read(audio::Frame &frame)
Read frame.
roc::sndio::WavSource::has_clock
virtual bool has_clock() const
Check if the source has own clock.
roc::sndio::WavSource::open
bool open(const char *path)
Open input file or device.
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::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
wav_source.h
Generated by
1.17.0