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