Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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
18#include "roc_core/array.h"
19#include "roc_core/iarena.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
26namespace roc {
27namespace sndio {
28
29//! Sndfile sink.
30//! @remarks
31//! Writes samples to output file.
32//! Supports multiple drivers for different file types.
33class SndfileSink : public ISink, public core::NonCopyable<> {
34public:
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.
76
77 //! Get latency of the sink.
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
89private:
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_
Dynamic array.
Audio frame.
Definition frame.h:25
Sample specification. Describes sample rate and channels.
Definition sample_spec.h:30
Memory arena interface.
Definition iarena.h:23
Base class for non-copyable objects.
Definition noncopyable.h:23
Sink interface.
Definition isink.h:22
Source interface.
Definition isource.h:23
SndfileSink(core::IArena &arena, const Config &config)
Initialize.
virtual bool has_clock() const
Check if the sink has own clock.
virtual bool restart()
Restart reading from the beginning.
virtual ISink * to_sink()
Cast IDevice to ISink.
virtual ISource * to_source()
Cast IDevice to ISink.
virtual bool resume()
Resume paused reading.
bool is_valid() const
Check if the object was successfully constructed.
virtual DeviceState state() const
Get device state.
bool open(const char *driver, const char *path)
Open output file or device.
virtual core::nanoseconds_t latency() const
Get latency of the sink.
virtual DeviceType type() const
Get device type.
virtual void write(audio::Frame &frame)
Write audio frame.
virtual bool has_latency() const
Check if the sink supports latency reports.
virtual audio::SampleSpec sample_spec() const
Get sample specification of the sink.
virtual void pause()
Pause reading.
Memory arena interface.
Sink interface.
int64_t nanoseconds_t
Nanoseconds.
Definition time.h:58
DeviceType
Device type.
Definition device_type.h:19
DeviceState
Device state.
Root namespace.
Non-copyable object.
Sink and source config.
Sample specifications.
Commonly used types and functions.
Sink and source config.
Definition config.h:29
Various units used in packets.