Audacity 3.2.0
FormatClassifier.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 FormatClassifier.h
6
7 Philipp Sibler
8
9**********************************************************************/
10
11#ifndef __AUDACITY_FORMATCLASSIFIER_H_
12#define __AUDACITY_FORMATCLASSIFIER_H_
13
14#include <vector>
15#include "MultiFormatReader.h"
16#include "SpecPowerMeter.h"
17
18#include <sndfile.h>
19
20#ifndef SNDFILE_1
21#error Requires libsndfile 1.0.3 or higher
22#endif
23
24// #define FORMATCLASSIFIER_SIGNAL_DEBUG 1
25
26#ifdef FORMATCLASSIFIER_SIGNAL_DEBUG
27
28class DebugWriter
29{
30 FILE* mpFid;
31
32public:
33 DebugWriter(const char* filename)
34 {
35 mpFid = fopen(filename, "wb");
36 }
37
38 ~DebugWriter()
39 {
40 if (mpFid) fclose(mpFid);
41 }
42
43 void WriteSignal(float* buffer, size_t len)
44 {
45 WriteSignal(buffer, 4, len);
46 }
47
48 void WriteSignal(void* buffer, size_t size, size_t len)
49 {
50 fwrite(buffer, size, len, mpFid);
51 }
52};
53
54#endif
55
57{
58public:
59
60 typedef struct
61 {
65
66 typedef std::vector<FormatClassT> FormatVectorT;
67 typedef std::vector<FormatClassT>::iterator FormatVectorIt;
68
69private:
70
71 static const size_t cSiglen = 512;
72 static const size_t cNumInts = 32;
73
77
78#ifdef FORMATCLASSIFIER_SIGNAL_DEBUG
79 std::unique_ptr<DebugWriter> mpWriter;
80#endif
81
85
88
90 unsigned mResultChannels { 0 };
91
92public:
93 FormatClassifier(const char* filename);
95
96 FormatClassT GetResultFormat();
98 unsigned GetResultChannels();
99private:
100 void Run();
101 void ReadSignal(FormatClassT format, size_t stride);
102 void ConvertSamples(void* in, float* out, FormatClassT format);
103
104 void Add(float* in1, float* in2, size_t len);
105 void Sub(float* in, float subt, size_t len);
106 void Div(float* in, float div, size_t len);
107 void Abs(float* in, float* out, size_t len);
108 float Mean(float* in, size_t len);
109 float Max(float* in, size_t len);
110 float Max(float* in, size_t len, size_t* maxidx);
111
112 template<class T> void ToFloat(T* in, float* out, size_t len);
113};
114
115#endif
FormatClassifier classifies the sample format and endianness of raw audio files.
std::vector< FormatClassT >::iterator FormatVectorIt
FormatClassT mResultFormat
void ToFloat(T *in, float *out, size_t len)
void Abs(float *in, float *out, size_t len)
MultiFormatReader mReader
void ConvertSamples(void *in, float *out, FormatClassT format)
void Sub(float *in, float subt, size_t len)
FormatClassT GetResultFormat()
static const size_t cNumInts
ArrayOf< uint8_t > mRawBuffer
void Div(float *in, float div, size_t len)
unsigned mResultChannels
unsigned GetResultChannels()
void Add(float *in1, float *in2, size_t len)
FormatVectorT mClasses
std::vector< FormatClassT > FormatVectorT
float Mean(float *in, size_t len)
FormatClassifier(const char *filename)
SpecPowerCalculation mMeter
static const size_t cSiglen
float Max(float *in, size_t len)
void ReadSignal(FormatClassT format, size_t stride)
MultiFormatReader reads raw audio files in different formats and machine endianness representations.
SpecPowerCalculation is a simple spectral power level meter.
MultiFormatReader::FormatT format
MachineEndianness::EndiannessT endian