OpenShot Audio Library | OpenShotAudio: juce_AudioFormatWriter.h Source File

OpenShot Audio Library | OpenShotAudio 0.3.0

Loading...
Searching...
No Matches
juce_AudioFormatWriter.h
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2017 - ROLI Ltd.
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 5 End-User License
11 Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
12 27th April 2017).
13
14 End User License Agreement: www.juce.com/juce-5-licence
15 Privacy Policy: www.juce.com/juce-5-privacy-policy
16
17 Or: You may also use this code under the terms of the GPL v3 (see
18 www.gnu.org/licenses).
19
20 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
21 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
22 DISCLAIMED.
23
24 ==============================================================================
25*/
26
27namespace juce
28{
29
30//==============================================================================
44 class JUCE_API AudioFormatWriter
45{
46protected:
47 //==============================================================================
61 AudioFormatWriter (OutputStream* destStream,
62 const String& formatName,
63 double sampleRate,
64 unsigned int numberOfChannels,
65 unsigned int bitsPerSample);
66
67 //==============================================================================
81 AudioFormatWriter (OutputStream* destStream,
82 const String& formatName,
83 double sampleRate,
84 const AudioChannelSet& audioChannelLayout,
85 unsigned int bitsPerSample);
86
87public:
89 virtual ~AudioFormatWriter();
90
91 //==============================================================================
96 const String& getFormatName() const noexcept { return formatName; }
97
98 //==============================================================================
117 virtual bool write (const int** samplesToWrite, int numSamples) = 0;
118
128 virtual bool flush();
129
130 //==============================================================================
141 bool writeFromAudioReader (AudioFormatReader& reader,
142 int64 startSample,
143 int64 numSamplesToRead);
144
154 bool writeFromAudioSource (AudioSource& source,
155 int numSamplesToRead,
156 int samplesPerBlock = 2048);
157
158
160 bool writeFromAudioSampleBuffer (const AudioBuffer<float>& source,
161 int startSample, int numSamples);
162
164 bool writeFromFloatArrays (const float* const* channels, int numChannels, int numSamples);
165
166 //==============================================================================
168 double getSampleRate() const noexcept { return sampleRate; }
169
171 int getNumChannels() const noexcept { return (int) numChannels; }
172
174 int getBitsPerSample() const noexcept { return (int) bitsPerSample; }
175
177 bool isFloatingPoint() const noexcept { return usesFloatingPointData; }
178
179 //==============================================================================
184 class ThreadedWriter
185 {
186 public:
194 ThreadedWriter (AudioFormatWriter* writer,
195 TimeSliceThread& backgroundThread,
196 int numSamplesToBuffer);
197
199 ~ThreadedWriter();
200
213 bool write (const float* const* data, int numSamples);
214
216 class JUCE_API IncomingDataReceiver
217 {
218 public:
219 IncomingDataReceiver() = default;
220 virtual ~IncomingDataReceiver() = default;
221
222 virtual void reset (int numChannels, double sampleRate, int64 totalSamplesInSource) = 0;
223 virtual void addBlock (int64 sampleNumberInSource, const AudioBuffer<float>& newData,
224 int startOffsetInBuffer, int numSamples) = 0;
225 };
226
234 void setDataReceiver (IncomingDataReceiver*);
235
239 void setFlushInterval (int numSamplesPerFlush) noexcept;
240
241 private:
242 class Buffer;
243 std::unique_ptr<Buffer> buffer;
244 };
245
246protected:
247 //==============================================================================
249 double sampleRate;
250
252 unsigned int numChannels;
253
255 unsigned int bitsPerSample;
256
258 bool usesFloatingPointData;
259
261 AudioChannelSet channelLayout;
262
264 OutputStream* output;
265
267 template <class DestSampleType, class SourceSampleType, class DestEndianness>
268 struct WriteHelper
269 {
270 using DestType = AudioData::Pointer <DestSampleType, DestEndianness, AudioData::Interleaved, AudioData::NonConst>;
271 using SourceType = AudioData::Pointer <SourceSampleType, AudioData::NativeEndian, AudioData::NonInterleaved, AudioData::Const>;
272
273 static void write (void* destData, int numDestChannels, const int* const* source,
274 int numSamples, const int sourceOffset = 0) noexcept
275 {
276 for (int i = 0; i < numDestChannels; ++i)
277 {
278 const DestType dest (addBytesToPointer (destData, i * DestType::getBytesPerSample()), numDestChannels);
279
280 if (*source != nullptr)
281 {
282 dest.convertSamples (SourceType (*source + sourceOffset), numSamples);
283 ++source;
284 }
285 else
286 {
287 dest.clearSamples (numSamples);
288 }
289 }
290 }
291 };
292
293private:
294 String formatName;
295 friend class ThreadedWriter;
296
297 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioFormatWriter)
298};
299
300} // 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:486
juce::AudioData::Pointer::convertSamples
void convertSamples(Pointer source, int numSamples) const noexcept
Definition: juce_AudioDataConverters.h:442
juce::AudioFormatReader
Definition: juce_AudioFormatReader.h:45
juce::AudioFormatWriter::ThreadedWriter::IncomingDataReceiver
Definition: juce_AudioFormatWriter.h:217
juce::AudioFormatWriter::ThreadedWriter
Definition: juce_AudioFormatWriter.h:185
juce::AudioFormatWriter
Definition: juce_AudioFormatWriter.h:45
juce::AudioFormatWriter::numChannels
unsigned int numChannels
Definition: juce_AudioFormatWriter.h:252
juce::AudioFormatWriter::sampleRate
double sampleRate
Definition: juce_AudioFormatWriter.h:249
juce::AudioFormatWriter::usesFloatingPointData
bool usesFloatingPointData
Definition: juce_AudioFormatWriter.h:258
juce::AudioFormatWriter::getFormatName
const String & getFormatName() const noexcept
Definition: juce_AudioFormatWriter.h:96
juce::AudioFormatWriter::bitsPerSample
unsigned int bitsPerSample
Definition: juce_AudioFormatWriter.h:255
juce::AudioFormatWriter::write
virtual bool write(const int **samplesToWrite, int numSamples)=0
juce::AudioFormatWriter::getNumChannels
int getNumChannels() const noexcept
Definition: juce_AudioFormatWriter.h:171
juce::AudioFormatWriter::getSampleRate
double getSampleRate() const noexcept
Definition: juce_AudioFormatWriter.h:168
juce::AudioFormatWriter::isFloatingPoint
bool isFloatingPoint() const noexcept
Definition: juce_AudioFormatWriter.h:177
juce::AudioFormatWriter::channelLayout
AudioChannelSet channelLayout
Definition: juce_AudioFormatWriter.h:261
juce::AudioFormatWriter::getBitsPerSample
int getBitsPerSample() const noexcept
Definition: juce_AudioFormatWriter.h:174
juce::AudioFormatWriter::output
OutputStream * output
Definition: juce_AudioFormatWriter.h:264
juce::AudioSource
Definition: juce_AudioSource.h:110
juce::OutputStream
Definition: juce_OutputStream.h:38
juce::String
Definition: juce_String.h:39
juce::TimeSliceThread
Definition: juce_TimeSliceThread.h:83
juce::AudioFormatWriter::WriteHelper
Definition: juce_AudioFormatWriter.h:269