Exemplo n.º 1
0
/*
bool BufferedAudioSource::init(float* interleavedData, Int64 numSamples)
{
    return true;
}
*/
bool BufferedAudioSource::init(const RString& path, bool loadIntoMemory)
{
	if(loadIntoMemory)
	{
		RPRINT("loading sound into memory...\n");
        int channels = getNumChannels();
        double length = getLength();
		double srate = getSampleRate();
		UInt32 totalFrames = getSampleRate() * getLength();
		mBuffer.resize(getNumChannels(), totalFrames);
		float *pWritePos = mBuffer.getData();
		UInt32 numFrames = (UInt32)(getSampleRate());
		UInt32 framesRead = 0;
		UInt32 remainingFrames = totalFrames;
		UInt32 tf = 0;
		do
		{
            int version = 0;
			framesRead = decodeData(pWritePos, remainingFrames >= numFrames ? numFrames : remainingFrames, version);
			pWritePos += framesRead * getNumChannels();
			tf += framesRead;
			remainingFrames -= framesRead;
		}
		while(remainingFrames > 0 && framesRead > 0);
		mEOF = true;
		mLoadedInMemory = loadIntoMemory;
		mBuffer.resize(getNumChannels(), tf);
	}
	else
	{
		mBuffer = RAudioBuffer(getNumChannels(), 0);
	}

	return true;
}
Exemplo n.º 2
0
bool BufferedAudioSource::init(const RString& path, bool loadIntoMemory) 
{ 
	if(loadIntoMemory)
	{
		//RPRINT("loading sound into memory...\n");
        int channels = getNumChannels();
        double length = getLength();
		mBuffer.resize(getNumChannels(), getSampleRate() * getLength());
		float *pWritePos = mBuffer.getData();
		UInt32 numFrames = (UInt32)(getSampleRate());
		UInt32 framesRead = 0;
		do
		{
			framesRead = decodeData(pWritePos, numFrames);
			pWritePos += framesRead * getNumChannels();
		}
		while(framesRead > 0);
		mLoadedInMemory = loadIntoMemory; 
		doneDecoding();
	}
	else
	{
        RScopedLock l(&mLock);
		mBuffer = RAudioBuffer(getNumChannels(), getSampleRate() * SECONDS_TO_BUFFER);
		BufferedAudioSourceThread::getInstance()->addSource(this);
	}

	return true;
}