/// Read the summary of this alias block from disk.  Since the audio data
/// is elsewhere, this consists of reading the entire summary file.
///
/// @param *data The buffer where the summary data will be stored.  It must
///              be at least mSummaryInfo.totalSummaryBytes long.
bool ODPCMAliasBlockFile::ReadSummary(void *data)
{
   
   mFileNameMutex.Lock();
   wxFFile summaryFile(mFileName.GetFullPath(), wxT("rb"));
   
   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;
      
      mFileNameMutex.Unlock();
      return true;

   }else mSilentLog=FALSE; // worked properly, any future error is new 

   int read = summaryFile.Read(data, (size_t)mSummaryInfo.totalSummaryBytes);

   FixSummary(data);

   
   mFileNameMutex.Unlock();
   return (read == mSummaryInfo.totalSummaryBytes);
}
Esempio n. 2
0
/// Write the summary to disk.  Derived classes must call this method
/// from their constructors for the summary to be correctly written.
/// It uses the derived class's ReadData() to retrieve the data to
/// summarize.
void AliasBlockFile::WriteSummary()
{
   // Now checked carefully in the DirManager
   //wxASSERT( !wxFileExists(FILENAME(mFileName.GetFullPath())));

   // I would much rather have this code as part of the constructor, but
   // I can't call virtual functions from the constructor.  So we just
   // need to ensure that every derived class calls this in *its* constructor
   wxFFile summaryFile(mFileName.GetFullPath(), wxT("wb"));

   if( !summaryFile.IsOpened() ){
      // Never silence the Log w.r.t write errors; they always count
      // as new errors
      wxLogError(wxT("Unable to write summary data to file %s"),
                   mFileName.GetFullPath().c_str());
      // If we can't write, there's nothing to do.
      return;
   }

   // To build the summary data, call ReadData (implemented by the
   // derived classes) to get the sample data
   samplePtr sampleData = NewSamples(mLen, floatSample);
   this->ReadData(sampleData, floatSample, 0, mLen);

   void *summaryData = BlockFile::CalcSummary(sampleData, mLen,
                                            floatSample);
   summaryFile.Write(summaryData, mSummaryInfo.totalSummaryBytes);

   DeleteSamples(sampleData);
}
Esempio n. 3
0
/// Read the summary of this alias block from disk.  Since the audio data
/// is elsewhere, this consists of reading the entire summary file.
/// Fill with zeroes and return false if data are unavailable for any reason.
///
/// @param *data The buffer where the summary data will be stored.  It must
///              be at least mSummaryInfo.totalSummaryBytes long.
bool ODPCMAliasBlockFile::ReadSummary(ArrayOf<char> &data)
{
   data.reinit( mSummaryInfo.totalSummaryBytes );

   ODLocker locker{ &mFileNameMutex };
   wxFFile summaryFile(mFileName.GetFullPath(), wxT("rb"));

   if( !summaryFile.IsOpened() ) {

      // NEW model; we need to return valid data
      memset(data.get(), 0, 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 false;
   }
   else
      mSilentLog = FALSE; // worked properly, any future error is NEW

   auto read = summaryFile.Read(data.get(), mSummaryInfo.totalSummaryBytes);

   if (read != mSummaryInfo.totalSummaryBytes) {
      memset(data.get(), 0, mSummaryInfo.totalSummaryBytes);
      return false;
   }
   
   FixSummary(data.get());

   return true;
}
Esempio n. 4
0
//Check to see if we have the file for these calls.
wxLongLong ODDecodeBlockFile::GetSpaceUsage()
{
    if(IsSummaryAvailable())
    {
        wxFFile summaryFile(mFileName.GetFullPath());
        return summaryFile.Length();
    }
    else
    {
        return 0;
    }
}
Esempio n. 5
0
void Output::countVeggies(const int gridSize, Parameters* parameters, Fire* fire)
{
    // Output summary file:

    std::ofstream summaryFile ("C:/Users/Student/Desktop/Jarro/Master/Programming/Model_results/TEST2/summaryFile.txt");
    summaryFile << "Parameter threshold = " << fire->setParamThreshold << '\n'
                     << "ROS minimum = " << fire->rMIN << '\n'
                     << "Number of patches burnt = " << fire->numberOfBurntPatches << '\n'
                     << "Amount of grid burnt = " << fire->numberOfBurntPatches / gridSize << '\n'
                     << "Number of runs used = " << fire->numberRuns << '\n'
                     << "Number of seconds consumed = " << fire->elapsed_secs;

    summaryFile.close();



//    burnt_annuals = 0;
//    burnt_perennials = 0;
//    burnt_shrubs = 0;

//    // count the burnt annuals after fire-runthrough
//    for (int i = 0; i < gridSize; i++)
//    {
//        for (int j = 0; j < gridSize; j++)
//        {
//            if (landscape -> landArray[i][j] == 5 && fire -> fireArray[i][j] == 2)
//                burnt_annuals++;
//        }
//    }

//    // count the burnt perennials after fire-runthrough
//    for (int i = 0; i < gridSize; i++)
//    {
//        for (int j = 0; j < gridSize; j++)
//        {
//            if (landscape -> landArray[i][j] == 6 && fire -> fireArray[i][j] == 2)
//                burnt_perennials++;
//        }
//    }

//    // count the burnt shrubs after fire-runthrough
//    for (int i = 0; i < gridSize; i++)
//    {
//        for (int j = 0; j < gridSize; j++)
//        {
//            if (landscape -> landArray[i][j] == 7 && fire -> fireArray[i][j] == 2)
//                burnt_shrubs++;
//        }
//    }
}
//Check to see if we have the file for these calls.
wxLongLong ODPCMAliasBlockFile::GetSpaceUsage()
{ 
   if(IsSummaryAvailable())
   {
      wxLongLong ret;
      mFileNameMutex.Lock();
      wxFFile summaryFile(mFileName.GetFullPath());
      ret= summaryFile.Length();
      mFileNameMutex.Unlock();
      return ret;
   }
   else
   {
      return 0;
   }
}
/// Write the summary to disk, using the derived ReadData() to get the data
void ODPCMAliasBlockFile::WriteSummary()
{
   
   //Below from BlockFile.cpp's method.  We need to delete the data returned by
   //CalcSummary, because it uses local info.  In the future we might do something
   //smarter and thread-dependant like a static thread context.
   wxFFile summaryFile(mFileName.GetFullPath(), wxT("wb"));

   if( !summaryFile.IsOpened() ){
      // Never silence the Log w.r.t write errors; they always count
      // as new errors
      
      //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",
                   mFileName.GetFullPath().c_str());
      // If we can't write, there's nothing to do.
      return;
   }

   // To build the summary data, call ReadData (implemented by the
   // derived classes) to get the sample data
   samplePtr sampleData = NewSamples(mLen, floatSample);
   this->ReadData(sampleData, floatSample, 0, mLen);

   void *summaryData = CalcSummary(sampleData, mLen,
                                            floatSample);
   summaryFile.Write(summaryData, mSummaryInfo.totalSummaryBytes);

   DeleteSamples(sampleData);
   delete [] summaryData;
   
   
   //above from BlockFiles.cpps method
   
   

   mSummaryAvailableMutex.Lock();
   mSummaryAvailable=true;
   mSummaryAvailableMutex.Unlock();
}
Esempio n. 8
0
/// Read the summary section of the disk file.
///
/// @param *data The buffer to write the data to.  It must be at least
/// mSummaryinfo.totalSummaryBytes long.
bool LegacyBlockFile::ReadSummary(void *data)
{
   wxFFile summaryFile(mFileName.GetFullPath(), wxT("rb"));
   int read;
   {
      Maybe<wxLogNull> silence{};
      if (mSilentLog)
         silence.create();

      if (!summaryFile.IsOpened()){

         memset(data, 0, (size_t)mSummaryInfo.totalSummaryBytes);

         mSilentLog = TRUE;

         return true;
      }

      read = summaryFile.Read(data, (size_t)mSummaryInfo.totalSummaryBytes);
   }
   mSilentLog=FALSE;

   return (read == mSummaryInfo.totalSummaryBytes);
}
Esempio n. 9
0
void ComputeLegacySummaryInfo(wxFileName fileName,
                              int summaryLen,
                              sampleFormat format,
                              SummaryInfo *info,
                              bool noRMS,bool Silent,
                              float *min, float *max, float *rms)
{
   int fields = 3; /* min, max, rms */

   if (noRMS)
      fields = 2;

   info->fields = fields;
   info->format = format;
   info->bytesPerFrame =
      SAMPLE_SIZE(info->format) * fields;
   info->totalSummaryBytes = summaryLen;
   info->offset64K = 20; /* legacy header tag len */
   info->frames64K = (summaryLen-20) /
      (info->bytesPerFrame * 256);
   info->offset256 = info->offset64K +
      (info->frames64K * info->bytesPerFrame);
   info->frames256 =
      (summaryLen - 20 -
       (info->frames64K * info->bytesPerFrame)) /
      info->bytesPerFrame;

   //
   // Compute the min, max, and RMS of the block from the
   // 64K summary data
   //

   float *summary = new float[info->frames64K * fields];
   SampleBuffer data(info->frames64K * fields,
      info->format);

   int read;
   {
      Maybe<wxLogNull> silence{};
      wxFFile summaryFile(fileName.GetFullPath(), wxT("rb"));
      if (Silent)
         silence.create();

      if (!summaryFile.IsOpened()) {
         wxLogWarning(wxT("Unable to access summary file %s; substituting silence for remainder of session"),
            fileName.GetFullPath().c_str());

         read = info->frames64K * info->bytesPerFrame;
         memset(data.ptr(), 0, read);
      }
      else{
         summaryFile.Seek(info->offset64K);
         read = summaryFile.Read(data.ptr(),
            info->frames64K *
            info->bytesPerFrame);
      }
   }

   int count = read / info->bytesPerFrame;

   CopySamples(data.ptr(), info->format,
               (samplePtr)summary, floatSample, count);

   (*min) = FLT_MAX;
   (*max) = FLT_MIN;
   float sumsq = 0;

   for(int i=0; i<count; i++) {
      if (summary[fields*i] < (*min))
         (*min) = summary[fields*i];
      if (summary[fields*i+1] > (*max))
         (*max) = summary[fields*i+1];
      if (fields >= 3)
         sumsq += summary[fields*i+2]*summary[fields*i+2];
   }
   if (fields >= 3)
      (*rms) = sqrt(sumsq / count);
   else
      (*rms) = 0;

   delete[] summary;
}
Esempio n. 10
0
wxLongLong AliasBlockFile::GetSpaceUsage()
{
   wxFFile summaryFile(mFileName.GetFullPath());
   return summaryFile.Length();
}