Audacity  2.2.2
Functions
LegacyBlockFile.cpp File Reference
#include "../Audacity.h"
#include "LegacyBlockFile.h"
#include <float.h>
#include <math.h>
#include <wx/filefn.h>
#include <wx/file.h>
#include <wx/ffile.h>
#include <wx/utils.h>
#include <wx/log.h>
#include "../MemoryX.h"
#include "../FileFormats.h"
#include "../Internat.h"
#include "sndfile.h"

Go to the source code of this file.

Functions

void ComputeLegacySummaryInfo (const wxFileName &fileName, size_t summaryLen, sampleFormat format, SummaryInfo *info, bool noRMS, bool Silent, float *min, float *max, float *rms)
 

Function Documentation

void ComputeLegacySummaryInfo ( const wxFileName &  fileName,
size_t  summaryLen,
sampleFormat  format,
SummaryInfo info,
bool  noRMS,
bool  Silent,
float *  min,
float *  max,
float *  rms 
)

Definition at line 39 of file LegacyBlockFile.cpp.

References SummaryInfo::bytesPerFrame, CopySamples(), SummaryInfo::fields, floatSample, SummaryInfo::format, format, SummaryInfo::frames256, SummaryInfo::frames64K, SummaryInfo::offset256, SummaryInfo::offset64K, SampleBuffer::ptr(), SAMPLE_SIZE, and SummaryInfo::totalSummaryBytes.

45 {
46  int fields = 3; /* min, max, rms */
47 
48  if (noRMS)
49  fields = 2;
50 
51  info->fields = fields;
52  info->format = format;
53  info->bytesPerFrame =
54  SAMPLE_SIZE(info->format) * fields;
55  info->totalSummaryBytes = summaryLen;
56  info->offset64K = 20; /* legacy header tag len */
57  info->frames64K = (summaryLen-20) /
58  (info->bytesPerFrame * 256);
59  info->offset256 = info->offset64K +
60  (info->frames64K * info->bytesPerFrame);
61  info->frames256 =
62  (summaryLen - 20 -
63  (info->frames64K * info->bytesPerFrame)) /
64  info->bytesPerFrame;
65 
66  //
67  // Compute the min, max, and RMS of the block from the
68  // 64K summary data
69  //
70 
71  Floats summary{ info->frames64K * fields };
72  SampleBuffer data(info->frames64K * fields,
73  info->format);
74 
75  int read;
76  {
77  Maybe<wxLogNull> silence{};
78  const wxString fullPath{ fileName.GetFullPath() };
79  wxFFile summaryFile(fullPath, wxT("rb"));
80  if (Silent)
81  silence.create();
82 
83  // FIXME: TRAP_ERR no report to user of absent summary files.
84  if (!summaryFile.IsOpened()) {
85  wxLogWarning(wxT("Unable to access summary file %s; substituting silence for remainder of session"),
86  fullPath);
87 
88  read = info->frames64K * info->bytesPerFrame;
89  memset(data.ptr(), 0, read);
90  }
91  else{
92  // FIXME: TRAP_ERR Seek in summary file could fail.
93  summaryFile.Seek(info->offset64K);
94  read = summaryFile.Read(data.ptr(),
95  info->frames64K *
96  info->bytesPerFrame);
97  }
98  }
99 
100  int count = read / info->bytesPerFrame;
101 
102  CopySamples(data.ptr(), info->format,
103  (samplePtr)summary.get(), floatSample, count);
104 
105  (*min) = FLT_MAX;
106  (*max) = FLT_MIN;
107  float sumsq = 0;
108 
109  for(int i=0; i<count; i++) {
110  if (summary[fields*i] < (*min))
111  (*min) = summary[fields*i];
112  if (summary[fields*i+1] > (*max))
113  (*max) = summary[fields*i+1];
114  if (fields >= 3)
115  sumsq += summary[fields*i+2]*summary[fields*i+2];
116  }
117  if (fields >= 3)
118  (*rms) = sqrt(sumsq / count);
119  else
120  (*rms) = 0;
121 }
int bytesPerFrame
Definition: BlockFile.h:36
sampleFormat format
Definition: BlockFile.h:35
size_t frames256
Definition: BlockFile.h:39
int offset64K
Definition: BlockFile.h:38
void CopySamples(samplePtr src, sampleFormat srcFormat, samplePtr dst, sampleFormat dstFormat, unsigned int len, bool highQuality, unsigned int srcStride, unsigned int dstStride)
#define SAMPLE_SIZE(SampleFormat)
Definition: Types.h:198
Definition: MemoryX.h:204
int format
Definition: ExportPCM.cpp:56
char * samplePtr
Definition: Types.h:203
size_t totalSummaryBytes
Definition: BlockFile.h:41
int fields
Definition: BlockFile.h:34
size_t frames64K
Definition: BlockFile.h:37
int offset256
Definition: BlockFile.h:40