Audacity  3.0.3
Classes | Functions
LegacyBlockFile.h File Reference
#include "../BlockFile.h"
Include dependency graph for LegacyBlockFile.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  LegacyBlockFile
 Audacity 1.1.0 block file format: More...
 

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

◆ ComputeLegacySummaryInfo()

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 38 of file LegacyBlockFile.cpp.

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

References CopySamples(), floatSample, format, min(), SampleBuffer::ptr(), and SAMPLE_SIZE.

Here is the call graph for this function:
Optional
Like a smart pointer, allows for object to not exist (nullptr)
Definition: MemoryX.h:144
SAMPLE_SIZE
#define SAMPLE_SIZE(SampleFormat)
Definition: SampleFormat.h:44
floatSample
@ floatSample
Definition: SampleFormat.h:34
CopySamples
void CopySamples(constSamplePtr src, sampleFormat srcFormat, samplePtr dst, sampleFormat dstFormat, size_t len, DitherType ditherType, unsigned int srcStride, unsigned int dstStride)
Copy samples from any format to any other format; apply dithering only if narrowing the format.
Definition: SampleFormat.cpp:111
format
int format
Definition: ExportPCM.cpp:56
SampleBuffer
Definition: SampleFormat.h:69
samplePtr
char * samplePtr
Definition: SampleFormat.h:49
min
int min(int a, int b)
Definition: CompareAudioCommand.cpp:106
ArrayOf< float >