Audacity  2.2.2
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)
float Mean(float *in, size_t len)
MultiFormatReader reads raw audio files in different formats and machine endianness representations...
FormatClassT GetResultFormat()
FormatVectorT mClasses
static const size_t cSiglen
FormatClassifier classifies the sample format and endianness of raw audio files.
unsigned mResultChannels
void Div(float *in, float div, size_t len)
void ConvertSamples(void *in, float *out, FormatClassT format)
FormatClassT mResultFormat
static const size_t cNumInts
int format
Definition: ExportPCM.cpp:56
FormatClassifier(const char *filename)
std::vector< FormatClassT > FormatVectorT
void ToFloat(T *in, float *out, size_t len)
SpecPowerCalculation is a simple spectral power level meter.
MultiFormatReader::FormatT format
float Max(float *in, size_t len)
MachineEndianness::EndiannessT endian
SpecPowerCalculation mMeter
std::vector< FormatClassT >::iterator FormatVectorIt
unsigned GetResultChannels()
void Sub(float *in, float subt, size_t len)
void Abs(float *in, float *out, size_t len)
MultiFormatReader mReader
void ReadSignal(FormatClassT format, size_t stride)
ArrayOf< uint8_t > mRawBuffer