void BufferRecorderNode::writeToFile( const fs::path &filePath, SampleType sampleType ) { size_t currentWritePos = mWritePos; BufferRef copiedBuffer = getRecordedCopy(); audio::TargetFileRef target = audio::TargetFile::create( filePath, getSampleRate(), getNumChannels(), sampleType ); target->write( copiedBuffer.get(), currentWritePos ); }
BufferRef SourceFile::loadBuffer() { seek( 0 ); BufferRef result = make_shared<Buffer>( mNumFrames, getNumChannels() ); if( mConverter ) { // TODO: need BufferView's in order to reduce number of copies Buffer converterDestBuffer( mConverter->getDestMaxFramesPerBlock(), getNumChannels() ); size_t readCount = 0; while( true ) { size_t framesNeeded = min( getMaxFramesPerRead(), mFileNumFrames - readCount ); if( framesNeeded == 0 ) break; // make sourceBuffer num frames match outNumFrames so that Converter doesn't think it has more if( framesNeeded != mConverterReadBuffer.getNumFrames() ) mConverterReadBuffer.setNumFrames( framesNeeded ); size_t outNumFrames = performRead( &mConverterReadBuffer, 0, framesNeeded ); CI_ASSERT( outNumFrames == framesNeeded ); pair<size_t, size_t> count = mConverter->convert( &mConverterReadBuffer, &converterDestBuffer ); result->copyOffset( converterDestBuffer, count.second, mReadPos, 0 ); readCount += outNumFrames; mReadPos += count.second; } } else { size_t readCount = performRead( result.get(), 0, mNumFrames ); mReadPos = readCount; } return result; }