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
28#include <cstdio>
29
30class DebugWriter
31{
32 FILE* mpFid;
33
34public:
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{
60public:
61
62 typedef struct
63 {
67
68 typedef std::vector<FormatClassT> FormatVectorT;
69 typedef std::vector<FormatClassT>::iterator FormatVectorIt;
70
71private:
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
94public:
95 FormatClassifier(const char* filename);
97
98 FormatClassT GetResultFormat();
100 unsigned GetResultChannels();
101private:
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
int format
Definition: ExportPCM.cpp:56
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