Skip to content

Commit

Permalink
fix format && params
Browse files Browse the repository at this point in the history
  • Loading branch information
dengchengyun committed Nov 11, 2019
1 parent b3c7457 commit 53d93bb
Show file tree
Hide file tree
Showing 45 changed files with 792 additions and 854 deletions.
1 change: 1 addition & 0 deletions MAINTAINERS
@@ -1 +1,2 @@
Hui Zhang <zhtclz@foxmail.com>
Chengyun Deng <deng_chengyun@126.com>
12 changes: 9 additions & 3 deletions delta/data/feat/speech_feature.py
Expand Up @@ -15,11 +15,9 @@
# ==============================================================================
''' speech feat entrypoint unittest'''
import os

import numpy as np
import delta.compat as tf
from absl import logging

from delta.data.feat import speech_ops
from delta.layers.ops import py_x_ops
from delta.data.feat import python_speech_features as psf
Expand Down Expand Up @@ -86,7 +84,15 @@ def _freq_feat_graph(feat_name, **kwargs):
spec = py_x_ops.spectrum(
waveforms[:, 0],
tf.cast(sample_rate, tf.dtypes.float32),
output_type=1) #output_type: 1, power spec; 2 log power spec
window_length=0.025,
frame_length=0.010,
output_type=1,
snip_edges=1,
raw_energy=1,
preEph_coeff=0.97,
window_type='povey',
remove_dc_offset=True,
is_fbank=False) #output_type: 1, power spec; 2 log power spec
spec = tf.sqrt(spec)
# shape must be [T, D, C]
spec = tf.expand_dims(spec, -1)
Expand Down
2 changes: 0 additions & 2 deletions delta/data/feat/speech_feature_test.py
Expand Up @@ -16,12 +16,10 @@
''' speech feature entrypoint unittest'''
import os
from pathlib import Path

import librosa
import numpy as np
import delta.compat as tf
from absl import logging

from delta.data.feat import speech_ops
from delta.data.feat import speech_feature
from delta import PACKAGE_ROOT_DIR
Expand Down
2 changes: 0 additions & 2 deletions delta/data/frontend/analyfiltbank.py
Expand Up @@ -15,12 +15,10 @@
# ==============================================================================

import delta.compat as tf

from delta.layers.ops import py_x_ops
from delta.utils.hparam import HParams
from delta.data.frontend.base_frontend import BaseFrontend


class Analyfiltbank(BaseFrontend):

def __init__(self, config: dict):
Expand Down
6 changes: 3 additions & 3 deletions delta/data/frontend/fbank.py
Expand Up @@ -37,7 +37,7 @@ def params(cls, config=None):
--frame_length : Hop length in seconds. (float, default = 0.010)
--snip_edges : If 1, the last frame (shorter than window_length) will be cutoff. If 2, 1 // 2 frame_length data will be padded to data. (int, default = 1)
---raw_energy : If 1, compute frame energy before preemphasis and windowing. If 2, compute frame energy after preemphasis and windowing. (int, default = 1)
--preEph_coeff : Coefficient for use in frame-signal preemphasis. (float, default = 0.97)
--preeph_coeff : Coefficient for use in frame-signal preemphasis. (float, default = 0.97)
--window_type : Type of window ("hamm"|"hann"|"povey"|"rect"|"blac"|"tria"). (string, default = "povey")
--remove_dc_offset : Subtract mean from waveform on each frame (bool, default = true)
--is_fbank : If true, compute power spetrum without frame energy. If false, using the frame energy instead of the square of the constant component of the signal. (bool, default = true)
Expand All @@ -57,7 +57,7 @@ def params(cls, config=None):
sample_rate = 16000
snip_edges = 2
raw_energy = 1
preEph_coeff = 0.97
preeph_coeff = 0.97
window_type = 'povey'
remove_dc_offset = True
is_fbank = True
Expand All @@ -73,7 +73,7 @@ def params(cls, config=None):
hparams.add_hparam('sample_rate', sample_rate)
hparams.add_hparam('snip_edges', snip_edges)
hparams.add_hparam('raw_energy', raw_energy)
hparams.add_hparam('preEph_coeff', preEph_coeff)
hparams.add_hparam('preeph_coeff', preeph_coeff)
hparams.add_hparam('window_type', window_type)
hparams.add_hparam('remove_dc_offset', remove_dc_offset)
hparams.add_hparam('is_fbank', is_fbank)
Expand Down
6 changes: 3 additions & 3 deletions delta/data/frontend/mfcc.py
Expand Up @@ -36,7 +36,7 @@ def params(cls, config=None):
--frame_length : Hop length in seconds. (float, default = 0.010)
--snip_edges : If 1, the last frame (shorter than window_length) will be cutoff. If 2, 1 // 2 frame_length data will be padded to data. (int, default = 1)
---raw_energy : If 1, compute frame energy before preemphasis and windowing. If 2, compute frame energy after preemphasis and windowing. (int, default = 1)
--preEph_coeff : Coefficient for use in frame-signal preemphasis. (float, default = 0.97)
--preeph_coeff : Coefficient for use in frame-signal preemphasis. (float, default = 0.97)
--window_type : Type of window ("hamm"|"hann"|"povey"|"rect"|"blac"|"tria"). (string, default = "povey")
--remove_dc_offset : Subtract mean from waveform on each frame (bool, default = true)
--is_fbank : If true, compute power spetrum without frame energy. If false, using the frame energy instead of the square of the constant component of the signal. (bool, default = true)
Expand All @@ -58,7 +58,7 @@ def params(cls, config=None):
sample_rate = 16000
snip_edges = 2
raw_energy = 1
preEph_coeff = 0.97
preeph_coeff = 0.97
window_type = 'povey'
remove_dc_offset = True
is_fbank = True
Expand All @@ -75,7 +75,7 @@ def params(cls, config=None):
hparams.add_hparam('sample_rate', sample_rate)
hparams.add_hparam('snip_edges', snip_edges)
hparams.add_hparam('raw_energy', raw_energy)
hparams.add_hparam('preEph_coeff', preEph_coeff)
hparams.add_hparam('preeph_coeff', preeph_coeff)
hparams.add_hparam('window_type', window_type)
hparams.add_hparam('remove_dc_offset', remove_dc_offset)
hparams.add_hparam('is_fbank', is_fbank)
Expand Down
2 changes: 1 addition & 1 deletion delta/data/frontend/plp_test.py
Expand Up @@ -50,7 +50,7 @@ def test_plp(self):
[0.052763, -0.271487, 0.011329, 0.025320, 0.012851]])

self.assertEqual(tf.rank(plp_test).eval(), 2)
# Because the povey window (&& dithering=1.0) is used instead of the hamming window in spectrum.
# Because the povey window is used instead of the hamming window in spectrum.
self.assertAllClose(plp_test.eval()[50:55, 5:10], output_true, rtol=1e-02, atol=1e-02)

if __name__ == '__main__':
Expand Down
10 changes: 4 additions & 6 deletions delta/data/frontend/spectrum.py
Expand Up @@ -15,12 +15,10 @@
# ==============================================================================

import delta.compat as tf

from delta.layers.ops import py_x_ops
from delta.utils.hparam import HParams
from delta.data.frontend.base_frontend import BaseFrontend


class Spectrum(BaseFrontend):

def __init__(self, config: dict):
Expand All @@ -36,7 +34,7 @@ def params(cls, config=None):
--frame_length : Hop length in seconds. (float, default = 0.010)
--snip_edges : If 1, the last frame (shorter than window_length) will be cutoff. If 2, 1 // 2 frame_length data will be padded to data. (int, default = 1)
---raw_energy : If 1, compute frame energy before preemphasis and windowing. If 2, compute frame energy after preemphasis and windowing. (int, default = 1)
--preEph_coeff : Coefficient for use in frame-signal preemphasis. (float, default = 0.97)
--preeph_coeff : Coefficient for use in frame-signal preemphasis. (float, default = 0.97)
--window_type : Type of window ("hamm"|"hann"|"povey"|"rect"|"blac"|"tria"). (string, default = "povey")
--remove_dc_offset : Subtract mean from waveform on each frame (bool, default = true)
--is_fbank : If true, compute power spetrum without frame energy. If false, using the frame energy instead of the square of the constant component of the signal. (bool, default = false)
Expand All @@ -50,7 +48,7 @@ def params(cls, config=None):
sample_rate = 16000
snip_edges = 2
raw_energy = 1
preEph_coeff = 0.97
preeph_coeff = 0.97
window_type = 'povey'
remove_dc_offset = True
is_fbank = False
Expand All @@ -62,7 +60,7 @@ def params(cls, config=None):
hparams.add_hparam('sample_rate', sample_rate)
hparams.add_hparam('snip_edges', snip_edges)
hparams.add_hparam('raw_energy', raw_energy)
hparams.add_hparam('preEph_coeff', preEph_coeff)
hparams.add_hparam('preeph_coeff', preeph_coeff)
hparams.add_hparam('window_type', window_type)
hparams.add_hparam('remove_dc_offset', remove_dc_offset)
hparams.add_hparam('is_fbank', is_fbank)
Expand Down Expand Up @@ -100,7 +98,7 @@ def call(self, audio_data, sample_rate=None):
output_type=p.output_type,
snip_edges=p.snip_edges,
raw_energy=p.raw_energy,
preEph_coeff=p.preEph_coeff,
preEph_coeff=p.preeph_coeff,
window_type=p.window_type,
remove_dc_offset=p.remove_dc_offset,
is_fbank=p.is_fbank)
Expand Down
2 changes: 0 additions & 2 deletions delta/data/frontend/spectrum_test.py
Expand Up @@ -18,12 +18,10 @@
import numpy as np
from pathlib import Path
import delta.compat as tf

from delta import PACKAGE_ROOT_DIR
from delta.data.frontend.read_wav import ReadWav
from delta.data.frontend.spectrum import Spectrum


class SpectrumTest(tf.test.TestCase):

def test_spectrum(self):
Expand Down
134 changes: 63 additions & 71 deletions delta/layers/ops/kernels/add_rir_noise_aecres_1.2/BaseLib.cpp 100755 → 100644
Expand Up @@ -14,78 +14,70 @@ See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

#include <math.h>
#include "typedefs_sh.h"
#include "BaseLib.h"
#include <math.h>
#include <stddef.h>
#include "typedefs_sh.h"

void FFT(COMPLEX *pFFTData, int nFFTOrder)
{
int n, i, nv2, j, k, le, l, le1, ip, nm1;
COMPLEX t, u, w;

n = 1;
for(i = 0; i < (int)nFFTOrder; i++)
{
n = n * 2;
}

nv2 = n / 2;
nm1 = n - 1;
j = 1;

for (i = 1; i <= nm1; i ++)
{
if (i < j)
{
t.real = pFFTData[i - 1].real;
t.image = pFFTData[i - 1].image;
pFFTData[i - 1].real = pFFTData[j - 1].real;
pFFTData[i - 1].image = pFFTData[j - 1].image;
pFFTData[j - 1].real = t.real;
pFFTData[j - 1].image = t.image;
}

k = nv2;

while (k < j)
{
j -= k;
k /= 2;
}
j += k;
}

le = 1;

for (l= 1; l <= (int)nFFTOrder; l++)
{
le *= 2;
le1 = le / 2;
u.real = 1.0f;
u.image = 0.0f;
w.real = (float) cos(PI / le1);
w.image =(float) -sin(PI / le1);

for (j = 1; j <= le1; j++)
{
for (i = j; i <= n; i += le)
{
ip = i + le1;
t.real = pFFTData[ip - 1].real * u.real - pFFTData[ip - 1].image * u.image;
t.image = pFFTData[ip - 1].real * u.image + pFFTData[ip - 1].image * u.real;
pFFTData[ip - 1].real = pFFTData[i - 1].real - t.real;
pFFTData[ip - 1].image = pFFTData[i - 1].image - t.image;
pFFTData[i - 1].real = t.real + pFFTData[i - 1].real;
pFFTData[i - 1].image = t.image + pFFTData[i - 1].image;
}

t.real = u.real * w.real - u.image * w.image;
t.image = u.image * w.real + u.real * w.image;
u.real = t.real;
u.image = t.image;
}
}
void FFT(COMPLEX *pFFTData, int nFFTOrder) {
int n, i, nv2, j, k, le, l, le1, ip, nm1;
COMPLEX t, u, w;

n = 1;
for (i = 0; i < (int)nFFTOrder; i++) {
n = n * 2;
}

nv2 = n / 2;
nm1 = n - 1;
j = 1;

for (i = 1; i <= nm1; i++) {
if (i < j) {
t.real = pFFTData[i - 1].real;
t.image = pFFTData[i - 1].image;
pFFTData[i - 1].real = pFFTData[j - 1].real;
pFFTData[i - 1].image = pFFTData[j - 1].image;
pFFTData[j - 1].real = t.real;
pFFTData[j - 1].image = t.image;
}

k = nv2;

while (k < j) {
j -= k;
k /= 2;
}
j += k;
}

le = 1;

for (l = 1; l <= (int)nFFTOrder; l++) {
le *= 2;
le1 = le / 2;
u.real = 1.0f;
u.image = 0.0f;
w.real = (float)cos(PI / le1);
w.image = (float)-sin(PI / le1);

for (j = 1; j <= le1; j++) {
for (i = j; i <= n; i += le) {
ip = i + le1;
t.real =
pFFTData[ip - 1].real * u.real - pFFTData[ip - 1].image * u.image;
t.image =
pFFTData[ip - 1].real * u.image + pFFTData[ip - 1].image * u.real;
pFFTData[ip - 1].real = pFFTData[i - 1].real - t.real;
pFFTData[ip - 1].image = pFFTData[i - 1].image - t.image;
pFFTData[i - 1].real = t.real + pFFTData[i - 1].real;
pFFTData[i - 1].image = t.image + pFFTData[i - 1].image;
}

t.real = u.real * w.real - u.image * w.image;
t.image = u.image * w.real + u.real * w.image;
u.real = t.real;
u.image = t.image;
}
}
}


6 changes: 3 additions & 3 deletions delta/layers/ops/kernels/add_rir_noise_aecres_1.2/BaseLib.h 100755 → 100644
Expand Up @@ -14,10 +14,10 @@ See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

#ifndef __BASELIB_H_
#define __BASELIB_H_
#ifndef __BASELIB_H_
#define __BASELIB_H_

#include "typedefs_sh.h"
#include "typedefs_sh.h"

void FFT(COMPLEX *pFFTData, int nFFTOrder);

Expand Down
30 changes: 11 additions & 19 deletions delta/layers/ops/kernels/add_rir_noise_aecres_1.2/CAdd_All.cpp 100755 → 100644
Expand Up @@ -14,25 +14,17 @@ See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

#include "conv.h"
#include "CAdd_All.h"

CAdd_All::CAdd_All()
{
st_rir = conv_init(16000, 0);
}

CAdd_All::~CAdd_All()
{
conv_exit(st_rir);
}
#include "conv.h"

int CAdd_All::add_rir(void* st, short* inputdata, int inputdata_length,
short* outputdata, int* outputdata_size, char* filelist)
{
int ret;
ret = conv_process(st, inputdata, inputdata_length,
outputdata, outputdata_size, filelist);
return ret;
}
CAdd_All::CAdd_All() { st_rir = conv_init(16000, 0); }

CAdd_All::~CAdd_All() { conv_exit(st_rir); }

int CAdd_All::add_rir(void* st, short* inputdata, int inputdata_length,
short* outputdata, int* outputdata_size, char* filelist) {
int ret;
ret = conv_process(st, inputdata, inputdata_length, outputdata,
outputdata_size, filelist);
return ret;
}

0 comments on commit 53d93bb

Please sign in to comment.