JUCE
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
AudioFormatWriter Class Referenceabstract

Writes samples to an audio file stream. More...

Classes

class  ThreadedWriter
 Provides a FIFO for an AudioFormatWriter, allowing you to push incoming data into a buffer which will be flushed to disk by a background thread. More...
 
struct  WriteHelper
 Used by AudioFormatWriter subclasses to copy data to different formats. More...
 

Public Member Functions

virtual ~AudioFormatWriter ()
 Destructor.
 
const StringgetFormatName () const noexcept
 Returns a description of what type of format this is.
 
virtual bool write (const int **samplesToWrite, int numSamples)=0
 Writes a set of samples to the audio stream.
 
bool writeFromAudioReader (AudioFormatReader &reader, int64 startSample, int64 numSamplesToRead)
 Reads a section of samples from an AudioFormatReader, and writes these to the output.
 
bool writeFromAudioSource (AudioSource &source, int numSamplesToRead, int samplesPerBlock=2048)
 Reads some samples from an AudioSource, and writes these to the output.
 
bool writeFromAudioSampleBuffer (const AudioSampleBuffer &source, int startSample, int numSamples)
 Writes some samples from an AudioSampleBuffer.
 
bool writeFromFloatArrays (const float *const *channels, int numChannels, int numSamples)
 Writes some samples from a set of float data channels.
 
double getSampleRate () const noexcept
 Returns the sample rate being used.
 
int getNumChannels () const noexcept
 Returns the number of channels being written.
 
int getBitsPerSample () const noexcept
 Returns the bit-depth of the data being written.
 
bool isFloatingPoint () const noexcept
 Returns true if it's a floating-point format, false if it's fixed-point.
 

Protected Member Functions

 AudioFormatWriter (OutputStream *destStream, const String &formatName, double sampleRate, unsigned int numberOfChannels, unsigned int bitsPerSample)
 Creates an AudioFormatWriter object.
 

Protected Attributes

double sampleRate
 The sample rate of the stream.
 
unsigned int numChannels
 The number of channels being written to the stream.
 
unsigned int bitsPerSample
 The bit depth of the file.
 
bool usesFloatingPointData
 True if it's a floating-point format, false if it's fixed-point.
 
OutputStreamoutput
 The output stream for use by subclasses.
 

Detailed Description

Writes samples to an audio file stream.

A subclass that writes a specific type of audio format will be created by an AudioFormat object.

After creating one of these with the AudioFormat::createWriterFor() method you can call its write() method to store the samples, and then delete it.

See Also
AudioFormat, AudioFormatReader

Constructor & Destructor Documentation

AudioFormatWriter::AudioFormatWriter ( OutputStream destStream,
const String formatName,
double  sampleRate,
unsigned int  numberOfChannels,
unsigned int  bitsPerSample 
)
protected

Creates an AudioFormatWriter object.

Parameters
destStreamthe stream to write to - this will be deleted by this object when it is no longer needed
formatNamethe description that will be returned by the getFormatName() method
sampleRatethe sample rate to use - the base class just stores this value, it doesn't do anything with it
numberOfChannelsthe number of channels to write - the base class just stores this value, it doesn't do anything with it
bitsPerSamplethe bit depth of the stream - the base class just stores this value, it doesn't do anything with it
virtual AudioFormatWriter::~AudioFormatWriter ( )
virtual

Destructor.

Member Function Documentation

const String& AudioFormatWriter::getFormatName ( ) const
noexcept

Returns a description of what type of format this is.

E.g. "AIFF file"

virtual bool AudioFormatWriter::write ( const int **  samplesToWrite,
int  numSamples 
)
pure virtual

Writes a set of samples to the audio stream.

Note that if you're trying to write the contents of an AudioSampleBuffer, you can use AudioSampleBuffer::writeToAudioWriter().

Parameters
samplesToWritean array of arrays containing the sample data for each channel to write. This is a zero-terminated array of arrays, and can contain a different number of channels than the actual stream uses, and the writer should do its best to cope with this. If the format is fixed-point, each channel will be formatted as an array of signed integers using the full 32-bit range -0x80000000 to 0x7fffffff, regardless of the source's bit-depth. If it is a floating-point format, you should treat the arrays as arrays of floats, and just cast it to an (int**) to pass it into the method.
numSamplesthe number of samples to write
bool AudioFormatWriter::writeFromAudioReader ( AudioFormatReader reader,
int64  startSample,
int64  numSamplesToRead 
)

Reads a section of samples from an AudioFormatReader, and writes these to the output.

This will take care of any floating-point conversion that's required to convert between the two formats. It won't deal with sample-rate conversion, though.

If numSamplesToRead < 0, it will write the entire length of the reader.

Returns
false if it can't read or write properly during the operation
bool AudioFormatWriter::writeFromAudioSource ( AudioSource source,
int  numSamplesToRead,
int  samplesPerBlock = 2048 
)

Reads some samples from an AudioSource, and writes these to the output.

The source must already have been initialised with the AudioSource::prepareToPlay() method

Parameters
sourcethe source to read from
numSamplesToReadtotal number of samples to read and write
samplesPerBlockthe maximum number of samples to fetch from the source
Returns
false if it can't read or write properly during the operation
bool AudioFormatWriter::writeFromAudioSampleBuffer ( const AudioSampleBuffer source,
int  startSample,
int  numSamples 
)

Writes some samples from an AudioSampleBuffer.

bool AudioFormatWriter::writeFromFloatArrays ( const float *const *  channels,
int  numChannels,
int  numSamples 
)

Writes some samples from a set of float data channels.

double AudioFormatWriter::getSampleRate ( ) const
noexcept

Returns the sample rate being used.

int AudioFormatWriter::getNumChannels ( ) const
noexcept

Returns the number of channels being written.

int AudioFormatWriter::getBitsPerSample ( ) const
noexcept

Returns the bit-depth of the data being written.

bool AudioFormatWriter::isFloatingPoint ( ) const
noexcept

Returns true if it's a floating-point format, false if it's fixed-point.

Member Data Documentation

double AudioFormatWriter::sampleRate
protected

The sample rate of the stream.

unsigned int AudioFormatWriter::numChannels
protected

The number of channels being written to the stream.

unsigned int AudioFormatWriter::bitsPerSample
protected

The bit depth of the file.

bool AudioFormatWriter::usesFloatingPointData
protected

True if it's a floating-point format, false if it's fixed-point.

OutputStream* AudioFormatWriter::output
protected

The output stream for use by subclasses.


The documentation for this class was generated from the following file: