Update of /cvsroot/audacity/audacity-src/src/blockfile
In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv26885/blockfile

Modified Files:
        ODDecodeBlockFile.cpp ODDecodeBlockFile.h 
        ODPCMAliasBlockFile.cpp SimpleBlockFile.cpp 
Log Message:
checking in functional but incomplete on demand import of FLAC functionality.  
This feature is not enabled now.  Saving and copy/paste does not work yet.


Index: ODPCMAliasBlockFile.cpp
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/blockfile/ODPCMAliasBlockFile.cpp,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- ODPCMAliasBlockFile.cpp     10 Sep 2009 06:20:22 -0000      1.23
+++ ODPCMAliasBlockFile.cpp     9 Oct 2009 14:28:48 -0000       1.24
@@ -432,7 +432,7 @@
       //however, this is going to be called from a non-main thread,
       //and wxLog calls are not thread safe.
       printf("Unable to write summary data to file: ");// %s",
-     printf("test..\n");
+      printf("test..\n");
       printf(" filename: %s\n",mFileNameChar);
       mFileNameMutex.Unlock();
       return;

Index: SimpleBlockFile.cpp
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/blockfile/SimpleBlockFile.cpp,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- SimpleBlockFile.cpp 8 Oct 2009 14:32:09 -0000       1.30
+++ SimpleBlockFile.cpp 9 Oct 2009 14:28:48 -0000       1.31
@@ -114,7 +114,7 @@
 
    bool useCache = GetCache() && (!bypassCache);
 
-   if (!(allowDeferredWrite && useCache))
+   if (!(allowDeferredWrite && useCache) && !bypassCache)
       WriteSimpleBlockFile(sampleData, sampleLen, format, NULL);
       
    if (useCache) {

Index: ODDecodeBlockFile.cpp
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/blockfile/ODDecodeBlockFile.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- ODDecodeBlockFile.cpp       8 Oct 2009 14:32:09 -0000       1.3
+++ ODDecodeBlockFile.cpp       9 Oct 2009 14:28:48 -0000       1.4
@@ -39,11 +39,12 @@
 
    /// Create a disk file and write summary and sample data to it
 ODDecodeBlockFile::ODDecodeBlockFile(wxFileName baseFileName,wxFileName 
audioFileName, sampleCount aliasStart,
-                     sampleCount aliasLen, int aliasChannel):
+                     sampleCount aliasLen, int aliasChannel, int decodeType):
    SimpleBlockFile(baseFileName,NULL,aliasLen,floatSample,true,true), 
//floatSample has no effect.  last two bools - bypass writing of blockfile and 
cache
 
    mAliasStart(aliasStart),
-   mAliasChannel(aliasChannel)
+   mAliasChannel(aliasChannel),
+   mType(decodeType)
 {
    mDataAvailable=false;
    mAudioFileName = audioFileName;
@@ -51,12 +52,13 @@
    
 /// Create the memory structure to refer to the given block file
 ODDecodeBlockFile::ODDecodeBlockFile(wxFileName existingFile, wxFileName 
audioFileName, sampleCount aliasStart,
-                     sampleCount aliasLen, int aliasChannel,
+                     sampleCount aliasLen, int aliasChannel, int decodeType,
                    float min, float max, float rms):
    SimpleBlockFile(existingFile,aliasLen,min,max,rms),
    
    mAliasStart(aliasStart),
-   mAliasChannel(aliasChannel)
+   mAliasChannel(aliasChannel),
+   mType(decodeType)
 {
    mDataAvailable=false;
    mAudioFileName = audioFileName;
@@ -157,7 +159,8 @@
 {
    BlockFile *newBlockFile;
    
-   
+   //mAliasedFile can change so we lock readdatamutex, which is responsible 
for it.
+   mReadDataMutex.Lock();
    if(IsSummaryAvailable())
    {
       //create a simpleblockfile, because once it has the summary it is a 
simpleblockfile for all intents an purposes
@@ -175,6 +178,7 @@
       //just this once,.
    }
    
+   mReadDataMutex.Unlock();
    
    return newBlockFile;
 }
@@ -321,29 +325,34 @@
    // derived classes) to get the sample data
    samplePtr sampleData;// = NewSamples(mLen, floatSample);
    
-   //use the decoder here.
+   //use the decoder here.   
    mDecoderMutex.Lock();
    
    if(!mDecoder)
    {
       mDecoderMutex.Unlock();
+      UnlockRead();
       return;
    }
-   mDecoder->Decode(sampleData, mFormat, mDecodeFileStart, mLen, 
mAliasChannel);
+   
+   
+   //sampleData and mFormat are set by the decoder.
+   mDecoder->Decode(sampleData, mFormat, mAliasStart, mLen, mAliasChannel);
    
    mDecoderMutex.Unlock();
-//calc summary is done in WriteSimpleBlockFile
-//   this->ReadData(sampleData, floatSample, 0, mLen);
+   
 
-//   void *summaryData = CalcSummary(sampleData, mLen, floatSample);
-  //OD TODO: use new write()                                          
-//   summaryFile.Write(summaryData, mSummaryInfo.totalSummaryBytes);
+   //the summary is also calculated here.
+   mFileNameMutex.Lock();
+   //TODO: we may need to write a version of WriteSimpleBlockFile that uses 
threadsafe FILE vs wxFile
    WriteSimpleBlockFile(
     sampleData,
     mLen,
     mFormat,
      NULL);//summaryData);
 
+   mFileNameMutex.Unlock();
+   
    DeleteSamples(sampleData);
 //   delete [] (char *) summaryData;
 
@@ -353,7 +362,28 @@
    mDataAvailableMutex.Unlock();
 }
 
+///sets the file name the summary info will be saved in.  threadsafe.
+void ODDecodeBlockFile::SetFileName(wxFileName &name)
+{
+   mFileNameMutex.Lock();
+   mFileName=name;
+/* mchinen oct 9 2009 don't think we need the char* but leaving it in for now 
just as a reminder that we might
+   if wxFileName isn't threadsafe.  
+   delete [] mFileNameChar;
+   mFileNameChar = new 
char[strlen(mFileName.GetFullPath().mb_str(wxConvUTF8))+1];
+   strcpy(mFileNameChar,mFileName.GetFullPath().mb_str(wxConvUTF8)); */
+   mFileNameMutex.Unlock();
+}
 
+///sets the file name the summary info will be saved in.  threadsafe.
+wxFileName ODDecodeBlockFile::GetFileName()
+{
+   wxFileName name;
+   mFileNameMutex.Lock();
+   name = mFileName;
+   mFileNameMutex.Unlock();
+   return name;
+}
 
 /// A thread-safe version of CalcSummary.  BlockFile::CalcSummary
 /// uses a static summary array across the class, which we can't use.
@@ -506,11 +536,16 @@
                                 sampleCount start, sampleCount len)
 {
    
+   
    if(IsSummaryAvailable())
       return SimpleBlockFile::ReadData(data,format,start,len);
    else
-      return 0; //TODO: do we need to zero out the data?  It would be more 
efficient if the client code checked
-               //ISSummaryAvailable first.
+   {
+      //we should do an ODRequest to start processing the data here, and wait 
till it finishes. and just do a SimpleBlockFIle
+      //ReadData.
+      ClearSamples(data, format, 0, len);
+      return len;
+   }
 }
 
 /// Read the summary of this alias block from disk.  Since the audio data
@@ -520,29 +555,11 @@
 ///              be at least mSummaryInfo.totalSummaryBytes long.
 bool ODDecodeBlockFile::ReadSummary(void *data)
 {
-//   wxFFile summaryFile(mFileName.GetFullPath(), wxT("rb"));
-//   wxLogNull *silence=0;
-//   
-//   if( !summaryFile.IsOpened() ){
-//
-//      // new model; we need to return valid data
-//      memset(data,0,(size_t)mSummaryInfo.totalSummaryBytes);
-//   
-//      // we silence the logging for this operation in this object
-//      // after first occurrence of error; it's already reported and
-//      // spewing at the user will complicate the user's ability to
-//      // deal
-//      mSilentLog=TRUE;
-//      return true;
-//
-//   }else mSilentLog=FALSE; // worked properly, any future error is new 
-//
-//   int read = summaryFile.Read(data, (size_t)mSummaryInfo.totalSummaryBytes);
-//
-//   FixSummary(data);
-//
-//   return (read == mSummaryInfo.totalSummaryBytes);
-return true;
+   if(IsSummaryAvailable())
+      return SimpleBlockFile::ReadSummary(data);
+   
+   memset(data, 0, (size_t)mSummaryInfo.totalSummaryBytes);
+   return true;
 }
 
 ///set the decoder,
@@ -557,3 +574,24 @@
 }
    
 
+/// Prevents a read on other threads.
+void ODDecodeBlockFile::LockRead()
+{
+   mReadDataMutex.Lock();
+}
+/// Allows reading of encoded file on other threads.
+void ODDecodeBlockFile::UnlockRead()
+{
+   mReadDataMutex.Unlock();
+}
+
+/// Modify this block to point at a different file.  This is generally
+/// looked down on, but it is necessary in one case: see
+/// DirManager::EnsureSafeFilename().
+void ODDecodeBlockFile::ChangeAudioFile(wxFileName newAudioFile)
+{
+   mAudioFileName = newAudioFile;
+}
+   
+   
+

Index: ODDecodeBlockFile.h
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/blockfile/ODDecodeBlockFile.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- ODDecodeBlockFile.h 8 Oct 2009 14:32:09 -0000       1.4
+++ ODDecodeBlockFile.h 9 Oct 2009 14:28:48 -0000       1.5
@@ -43,10 +43,10 @@
 
    /// Create a disk file and write summary and sample data to it
    ODDecodeBlockFile(wxFileName baseFileName,wxFileName audioFileName, 
sampleCount aliasStart,
-                     sampleCount aliasLen, int aliasChannel);
+                     sampleCount aliasLen, int aliasChannel, int decodeType);
    /// Create the memory structure to refer to the given block file
    ODDecodeBlockFile(wxFileName existingFile, wxFileName audioFileName, 
sampleCount aliasStart,
-                     sampleCount aliasLen, int aliasChannel,
+                     sampleCount aliasLen, int aliasChannel, int decodeType,
                    float min, float max, float rms);
 
    virtual ~ODDecodeBlockFile();   
@@ -70,6 +70,11 @@
    virtual bool Read256(float *buffer, sampleCount start, sampleCount len);
    /// Returns the 64K summary data block
    virtual bool Read64K(float *buffer, sampleCount start, sampleCount len);
+   
+   /// returns true before decoding is complete, because it is linked to the 
encoded file until then.
+   /// returns false afterwards.
+   
+   
 
    ///Makes new ODPCMAliasBlockFile or PCMAliasBlockFile depending on summary 
availability
    virtual BlockFile *Copy(wxFileName fileName);
@@ -120,14 +125,38 @@
    
    wxFileName GetAudioFileName(){return mAudioFileName;}
    
+   ///sets the file name the summary info will be saved in.  threadsafe.
+   virtual void SetFileName(wxFileName &name);
+   virtual wxFileName GetFileName();
+   
+   /// Prevents a read on other threads of the encoded audio file.
+   virtual void LockRead();
+   /// Allows reading of encoded file on other threads.
+   virtual void UnlockRead();
+   
+   ///// Get the name of the file where the audio data for this block is
+   /// stored.
+   wxFileName GetEncodedAudioFilename()
+   {
+      return mAudioFileName;
+   }
+   
+   /// Modify this block to point at a different file.  This is generally
+   /// looked down on, but it is necessary in one case: see
+   /// DirManager::EnsureSafeFilename().
+   void ChangeAudioFile(wxFileName newAudioFile);
+
   protected:
    
 //   virtual void WriteSimpleBlockFile();
    virtual void *CalcSummary(samplePtr buffer, sampleCount len,
                              sampleFormat format);
-   
+   //The on demand type.
    int mType;
    
+   ///This lock is for the filename (string) of the blockfile that contains 
summary/audio data 
+   ///after decoding
+   ODLock mFileNameMutex;
                                                                                
  
    ///The original file the audio came from.
    wxFileName mAudioFileName;
@@ -139,6 +168,8 @@
    ODFileDecoder* mDecoder;
    ODLock mDecoderMutex;
    
+   ///For accessing the audio file that will be decoded.  Used by dir manager;
+   ODLock mReadDataMutex;
    
    ///for reporting after task is complete.  Only for display use.
    sampleCount mStart;
@@ -147,7 +178,6 @@
    sampleCount mClipOffset;
    
    sampleFormat mFormat;
-   sampleCount mDecodeFileStart;
    
    sampleCount mAliasStart;//where in the encoded audio file this block 
corresponds to.
    int         mAliasChannel;//The channel number in the encoded file..


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Audacity-cvs mailing list
Audacity-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/audacity-cvs

Reply via email to