OpenShot Audio Library | OpenShotAudio 0.4.0
juce_AudioFormatWriter.h
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
29//==============================================================================
43class JUCE_API AudioFormatWriter
44{
45protected:
46 //==============================================================================
61 const String& formatName,
62 double sampleRate,
63 unsigned int numberOfChannels,
64 unsigned int bitsPerSample);
65
66 //==============================================================================
81 const String& formatName,
82 double sampleRate,
83 const AudioChannelSet& audioChannelLayout,
84 unsigned int bitsPerSample);
85
86public:
88 virtual ~AudioFormatWriter();
89
90 //==============================================================================
95 const String& getFormatName() const noexcept { return formatName; }
96
97 //==============================================================================
116 virtual bool write (const int** samplesToWrite, int numSamples) = 0;
117
127 virtual bool flush();
128
129 //==============================================================================
140 bool writeFromAudioReader (AudioFormatReader& reader,
141 int64 startSample,
142 int64 numSamplesToRead);
143
153 bool writeFromAudioSource (AudioSource& source,
154 int numSamplesToRead,
155 int samplesPerBlock = 2048);
156
157
159 bool writeFromAudioSampleBuffer (const AudioBuffer<float>& source,
160 int startSample, int numSamples);
161
163 bool writeFromFloatArrays (const float* const* channels, int numChannels, int numSamples);
164
165 //==============================================================================
167 double getSampleRate() const noexcept { return sampleRate; }
168
170 int getNumChannels() const noexcept { return (int) numChannels; }
171
173 int getBitsPerSample() const noexcept { return (int) bitsPerSample; }
174
176 bool isFloatingPoint() const noexcept { return usesFloatingPointData; }
177
178 //==============================================================================
184 {
185 public:
194 TimeSliceThread& backgroundThread,
195 int numSamplesToBuffer);
196
199
212 bool write (const float* const* data, int numSamples);
213
215 class JUCE_API IncomingDataReceiver
216 {
217 public:
218 IncomingDataReceiver() = default;
219 virtual ~IncomingDataReceiver() = default;
220
221 virtual void reset (int numChannels, double sampleRate, int64 totalSamplesInSource) = 0;
222 virtual void addBlock (int64 sampleNumberInSource, const AudioBuffer<float>& newData,
223 int startOffsetInBuffer, int numSamples) = 0;
224 };
225
233 void setDataReceiver (IncomingDataReceiver*);
234
238 void setFlushInterval (int numSamplesPerFlush) noexcept;
239
240 private:
241 class Buffer;
242 std::unique_ptr<Buffer> buffer;
243 };
244
245protected:
246 //==============================================================================
249
251 unsigned int numChannels;
252
254 unsigned int bitsPerSample;
255
258
261
264
266 template <class DestSampleType, class SourceSampleType, class DestEndianness>
268 {
271
272 static void write (void* destData, int numDestChannels, const int* const* source,
273 int numSamples, const int sourceOffset = 0) noexcept
274 {
275 for (int i = 0; i < numDestChannels; ++i)
276 {
277 const DestType dest (addBytesToPointer (destData, i * DestType::getBytesPerSample()), numDestChannels);
278
279 if (*source != nullptr)
280 {
281 dest.convertSamples (SourceType (*source + sourceOffset), numSamples);
282 ++source;
283 }
284 else
285 {
286 dest.clearSamples (numSamples);
287 }
288 }
289 }
290 };
291
292private:
293 String formatName;
294 friend class ThreadedWriter;
295
296 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioFormatWriter)
297};
298
299} // namespace juce
void clearSamples(int numSamples) const noexcept
void convertSamples(Pointer source, int numSamples) const noexcept
const String & getFormatName() const noexcept
virtual bool write(const int **samplesToWrite, int numSamples)=0
int getNumChannels() const noexcept
double getSampleRate() const noexcept
bool isFloatingPoint() const noexcept
int getBitsPerSample() const noexcept