Debian Codegraph @

modules/lsp-runtime-lib/include/lsp-plug.in/mm/InAudioFileStream.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: 19 апр. 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_INAUDIOFILESTREAM_H_
23 #define LSP_PLUG_IN_MM_INAUDIOFILESTREAM_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/IInAudioStream.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 InAudioFileStream: public IInAudioStream
45 {
46 protected:
47 #if defined(PLATFORM_WINDOWS)
48 typedef struct WAVEFILE handle_t;
49 #elif defined(PLATFORM_MACOSX)
50 typedef void handle_t;
51 #else
52 typedef SNDFILE handle_t;
53 #endif
54
55 protected:
56 // Platform-specific parameters
57 handle_t *hHandle;
58 audio_stream_t sFormat;
59 bool bSeekable;
60
61 protected:
62 #if defined(PLATFORM_WINDOWS)
63 ssize_t read_acm_convert(void *dst, size_t nframes, size_t fmt);
64 #elif defined(PLATFORM_MACOSX)
65 static status_t decode_os_status(uint32_t code);
66 #else
67 static status_t decode_sf_error(SNDFILE *fd);
68 #endif
69
70 virtual ssize_t direct_read(void *dst, size_t nframes, size_t fmt) override;
71
72 virtual size_t select_format(size_t fmt) override;
73
74 status_t do_close();
75 static status_t close_handle(handle_t *h);
76
77 public:
78 explicit InAudioFileStream();
79 InAudioFileStream(const InAudioFileStream &) = delete;
80 InAudioFileStream(InAudioFileStream &&) = delete;
81 virtual ~InAudioFileStream() override;
82
83 InAudioFileStream & operator = (const InAudioFileStream &) = delete;
84 InAudioFileStream & operator = (InAudioFileStream &&) = delete;
85
86 public:
87 /**
88 * Open audio stream
89 * @param path path to the audio file
90 * @return status of operation
91 */
92 virtual status_t open(const char *path);
93
94 /**
95 * Open audio stream
96 * @param path path to the audio file
97 * @return status of operation
98 */
99 virtual status_t open(const LSPString *path);
100
101 /**
102 * Open audio stream
103 * @param path path to the audio file
104 * @return status of operation
105 */
106 virtual status_t open(const io::Path *path);
107
108 public:
109 virtual status_t info(mm::audio_stream_t *dst) const override;
110 virtual size_t sample_rate() const override;
111 virtual size_t channels() const override;
112 virtual wssize_t length() const override;
113 virtual size_t format() const override;
114
115 virtual status_t close() override;
116 virtual wssize_t skip(wsize_t nframes) override;
117 virtual wssize_t seek(wsize_t nframes) override;
118 };
119
120 } /* namespace mm */
121 } /* namespace lsp */
122
123 #endif /* LSP_PLUG_IN_MM_INAUDIOFILESTREAM_H_ */