21 #include "../Audacity.h"
27 #include <wx/filefn.h>
33 #include "../FileFormats.h"
34 #include "../xml/XMLTagHandler.h"
42 bool noRMS,
bool Silent,
43 float *
min,
float *max,
float *rms)
50 info->fields = fields;
54 info->totalSummaryBytes = summaryLen;
56 info->frames64K = (summaryLen-20) /
57 (info->bytesPerFrame * 256);
58 info->offset256 = info->offset64K +
59 (info->frames64K * info->bytesPerFrame);
62 (info->frames64K * info->bytesPerFrame)) /
70 Floats summary{ info->frames64K * fields };
77 const wxString fullPath{ fileName.GetFullPath() };
78 wxFFile summaryFile(fullPath, wxT(
"rb"));
83 if (!summaryFile.IsOpened()) {
84 wxLogWarning(wxT(
"Unable to access summary file %s; substituting silence for remainder of session"),
87 read = info->frames64K * info->bytesPerFrame;
88 memset(data.
ptr(), 0, read);
92 summaryFile.Seek(info->offset64K);
93 read = summaryFile.Read(data.
ptr(),
99 int count = read / info->bytesPerFrame;
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];
114 sumsq += summary[fields*i+2]*summary[fields*i+2];
117 (*rms) = sqrt(sumsq / count);
131 BlockFile{ std::move(existingFile), len },
143 summaryLen, summaryFormat,
144 &mSummaryInfo, noRMS, FALSE,
145 &mMin, &mMax, &mRMS);
159 data.
reinit( mSummaryInfo.totalSummaryBytes );
160 wxFFile summaryFile(mFileName.GetFullPath(), wxT(
"rb"));
167 if (!summaryFile.IsOpened()) {
169 memset(data.get(), 0, mSummaryInfo.totalSummaryBytes);
176 read = summaryFile.Read(data.get(), mSummaryInfo.totalSummaryBytes);
180 if (read != mSummaryInfo.totalSummaryBytes) {
181 memset(data.get(), 0, mSummaryInfo.totalSummaryBytes);
196 size_t start,
size_t len,
bool mayThrow)
const
199 return CommonReadData( mayThrow,
200 mFileName, mSilentLog,
nullptr, origin, 0, data,
format, start, len,
208 xmlFile.
StartTag(wxT(
"legacyblockfile"));
210 xmlFile.
WriteAttr(wxT(
"name"), mFileName.GetFullName());
212 if (mSummaryInfo.fields < 3)
214 xmlFile.
WriteAttr(wxT(
"summarylen"), mSummaryInfo.totalSummaryBytes);
216 xmlFile.
EndTag(wxT(
"legacyblockfile"));
227 size_t summaryLen = 0;
233 const wxChar *attr = *attrs++;
234 const wxChar *value = *attrs++;
238 const wxString strValue = value;
243 fileName.Assign(projDir, strValue);
246 if (!wxStrcmp(attr, wxT(
"len")) && (nValue >= 0))
248 else if (!wxStrcmp(attr, wxT(
"norms")))
249 noRMS = (nValue != 0);
250 else if (!wxStrcmp(attr, wxT(
"format")) && XMLValueChecker::IsValidSampleFormat(nValue))
252 else if (!wxStrcmp(attr, wxT(
"summarylen")) && (nValue > 0))
258 return make_blockfile<LegacyBlockFile>
259 (std::move(fileName),
format, summaryLen, len, noRMS);
267 return make_blockfile<LegacyBlockFile>
268 (std::move(newFileName),
269 mFormat, mSummaryInfo.totalSummaryBytes,
270 mLen, mSummaryInfo.fields < 3);
275 wxFFile dataFile(mFileName.GetFullPath());
276 return dataFile.Length();