text
stringlengths 0
2.2M
|
---|
case 24: ReadHelper<AudioData::Int32, AudioData::Int24, Endianness>::read (destSamples, startOffsetInDestBuffer, numDestChannels, sourceData, numberOfChannels, numSamples); break;
|
case 32: if (floatingPointData) ReadHelper<AudioData::Float32, AudioData::Float32, Endianness>::read (destSamples, startOffsetInDestBuffer, numDestChannels, sourceData, numberOfChannels, numSamples);
|
else ReadHelper<AudioData::Int32, AudioData::Int32, Endianness>::read (destSamples, startOffsetInDestBuffer, numDestChannels, sourceData, numberOfChannels, numSamples);
|
break;
|
default: jassertfalse; break;
|
}
|
}
|
int bytesPerFrame;
|
int64 dataChunkStart;
|
bool littleEndian;
|
private:
|
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AiffAudioFormatReader)
|
};
|
//==============================================================================
|
class AiffAudioFormatWriter : public AudioFormatWriter
|
{
|
public:
|
AiffAudioFormatWriter (OutputStream* out, double rate,
|
unsigned int numChans, unsigned int bits,
|
const StringPairArray& metadataValues)
|
: AudioFormatWriter (out, aiffFormatName, rate, numChans, bits)
|
{
|
using namespace AiffFileHelpers;
|
if (metadataValues.size() > 0)
|
{
|
// The meta data should have been sanitised for the AIFF format.
|
// If it was originally sourced from a WAV file the MetaDataSource
|
// key should be removed (or set to "AIFF") once this has been done
|
jassert (metadataValues.getValue ("MetaDataSource", "None") != "WAV");
|
MarkChunk::create (markChunk, metadataValues);
|
COMTChunk::create (comtChunk, metadataValues);
|
InstChunk::create (instChunk, metadataValues);
|
}
|
headerPosition = out->getPosition();
|
writeHeader();
|
}
|
~AiffAudioFormatWriter() override
|
{
|
if ((bytesWritten & 1) != 0)
|
output->writeByte (0);
|
writeHeader();
|
}
|
//==============================================================================
|
bool write (const int** data, int numSamples) override
|
{
|
jassert (numSamples >= 0);
|
jassert (data != nullptr && *data != nullptr); // the input must contain at least one channel!
|
if (writeFailed)
|
return false;
|
auto bytes = numChannels * (size_t) numSamples * bitsPerSample / 8;
|
tempBlock.ensureSize (bytes, false);
|
switch (bitsPerSample)
|
{
|
case 8: WriteHelper<AudioData::Int8, AudioData::Int32, AudioData::BigEndian>::write (tempBlock.getData(), (int) numChannels, data, numSamples); break;
|
case 16: WriteHelper<AudioData::Int16, AudioData::Int32, AudioData::BigEndian>::write (tempBlock.getData(), (int) numChannels, data, numSamples); break;
|
case 24: WriteHelper<AudioData::Int24, AudioData::Int32, AudioData::BigEndian>::write (tempBlock.getData(), (int) numChannels, data, numSamples); break;
|
case 32: WriteHelper<AudioData::Int32, AudioData::Int32, AudioData::BigEndian>::write (tempBlock.getData(), (int) numChannels, data, numSamples); break;
|
default: jassertfalse; break;
|
}
|
if (bytesWritten + bytes >= (size_t) 0xfff00000
|
|| ! output->write (tempBlock.getData(), bytes))
|
{
|
// failed to write to disk, so let's try writing the header.
|
// If it's just run out of disk space, then if it does manage
|
// to write the header, we'll still have a useable file..
|
writeHeader();
|
writeFailed = true;
|
return false;
|
}
|
bytesWritten += bytes;
|
lengthInSamples += (uint64) numSamples;
|
return true;
|
}
|
private:
|
MemoryBlock tempBlock, markChunk, comtChunk, instChunk;
|
uint64 lengthInSamples = 0, bytesWritten = 0;
|
int64 headerPosition = 0;
|
bool writeFailed = false;
|
void writeHeader()
|
{
|
using namespace AiffFileHelpers;
|
const bool couldSeekOk = output->setPosition (headerPosition);
|
ignoreUnused (couldSeekOk);
|
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.