text
stringlengths
0
2.2M
// if this fails, you've given it an output stream that can't seek! It needs
// to be able to seek back to write the header
jassert (couldSeekOk);
auto headerLen = (int) (54 + (markChunk.isEmpty() ? 0 : markChunk.getSize() + 8)
+ (comtChunk.isEmpty() ? 0 : comtChunk.getSize() + 8)
+ (instChunk.isEmpty() ? 0 : instChunk.getSize() + 8));
auto audioBytes = (int) (lengthInSamples * ((bitsPerSample * numChannels) / 8));
audioBytes += (audioBytes & 1);
output->writeInt (chunkName ("FORM"));
output->writeIntBigEndian (headerLen + audioBytes - 8);
output->writeInt (chunkName ("AIFF"));
output->writeInt (chunkName ("COMM"));
output->writeIntBigEndian (18);
output->writeShortBigEndian ((short) numChannels);
output->writeIntBigEndian ((int) lengthInSamples);
output->writeShortBigEndian ((short) bitsPerSample);
uint8 sampleRateBytes[10] = {};
if (sampleRate <= 1)
{
sampleRateBytes[0] = 0x3f;
sampleRateBytes[1] = 0xff;
sampleRateBytes[2] = 0x80;
}
else
{
int mask = 0x40000000;
sampleRateBytes[0] = 0x40;
if (sampleRate >= mask)
{
jassertfalse;
sampleRateBytes[1] = 0x1d;
}
else
{
int n = (int) sampleRate;
int i;
for (i = 0; i <= 32 ; ++i)
{
if ((n & mask) != 0)
break;
mask >>= 1;
}
n = n << (i + 1);
sampleRateBytes[1] = (uint8) (29 - i);
sampleRateBytes[2] = (uint8) ((n >> 24) & 0xff);
sampleRateBytes[3] = (uint8) ((n >> 16) & 0xff);
sampleRateBytes[4] = (uint8) ((n >> 8) & 0xff);
sampleRateBytes[5] = (uint8) (n & 0xff);
}
}
output->write (sampleRateBytes, 10);
if (! markChunk.isEmpty())
{
output->writeInt (chunkName ("MARK"));
output->writeIntBigEndian ((int) markChunk.getSize());
*output << markChunk;
}
if (! comtChunk.isEmpty())
{
output->writeInt (chunkName ("COMT"));
output->writeIntBigEndian ((int) comtChunk.getSize());
*output << comtChunk;
}
if (! instChunk.isEmpty())
{
output->writeInt (chunkName ("INST"));
output->writeIntBigEndian ((int) instChunk.getSize());
*output << instChunk;
}
output->writeInt (chunkName ("SSND"));
output->writeIntBigEndian (audioBytes + 8);
output->writeInt (0);
output->writeInt (0);
jassert (output->getPosition() == headerLen);
}
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AiffAudioFormatWriter)
};
//==============================================================================
class MemoryMappedAiffReader : public MemoryMappedAudioFormatReader
{
public:
MemoryMappedAiffReader (const File& f, const AiffAudioFormatReader& reader)