Debian Codegraph @

modules/lsp-runtime-lib/include/lsp-plug.in/mm/OutAudioFileStream.h

raw
1 /*
2 * Copyright (C) 2025 Linux Studio Plugins Project <https://lsp-plug.in/>
3 * (C) 2025 Vladimir Sadovnikov <[email protected]>
4 *
5 * This file is part of lsp-runtime-lib
6 * Created on: 20 апр. 2020 г.
7 *
8 * lsp-runtime-lib is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version.
12 *
13 * lsp-runtime-lib is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with lsp-runtime-lib. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22 #ifndef LSP_PLUG_IN_MM_OUTAUDIOFILESTREAM_H_
23 #define LSP_PLUG_IN_MM_OUTAUDIOFILESTREAM_H_
24
25 #include <lsp-plug.in/runtime/version.h>
26
27 #include <lsp-plug.in/common/status.h>
28 #include <lsp-plug.in/io/Path.h>
29 #include <lsp-plug.in/mm/IOutAudioStream.h>
30 #include <lsp-plug.in/runtime/LSPString.h>
31
32 #ifdef USE_LIBSNDFILE
33 #include <sndfile.h>
34 #endif /* USE_LIBSNDFILE */
35
36 namespace lsp
37 {
38 namespace mm
39 {
40 #if defined(PLATFORM_WINDOWS)
41 struct WAVEFILE;
42 #endif /* PLATFORM_WINDOWS */
43
44 class OutAudioFileStream: public IOutAudioStream
45 {
46 protected:
47
48 #if defined(PLATFORM_WINDOWS)
49 typedef struct WAVEFILE handle_t;
50 #elif defined(PLATFORM_MACOSX)
51 typedef void handle_t;
52 #else
53 typedef SNDFILE handle_t;
54
55 #endif
56
57 protected:
58 handle_t *hHandle;
59 size_t nCodec;
60 bool bSeekable;
61
62 protected:
63 #if defined(PLATFORM_WINDOWS)
64 virtual ssize_t conv_write(const void *src, size_t nframes, size_t fmt);
65 ssize_t write_acm_convert(const void *src, size_t nframes);
66 status_t flush_handle(handle_t *hHandle, bool eof);
67 #elif defined(PLATFORM_MACOSX)
68 static status_t decode_os_status(uint32_t code);
69 static uint32_t select_file_format(size_t codec);
70 #else
71 static status_t decode_sf_error(SNDFILE *fd);
72 static bool select_sndfile_format(SF_INFO *info, audio_stream_t *fmt, size_t codec);
73 #endif
74
75 status_t flush_internal(bool eof);
76 status_t do_close();
77 static status_t close_handle(handle_t *h);
78
79 protected:
80 virtual ssize_t direct_write(const void *src, size_t nframes, size_t fmt) override;
81 virtual size_t select_format(size_t rfmt) override;
82
83 public:
84 explicit OutAudioFileStream();
85 OutAudioFileStream(const OutAudioFileStream &) = delete;
86 OutAudioFileStream(OutAudioFileStream &&) = delete;
87 virtual ~OutAudioFileStream() override;
88
89 OutAudioFileStream & operator = (const OutAudioFileStream &) = delete;
90 OutAudioFileStream & operator = (OutAudioFileStream &&) = delete;
91
92 public:
93 /**
94 * Get codec used for output file
95 * @return codec used for output file
96 */
97 inline size_t codec() const { return nCodec; }
98
99 /**
100 * Open audio stream
101 * @param path path to the audio file
102 * @return status of operation
103 */
104 virtual status_t open(const char *path, const audio_stream_t *fmt, size_t codec);
105
106 /**
107 * Open audio stream
108 * @param path path to the audio file
109 * @return status of operation
110 */
111 virtual status_t open(const LSPString *path, const audio_stream_t *fmt, size_t codec);
112
113 /**
114 * Open audio stream
115 * @param path path to the audio file
116 * @return status of operation
117 */
118 virtual status_t open(const io::Path *path, const audio_stream_t *fmt, size_t codec);
119
120 public: // IOutAudioStream
121 virtual status_t close() override;
122 virtual status_t flush() override;
123 virtual wssize_t seek(wsize_t nframes) override;
124 };
125
126 } /* namespace mm */
127 } /* namespace lsp */
128
129 #endif /* LSP_PLUG_IN_MM_OUTAUDIOFILESTREAM_H_ */