OpenShot Audio Library | OpenShotAudio 0.4.0

Loading...
Searching...
No Matches
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
26 namespace juce
27{
28
29//==============================================================================
43 class JUCE_API AudioFormatWriter
44{
45 protected:
46 //==============================================================================
60 AudioFormatWriter (OutputStream* destStream,
61 const String& formatName,
62 double sampleRate,
63 unsigned int numberOfChannels,
64 unsigned int bitsPerSample);
65
66 //==============================================================================
80 AudioFormatWriter (OutputStream* destStream,
81 const String& formatName,
82 double sampleRate,
83 const AudioChannelSet& audioChannelLayout,
84 unsigned int bitsPerSample);
85
86 public:
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 //==============================================================================
183 class ThreadedWriter
184 {
185 public:
193 ThreadedWriter (AudioFormatWriter* writer,
194 TimeSliceThread& backgroundThread,
195 int numSamplesToBuffer);
196
198 ~ThreadedWriter();
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
245 protected:
246 //==============================================================================
248 double sampleRate;
249
251 unsigned int numChannels;
252
254 unsigned int bitsPerSample;
255
257 bool usesFloatingPointData;
258
260 AudioChannelSet channelLayout;
261
263 OutputStream* output;
264
266 template <class DestSampleType, class SourceSampleType, class DestEndianness>
267 struct WriteHelper
268 {
269 using DestType = AudioData::Pointer <DestSampleType, DestEndianness, AudioData::Interleaved, AudioData::NonConst>;
270 using SourceType = AudioData::Pointer <SourceSampleType, AudioData::NativeEndian, AudioData::NonInterleaved, AudioData::Const>;
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
292 private:
293 String formatName;
294 friend class ThreadedWriter;
295
296 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioFormatWriter)
297};
298
299} // namespace juce
juce::AudioBuffer
Definition juce_AudioSampleBuffer.h:34
juce::AudioChannelSet
Definition juce_AudioChannelSet.h:47
juce::AudioData::Pointer
Definition juce_AudioDataConverters.h:355
juce::AudioData::Pointer::clearSamples
void clearSamples(int numSamples) const noexcept
Definition juce_AudioDataConverters.h:489
juce::AudioData::Pointer::convertSamples
void convertSamples(Pointer source, int numSamples) const noexcept
Definition juce_AudioDataConverters.h:445
juce::AudioFormatReader
Definition juce_AudioFormatReader.h:44
juce::AudioFormatWriter::ThreadedWriter::IncomingDataReceiver
Definition juce_AudioFormatWriter.h:216
juce::AudioFormatWriter::ThreadedWriter
Definition juce_AudioFormatWriter.h:184
juce::AudioFormatWriter
Definition juce_AudioFormatWriter.h:44
juce::AudioFormatWriter::numChannels
unsigned int numChannels
Definition juce_AudioFormatWriter.h:251
juce::AudioFormatWriter::sampleRate
double sampleRate
Definition juce_AudioFormatWriter.h:248
juce::AudioFormatWriter::usesFloatingPointData
bool usesFloatingPointData
Definition juce_AudioFormatWriter.h:257
juce::AudioFormatWriter::getFormatName
const String & getFormatName() const noexcept
Definition juce_AudioFormatWriter.h:95
juce::AudioFormatWriter::bitsPerSample
unsigned int bitsPerSample
Definition juce_AudioFormatWriter.h:254
juce::AudioFormatWriter::write
virtual bool write(const int **samplesToWrite, int numSamples)=0
juce::AudioFormatWriter::getNumChannels
int getNumChannels() const noexcept
Definition juce_AudioFormatWriter.h:170
juce::AudioFormatWriter::getSampleRate
double getSampleRate() const noexcept
Definition juce_AudioFormatWriter.h:167
juce::AudioFormatWriter::isFloatingPoint
bool isFloatingPoint() const noexcept
Definition juce_AudioFormatWriter.h:176
juce::AudioFormatWriter::channelLayout
AudioChannelSet channelLayout
Definition juce_AudioFormatWriter.h:260
juce::AudioFormatWriter::getBitsPerSample
int getBitsPerSample() const noexcept
Definition juce_AudioFormatWriter.h:173
juce::AudioFormatWriter::output
OutputStream * output
Definition juce_AudioFormatWriter.h:263
juce::AudioSource
Definition juce_AudioSource.h:110
juce::OutputStream
Definition juce_OutputStream.h:38
juce::String
Definition juce_String.h:53
juce::TimeSliceThread
Definition juce_TimeSliceThread.h:83
juce::AudioFormatWriter::WriteHelper
Definition juce_AudioFormatWriter.h:268