/// Constructs a SimpleBlockFile based on sample data and writes /// it to disk. /// /// @param baseFileName The filename to use, but without an extension. /// This constructor will add the appropriate /// extension (.au in this case). /// @param sampleData The sample data to be written to this block. /// @param sampleLen The number of samples to be written to this block. /// @param format The format of the given samples. /// @param allowDeferredWrite Allow deferred write-caching SimpleBlockFile::SimpleBlockFile(wxFileName baseFileName, samplePtr sampleData, sampleCount sampleLen, sampleFormat format, bool allowDeferredWrite /* = false */): BlockFile(wxFileName(baseFileName.GetFullPath() + wxT(".au")), sampleLen) { mCache.active = false; DEBUG_OUTPUT("SimpleBlockFile created based on sample data"); bool useCache = GetCache(); if (!(allowDeferredWrite && useCache)) WriteSimpleBlockFile(sampleData, sampleLen, format, NULL); if (useCache) { DEBUG_OUTPUT("Caching block file data"); mCache.active = true; mCache.needWrite = true; mCache.format = format; mCache.sampleData = new char[sampleLen * SAMPLE_SIZE(format)]; memcpy(mCache.sampleData, sampleData, sampleLen * SAMPLE_SIZE(format)); void* summaryData = BlockFile::CalcSummary(sampleData, sampleLen, format); mCache.summaryData = new char[mSummaryInfo.totalSummaryBytes]; memcpy(mCache.summaryData, summaryData, (size_t)mSummaryInfo.totalSummaryBytes); } }
/// Constructs a SimpleBlockFile based on sample data and writes /// it to disk. /// /// @param baseFileName The filename to use, but without an extension. /// This constructor will add the appropriate /// extension (.au in this case). /// @param sampleData The sample data to be written to this block. /// @param sampleLen The number of samples to be written to this block. /// @param format The format of the given samples. /// @param allowDeferredWrite Allow deferred write-caching SimpleBlockFile::SimpleBlockFile(wxFileName baseFileName, samplePtr sampleData, sampleCount sampleLen, sampleFormat format, bool allowDeferredWrite /* = false */, bool bypassCache /* = false */): BlockFile(wxFileName(baseFileName.GetFullPath() + wxT(".au")), sampleLen) { mCache.active = false; bool useCache = GetCache() && (!bypassCache); if (!(allowDeferredWrite && useCache) && !bypassCache) { bool bSuccess = WriteSimpleBlockFile(sampleData, sampleLen, format, NULL); wxASSERT(bSuccess); // TODO: Handle failure here by alert to user and undo partial op. } if (useCache) { //wxLogDebug("SimpleBlockFile::SimpleBlockFile(): Caching block file data."); mCache.active = true; mCache.needWrite = true; mCache.format = format; mCache.sampleData = new char[sampleLen * SAMPLE_SIZE(format)]; memcpy(mCache.sampleData, sampleData, sampleLen * SAMPLE_SIZE(format)); void* summaryData = BlockFile::CalcSummary(sampleData, sampleLen, format); mCache.summaryData = new char[mSummaryInfo.totalSummaryBytes]; memcpy(mCache.summaryData, summaryData, (size_t)mSummaryInfo.totalSummaryBytes); } }
/// Write the summary to disk, using the derived ReadData() to get the data /// Here, the decoder ODTask associated with this file must fetch the samples with /// the ODDecodeTask::Decode() method. int ODDecodeBlockFile::WriteODDecodeBlockFile() { // To build the summary data, call ReadData (implemented by the // derived classes) to get the sample data samplePtr sampleData;// = NewSamples(mLen, floatSample); int ret; //use the decoder here. mDecoderMutex.Lock(); if(!mDecoder) { mDecoderMutex.Unlock(); return -1; } //sampleData and mFormat are set by the decoder. ret = mDecoder->Decode(sampleData, mFormat, mAliasStart, mLen, mAliasChannel); mDecoderMutex.Unlock(); if(ret < 0) { printf("ODDecodeBlockFile Decode failure\n"); return ret; //failure } //the summary is also calculated here. mFileNameMutex.Lock(); //TODO: we may need to write a version of WriteSimpleBlockFile that uses threadsafe FILE vs wxFile bool bSuccess = WriteSimpleBlockFile( sampleData, mLen, mFormat, NULL);//summaryData); wxASSERT(bSuccess); // TODO: Handle failure here by alert to user and undo partial op. mFileNameMutex.Unlock(); DeleteSamples(sampleData); // delete [] (char *) summaryData; mDataAvailableMutex.Lock(); mDataAvailable=true; mDataAvailableMutex.Unlock(); return ret; }
/// Write the summary to disk, using the derived ReadData() to get the data /// Here, the decoder ODTask associated with this file must fetch the samples with /// the ODDecodeTask::Decode() method. int ODDecodeBlockFile::WriteODDecodeBlockFile() { // To build the summary data, call ReadData (implemented by the // derived classes) to get the sample data SampleBuffer sampleData;// = NewSamples(mLen, floatSample); int ret; { //use the decoder here. ODLocker locker{ &mDecoderMutex }; if(!mDecoder) return -1; //sampleData and mFormat are set by the decoder. ret = mDecoder->Decode(sampleData, mFormat, mAliasStart, mLen, mAliasChannel); if(ret < 0) { wxPrintf("ODDecodeBlockFile Decode failure\n"); return ret; //failure } } { //the summary is also calculated here. ODLocker locker{ &mFileNameMutex }; //TODO: we may need to write a version of WriteSimpleBlockFile that uses threadsafe FILE vs wxFile bool bSuccess = WriteSimpleBlockFile( sampleData.ptr(), mLen, mFormat, NULL); if ( !bSuccess ) return -1; } wxAtomicInc( mDataAvailable ); return ret; }
/// Write the summary to disk, using the derived ReadData() to get the data /// Here, the decoder ODTask associated with this file must fetch the samples with /// the ODDecodeTask::Decode() method. void ODDecodeBlockFile::WriteODDecodeBlockFile() { // To build the summary data, call ReadData (implemented by the // derived classes) to get the sample data samplePtr sampleData = NewSamples(mLen, floatSample); //use the decoder here. mDecoderMutex.Lock(); if(!mDecoder) { mDecoderMutex.Unlock(); return; } mDecoder->Decode(sampleData, mFormat, mDecodeFileStart, mLen); mDecoderMutex.Unlock(); this->ReadData(sampleData, floatSample, 0, mLen); void *summaryData = CalcSummary(sampleData, mLen, floatSample); //OD TODO: use new write() // summaryFile.Write(summaryData, mSummaryInfo.totalSummaryBytes); WriteSimpleBlockFile( sampleData, mLen, mFormat, summaryData); DeleteSamples(sampleData); delete [] (char *) summaryData; mDataAvailableMutex.Lock(); mDataAvailable=true; mDataAvailableMutex.Unlock(); }