JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_AudioFormatWriter.h
Go to the documentation of this file.
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;
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 {
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
292private:
293 String formatName;
294 friend class ThreadedWriter;
295
297};
298
299} // namespace juce
A multi-channel buffer containing floating point audio samples.
Represents a set of audio channel types.
Used as a template parameter for AudioData::Pointer.
void clearSamples(int numSamples) const noexcept
Sets a number of samples to zero.
void convertSamples(Pointer source, int numSamples) const noexcept
Writes a stream of samples into this pointer from another pointer.
Reads samples from an audio file stream.
Provides a FIFO for an AudioFormatWriter, allowing you to push incoming data into a buffer which will...
Writes samples to an audio file stream.
unsigned int numChannels
The number of channels being written to the stream.
double sampleRate
The sample rate of the stream.
bool usesFloatingPointData
True if it's a floating-point format, false if it's fixed-point.
const String & getFormatName() const noexcept
Returns a description of what type of format this is.
unsigned int bitsPerSample
The bit depth of the file.
virtual bool write(const int **samplesToWrite, int numSamples)=0
Writes a set of samples to the audio stream.
int getNumChannels() const noexcept
Returns the number of channels being written.
double getSampleRate() const noexcept
Returns the sample rate being used.
bool isFloatingPoint() const noexcept
Returns true if it's a floating-point format, false if it's fixed-point.
AudioChannelSet channelLayout
The audio channel layout that the writer should use.
int getBitsPerSample() const noexcept
Returns the bit-depth of the data being written.
OutputStream * output
The output stream for use by subclasses.
Base class for objects that can produce a continuous stream of audio.
The base class for streams that write data to some kind of destination.
The JUCE String class!
Definition juce_String.h:53
A thread that keeps a list of clients, and calls each one in turn, giving them all a chance to run so...
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
This is a shorthand way of writing both a JUCE_DECLARE_NON_COPYABLE and JUCE_LEAK_DETECTOR macro for ...
JUCE Namespace.
Type * addBytesToPointer(Type *basePointer, IntegerType bytes) noexcept
A handy function which adds a number of bytes to any type of pointer and returns the result.
long long int64
A platform-independent 64-bit integer type.
write
Used by AudioFormatWriter subclasses to copy data to different formats.