zohann commited on
Commit
28889d1
·
verified ·
1 Parent(s): 04ae5ea

Upload Audio_Effects_SDK/samples/utils/wave_reader/wave.hpp with huggingface_hub

Browse files
Audio_Effects_SDK/samples/utils/wave_reader/wave.hpp ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright (c) 2019, NVIDIA Corporation. All rights reserved.
3
+ *
4
+ * NVIDIA Corporation and its licensors retain all intellectual property
5
+ * and proprietary rights in and to this software, related documentation
6
+ * and any modifications thereto. Any use, reproduction, disclosure or
7
+ * distribution of this software and related documentation without an express
8
+ * license agreement from NVIDIA Corporation is strictly prohibited.
9
+ */
10
+
11
+ #pragma once
12
+
13
+ #include <string>
14
+
15
+ #ifndef WAVE_FORMAT_PCM
16
+ #define WAVE_FORMAT_PCM 0x0001
17
+ #endif
18
+ #define WAVE_FORMAT_IEEE_FLOAT 0x0003
19
+ #define WAVE_FORMAT_ALAW 0x0006
20
+ #define WAVE_FORMAT_MULAW 0x0007
21
+ #define WAVE_FORMAT_EXTENSIBLE 0xFFFE
22
+
23
+ #define WAVE_WAVE 0x45564157 // 'EVAW' (little endian WAVE)
24
+ #define WAVE_RIFF 0x46464952 // 'FFIR' (little endian RIFF)
25
+ #define WAVE_FORMAT 0x20746D66 // ' tmf' (little endian fmt )
26
+ #define WAVE_DATA 0x61746164 // 'atad' (little endian data)
27
+
28
+ #define DEBUG 1
29
+
30
+ #if DEBUG
31
+ #define PRINTCONTROL(x) x;
32
+ #define WAVE_ZERO_ON_ALLOCATE 1
33
+ #else
34
+ #define PRINTCONTROL(x)
35
+ #define WAVE_ZERO_ON_ALLOCATE 0
36
+ #endif
37
+
38
+ #define MAX_CHANNELS 64
39
+
40
+ typedef struct {
41
+ int ckId;
42
+ int cksize;
43
+ int waveId;
44
+ int waveChunks;
45
+ } WaveHeader;
46
+
47
+ typedef struct {
48
+ uint16_t formatTag; /* format type */
49
+ uint16_t nChannels; /* number of channels (i.e. mono, stereo...) */
50
+ unsigned int nSamplesPerSec; /* sample rate */
51
+ unsigned int nAvgBytesPerSec; /* for buffer estimation */
52
+ uint16_t nBlockAlign; /* block size of data */
53
+ } waveFormat_basic_nopcm;
54
+
55
+ typedef struct {
56
+ uint16_t formatTag; /* format type */
57
+ uint16_t nChannels; /* number of channels (i.e. mono, stereo...) */
58
+ unsigned int nSamplesPerSec; /* sample rate */
59
+ unsigned int nAvgBytesPerSec; /* for buffer estimation */
60
+ uint16_t nBlockAlign; /* block size of data */
61
+ uint16_t wBitsPerSample; /* Number of bits per sample of mono data */
62
+ } waveFormat_basic;
63
+
64
+ typedef struct {
65
+ uint16_t wFormatTag; /* format type */
66
+ uint16_t nChannels; /* number of channels (i.e. mono, stereo...) */
67
+ unsigned int nSamplesPerSec; /* sample rate */
68
+ unsigned int nAvgBytesPerSec; /* for buffer estimation */
69
+ uint16_t nBlockAlign; /* block size of data */
70
+ uint16_t wBitsPerSample; /* Number of bits per sample of mono data */
71
+ uint16_t cbSize; /* the count in bytes of the size of */
72
+ /* extra information (after cbSize) */
73
+ } waveFormat_ext;
74
+
75
+ class Wave {
76
+ public:
77
+ Wave();
78
+ explicit Wave(std::string filename);
79
+ Wave(const Wave & argB);
80
+ ~Wave();
81
+
82
+ /* Tools for creating waves in software */
83
+ Wave(unsigned int nSamples, unsigned int nChannels, unsigned int sampleRate, unsigned int bitDepth);
84
+
85
+ // Special Constructor used for construction by extractChannel
86
+ Wave(unsigned int nSamples, unsigned int sampleRate, unsigned int bitDepth, float * singleChannel);
87
+
88
+ /* Tools for allowing waves to interact */
89
+ Wave & operator -=(const Wave & argB);
90
+ Wave & operator *=(float scale);
91
+ void operator >> (int shiftSamples);
92
+ void operator >> (float shiftSeconds);
93
+ void operator <<(int shiftSamples);
94
+ void operator <<(float shiftSeconds);
95
+
96
+ float& operator[](int sampleIndex);
97
+ float* getDataPtr(int channelIndex, int sampleIndex);
98
+
99
+ Wave extractChannel(int channelIndex);
100
+ void setChannel(int channelIndex, Wave* argB);
101
+
102
+ unsigned int getNumSamples();
103
+ unsigned int getNumChannels();
104
+ unsigned int getBitDepth();
105
+ unsigned int getSampleRate();
106
+
107
+ void writeFile(std::string filename);
108
+ int maxInt(int channelId);
109
+ int minInt(int channelId);
110
+ float maxFloat(int channelId);
111
+ float minFloat(int channelId);
112
+ void append(int numChannels, int numAppendedSamples, float ** buffers);
113
+
114
+ void normalize();
115
+
116
+ private:
117
+ unsigned int m_numChannels;
118
+ unsigned int m_sampleRate;
119
+ unsigned int m_bitDepth;
120
+ unsigned int m_numSamples;
121
+ unsigned int m_bufferAllocation;
122
+
123
+ int ** m_intData;
124
+ float ** m_floatData;
125
+
126
+ bool m_PCMIntValid;
127
+ bool m_PCMFloatValid;
128
+
129
+ bool allocateInt();
130
+ bool allocateFloat();
131
+ void reallocate();
132
+
133
+ void freeInt();
134
+ void freeFloat();
135
+
136
+ void fillFloatFromInt();
137
+ void fillIntFromFloat();
138
+ void validFloat();
139
+
140
+ void readFromFile(std::string filename);
141
+ };
142
+