Audacity  2.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 "../SampleFormat.h"
16 #include "MultiFormatReader.h"
17 #include "SpecPowerMeter.h"
18 
19 #include <sndfile.h>
20 
21 #ifndef SNDFILE_1
22 #error Requires libsndfile 1.0.3 or higher
23 #endif
24 
25 // #define FORMATCLASSIFIER_SIGNAL_DEBUG 1
26 
27 #ifdef FORMATCLASSIFIER_SIGNAL_DEBUG
28 
29 #include <cstdio>
30 
31 class DebugWriter
32 {
33  FILE* mpFid;
34 
35 public:
36  DebugWriter(const char* filename)
37  {
38  mpFid = fopen(filename, "wb");
39  }
40 
41  ~DebugWriter()
42  {
43  if (mpFid) fclose(mpFid);
44  }
45 
46  void WriteSignal(float* buffer, size_t len)
47  {
48  WriteSignal(buffer, 4, len);
49  }
50 
51  void WriteSignal(void* buffer, size_t size, size_t len)
52  {
53  fwrite(buffer, size, len, mpFid);
54  }
55 };
56 
57 #endif
58 
60 {
61 public:
62 
63  typedef struct
64  {
67  } FormatClassT;
68 
69  typedef std::vector<FormatClassT> FormatVectorT;
70  typedef std::vector<FormatClassT>::iterator FormatVectorIt;
71 
72 private:
73 
74  static const size_t cSiglen = 512;
75  static const size_t cNumInts = 32;
76 
80 
81 #ifdef FORMATCLASSIFIER_SIGNAL_DEBUG
82  std::unique_ptr<DebugWriter> mpWriter;
83 #endif
84 
88 
91 
93  unsigned mResultChannels { 0 };
94 
95 public:
96  FormatClassifier(const char* filename);
98 
99  FormatClassT GetResultFormat();
101  unsigned GetResultChannels();
102 private:
103  void Run();
104  void ReadSignal(FormatClassT format, size_t stride);
105  void ConvertSamples(void* in, float* out, FormatClassT format);
106 
107  void Add(float* in1, float* in2, size_t len);
108  void Sub(float* in, float subt, size_t len);
109  void Div(float* in, float div, size_t len);
110  void Abs(float* in, float* out, size_t len);
111  float Mean(float* in, size_t len);
112  float Max(float* in, size_t len);
113  float Max(float* in, size_t len, size_t* maxidx);
114 
115  template<class T> void ToFloat(T* in, float* out, size_t len);
116 };
117 
118 #endif
void Add(float *in1, float *in2, size_t len)
Definition: FormatClassifier.cpp:286
float Mean(float *in, size_t len)
Definition: FormatClassifier.cpp:326
MultiFormatReader reads raw audio files in different formats and machine endianness representations...
Definition: MultiFormatReader.h:49
FormatClassT GetResultFormat()
Definition: FormatClassifier.cpp:95
Floats mMonoFeat
Definition: FormatClassifier.h:89
FormatVectorT mClasses
Definition: FormatClassifier.h:77
static const size_t cSiglen
Definition: FormatClassifier.h:74
SpecPowerMeter is a simple spectral power level meter.
Definition: SpecPowerMeter.h:17
FormatClassifier classifies the sample format and endianness of raw audio files.
Definition: FormatClassifier.h:59
Floats mAuxBuffer
Definition: FormatClassifier.h:86
unsigned mResultChannels
Definition: FormatClassifier.h:93
void Div(float *in, float div, size_t len)
Definition: FormatClassifier.cpp:302
~FormatClassifier()
Definition: FormatClassifier.cpp:91
void ConvertSamples(void *in, float *out, FormatClassT format)
Definition: FormatClassifier.cpp:255
FormatClassT mResultFormat
Definition: FormatClassifier.h:92
FormatT
Definition: MultiFormatReader.h:56
static const size_t cNumInts
Definition: FormatClassifier.h:75
int format
Definition: ExportPCM.cpp:56
void Run()
Definition: FormatClassifier.cpp:147
int GetResultFormatLibSndfile()
Definition: FormatClassifier.cpp:100
FormatClassifier(const char *filename)
Definition: FormatClassifier.cpp:33
Floats mSigBuffer
Definition: FormatClassifier.h:85
std::vector< FormatClassT > FormatVectorT
Definition: FormatClassifier.h:69
Floats mStereoFeat
Definition: FormatClassifier.h:90
void ToFloat(T *in, float *out, size_t len)
Definition: FormatClassifier.cpp:363
MultiFormatReader::FormatT format
Definition: FormatClassifier.h:65
float Max(float *in, size_t len)
Definition: FormatClassifier.cpp:340
EndiannessT
Definition: MultiFormatReader.h:20
MachineEndianness::EndiannessT endian
Definition: FormatClassifier.h:66
SpecPowerMeter mMeter
Definition: FormatClassifier.h:79
std::vector< FormatClassT >::iterator FormatVectorIt
Definition: FormatClassifier.h:70
unsigned GetResultChannels()
Definition: FormatClassifier.cpp:142
Definition: FormatClassifier.h:63
void Sub(float *in, float subt, size_t len)
Definition: FormatClassifier.cpp:294
void Abs(float *in, float *out, size_t len)
Definition: FormatClassifier.cpp:311
MultiFormatReader mReader
Definition: FormatClassifier.h:78
void ReadSignal(FormatClassT format, size_t stride)
Definition: FormatClassifier.cpp:217
ArrayOf< uint8_t > mRawBuffer
Definition: FormatClassifier.h:87