```cpp
void STFT::stft(short*in,int length,double**out){
int i,j;
/*** Shfit & Copy***/
for (j = 0; j < channels; j++) {
for (i = 0; i < ol; i++) {
buf[j] = buf[j][i + shift_size];
}
}
// EOF
if(length!=shift_size*channels){
length = length/channels;
for (i = 0; i < length; i++) {
for (j = 0; j < channels; j++)
buf[j][i + ol]
= (double)(in[i * channels+ j]);
}
for (i = length; i < shift_size; i++) {
for (j = 0; j < channels; j++)
buf[j][i + ol] = 0;
}
//continue
}else{
for (i = 0; i < shift_size; i++) {
for (j = 0; j < channels; j++){
buf[j][i + ol]
= (double)(in[i * channels+ j]);
}
}
}
/*** Copy input -> hann_input buffer ***/
for (i = 0; i < channels; i++)
memcpy(out, buf, sizeof(double) * frame_size);
// scaling for precision
if(opt_scale)
for (i = 0; i < channels; i++)
for (j = 0; j < frame_size; j++)
out[j] /= MATLAB_scale;
/*** Window ***/
hw->Process(out, channels);
/*** FFT ***/
fft->FFT(out);
}
```
Mel滤波器构造代码如下:
```py
if fmax is None:
fmax = float(sr) / 2
# Initialize the weights
n_mels = int(n_mels)
weights = np.zeros((n_mels, int(1 + n_fft // 2)), dtype=dtype)
# Center freqs of each FFT bin
fftfreqs = fft_frequencies(sr=sr, n_fft=n_fft)
# 'Center freqs' of mel bands - uniformly spaced between limits
mel_f = mel_frequencies(n_mels + 2, fmin=fmin, fmax=fmax, htk=htk)
fdiff = np.diff(mel_f)
ramps = np.subtract.outer(mel_f, fftfreqs)
for i in range(n_mels):
# lower and upper slopes for all bins
lower = -ramps / fdiff
upper = ramps[i + 2] / fdiff[i + 1]
# .. then intersect them with each other and zero
weights = np.maximum(0, np.minimum(lower, upper))
if norm == "slaney":
# Slaney-style mel is scaled to be approx constant energy per channel
enorm = 2.0 / (mel_f[2 : n_mels + 2] - mel_f[:n_mels])
weights *= enorm[:, np.newaxis]
else:
weights = util.normalize(weights, norm=norm, axis=-1)
# Only check weights if f_mel[0] is positive
if not np.all((mel_f[:-2] == 0) | (weights.max(axis=1) > 0)):
# This means we have an empty channel somewhere
warnings.warn(
"Empty filters detected in mel frequency basis. "
"Some channels will produce empty responses. "
"Try increasing your sampling rate (and fmax) or "
"reducing n_mels.",
stacklevel=2,
)
return weights
```