Skip to content

Commit 095322b

Browse files
committed
upload project
0 parents  commit 095322b

14 files changed

+1028
-0
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
*.dSYM
2+
*.swp
3+
*.DS_Store
4+
*.o
5+
*.so
6+
*.dylib
7+
mels_a_file

5016672465406.wav

24.4 KB
Binary file not shown.

6983123609037.wav

1.14 MB
Binary file not shown.

Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
all:
3+
4+
5+
EXTRA_CXXFLAGS = -Wno-sign-compare
6+
include ../kaldi.mk
7+
OBJFILES = fft.o complex.o mels_utils.o
8+
LIBNAME = ext_mels
9+
BINFILES = mels_a_file
10+
ADDLIBS = ../feat/kaldi-feat.a ../util/kaldi-util.a ../matrix/kaldi-matrix.a ../base/kaldi-base.a
11+
12+
include ../makefiles/default_rules.mk

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#C/C++实现Python音频处理库librosa中melspectrogram的计算过程
2+
3+
4+
## 编译
5+
6+
因为有矩阵计算图省事所以依赖[kaldi](https://github.com/kaldi-asr/kaldi)
7+
先要准备好一个kaldi的编译好的环境
8+
9+
```
10+
11+
cd ${kaldi_project_path}/src
12+
git clone https://github.com/xiaominfc/melspectrogram_cpp
13+
cd melspectrogram_cpp
14+
make
15+
16+
```
17+
18+
## 测试
19+
20+
```
21+
python3 ./melspectrogram_util.py
22+
# 看到输出
23+
24+
./mels_a_file ./6983123609037.wav
25+
# 对比输出(cpp程序只输出了第一行)
26+
27+
```

complex.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// complex.cpp - impelementation of class
2+
// of complex number
3+
//
4+
// The code is property of LIBROW
5+
// You can use it on your own
6+
// When utilizing credit LIBROW site
7+
8+
// Include header file
9+
#include "complex.h"
10+
11+
// Imaginary unity constants
12+
const complex complex::i(0., 1.);
13+
const complex complex::j(0., 1.);

complex.h

Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
// complex.h - declaration of class
2+
// of complex number
3+
//
4+
// The code is property of LIBROW
5+
// You can use it on your own
6+
// When utilizing credit LIBROW site
7+
8+
#ifndef _COMPLEX_H_
9+
#define _COMPLEX_H_
10+
11+
class complex
12+
{
13+
protected:
14+
// Internal presentation - real and imaginary parts
15+
double m_re;
16+
double m_im;
17+
18+
public:
19+
// Imaginary unity
20+
static const complex i;
21+
static const complex j;
22+
23+
// Constructors
24+
complex(): m_re(0.), m_im(0.) {}
25+
complex(double re, double im): m_re(re), m_im(im) {}
26+
complex(double val): m_re(val), m_im(0.) {}
27+
28+
// Assignment
29+
complex& operator= (const double val)
30+
{
31+
m_re = val;
32+
m_im = 0.;
33+
return *this;
34+
}
35+
36+
// Basic operations - taking parts
37+
double re() const { return m_re; }
38+
double im() const { return m_im; }
39+
40+
// Conjugate number
41+
complex conjugate() const
42+
{
43+
return complex(m_re, -m_im);
44+
}
45+
46+
// Norm
47+
double norm() const
48+
{
49+
return m_re * m_re + m_im * m_im;
50+
}
51+
52+
// Arithmetic operations
53+
complex operator+ (const complex& other) const
54+
{
55+
return complex(m_re + other.m_re, m_im + other.m_im);
56+
}
57+
58+
complex operator- (const complex& other) const
59+
{
60+
return complex(m_re - other.m_re, m_im - other.m_im);
61+
}
62+
63+
complex operator* (const complex& other) const
64+
{
65+
return complex(m_re * other.m_re - m_im * other.m_im,
66+
m_re * other.m_im + m_im * other.m_re);
67+
}
68+
69+
complex operator/ (const complex& other) const
70+
{
71+
const double denominator = other.m_re * other.m_re + other.m_im * other.m_im;
72+
return complex((m_re * other.m_re + m_im * other.m_im) / denominator,
73+
(m_im * other.m_re - m_re * other.m_im) / denominator);
74+
}
75+
76+
complex& operator+= (const complex& other)
77+
{
78+
m_re += other.m_re;
79+
m_im += other.m_im;
80+
return *this;
81+
}
82+
83+
complex& operator-= (const complex& other)
84+
{
85+
m_re -= other.m_re;
86+
m_im -= other.m_im;
87+
return *this;
88+
}
89+
90+
complex& operator*= (const complex& other)
91+
{
92+
const double temp = m_re;
93+
m_re = m_re * other.m_re - m_im * other.m_im;
94+
m_im = m_im * other.m_re + temp * other.m_im;
95+
return *this;
96+
}
97+
98+
complex& operator/= (const complex& other)
99+
{
100+
const double denominator = other.m_re * other.m_re + other.m_im * other.m_im;
101+
const double temp = m_re;
102+
m_re = (m_re * other.m_re + m_im * other.m_im) / denominator;
103+
m_im = (m_im * other.m_re - temp * other.m_im) / denominator;
104+
return *this;
105+
}
106+
107+
complex& operator++ ()
108+
{
109+
++m_re;
110+
return *this;
111+
}
112+
113+
complex operator++ (int)
114+
{
115+
complex temp(*this);
116+
++m_re;
117+
return temp;
118+
}
119+
120+
complex& operator-- ()
121+
{
122+
--m_re;
123+
return *this;
124+
}
125+
126+
complex operator-- (int)
127+
{
128+
complex temp(*this);
129+
--m_re;
130+
return temp;
131+
}
132+
133+
complex operator+ (const double val) const
134+
{
135+
return complex(m_re + val, m_im);
136+
}
137+
138+
complex operator- (const double val) const
139+
{
140+
return complex(m_re - val, m_im);
141+
}
142+
143+
complex operator* (const double val) const
144+
{
145+
return complex(m_re * val, m_im * val);
146+
}
147+
148+
complex operator/ (const double val) const
149+
{
150+
return complex(m_re / val, m_im / val);
151+
}
152+
153+
complex& operator+= (const double val)
154+
{
155+
m_re += val;
156+
return *this;
157+
}
158+
159+
complex& operator-= (const double val)
160+
{
161+
m_re -= val;
162+
return *this;
163+
}
164+
165+
complex& operator*= (const double val)
166+
{
167+
m_re *= val;
168+
m_im *= val;
169+
return *this;
170+
}
171+
172+
complex& operator/= (const double val)
173+
{
174+
m_re /= val;
175+
m_im /= val;
176+
return *this;
177+
}
178+
179+
friend complex operator+ (const double left, const complex& right)
180+
{
181+
return complex(left + right.m_re, right.m_im);
182+
}
183+
184+
friend complex operator- (const double left, const complex& right)
185+
{
186+
return complex(left - right.m_re, -right.m_im);
187+
}
188+
189+
friend complex operator* (const double left, const complex& right)
190+
{
191+
return complex(left * right.m_re, left * right.m_im);
192+
}
193+
194+
friend complex operator/ (const double left, const complex& right)
195+
{
196+
const double denominator = right.m_re * right.m_re + right.m_im * right.m_im;
197+
return complex(left * right.m_re / denominator,
198+
-left * right.m_im / denominator);
199+
}
200+
201+
// Boolean operators
202+
bool operator== (const complex &other) const
203+
{
204+
return m_re == other.m_re && m_im == other.m_im;
205+
}
206+
207+
bool operator!= (const complex &other) const
208+
{
209+
return m_re != other.m_re || m_im != other.m_im;
210+
}
211+
212+
bool operator== (const double val) const
213+
{
214+
return m_re == val && m_im == 0.;
215+
}
216+
217+
bool operator!= (const double val) const
218+
{
219+
return m_re != val || m_im != 0.;
220+
}
221+
222+
friend bool operator== (const double left, const complex& right)
223+
{
224+
return left == right.m_re && right.m_im == 0.;
225+
}
226+
227+
friend bool operator!= (const double left, const complex& right)
228+
{
229+
return left != right.m_re || right.m_im != 0.;
230+
}
231+
};
232+
233+
#endif

ext_mels.a

215 KB
Binary file not shown.

0 commit comments

Comments
 (0)