AudioSampleBuffer:readFromAudioReader - multichannel support


#1

it seems that readFromAudioReader only supports mono/stereo files, are there alternatives to import multichannel files, or is this just missing?


#2

I initially added it as a quick way of playing stereo files and haven’t yet added support for anything else.


#3

ok, here is a multichannel version, you may add this for people (like me) how need it


void readFromAudioReader2 (AudioSampleBuffer& destBuffer, AudioFormatReader* reader,
											 const int startSample,
											 const int numSamples,
											 const int64 readerStartSample
											 )
{
	jassert (reader != nullptr);
	jassert (startSample >= 0 && startSample + numSamples <= destBuffer.getNumSamples());

	if (numSamples > 0)
	{
				
		HeapBlock<int*> chansa(destBuffer.getNumChannels());

		for (int c=0; c<destBuffer.getNumChannels(); ++c)
		{
			chansa[c] = reinterpret_cast<int*> (destBuffer.getSampleData (c, startSample)); 
		}

		reader->read (chansa.getData(), destBuffer.getNumChannels(), readerStartSample, numSamples, true);

		if (! reader->usesFloatingPointData)
		{
			for (int j = 0; j < destBuffer.getNumChannels(); ++j)
			{
				float* const d = reinterpret_cast <float*> (chansa[j]);

				if (d != nullptr)
				{
					const float multiplier = 1.0f / 0x7fffffff;

					for (int i = 0; i < numSamples; ++i)
						d[i] = *reinterpret_cast<int*> (d + i) * multiplier;
				}
			}
		}
	}
}