Skip to content

Commit

Permalink
Revert "Speed improvements"
Browse files Browse the repository at this point in the history
This reverts commit 2cbc593.
  • Loading branch information
astorfi committed Mar 3, 2018
1 parent 3dd9b31 commit 306ae67
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
4 changes: 1 addition & 3 deletions speechpy/feature.py
@@ -1,13 +1,11 @@
from __future__ import division

import numpy as np
from . import processing
from scipy.fftpack import dct
from functools import lru_cache
import math
from . import functions


@lru_cache()
def filterbanks(num_filter, fftpoints, sampling_freq, low_freq=None, high_freq=None):
"""Compute the Mel-filterbanks. Each filter will be stored in one rows. The columns correspond to fft bins.
Expand Down
19 changes: 6 additions & 13 deletions speechpy/processing.py
@@ -1,6 +1,4 @@
import decimal
from functools import lru_cache

import numpy as np
import math

Expand All @@ -25,14 +23,6 @@ def preemphasis(signal, shift=1, cof=0.98):
rolled_signal = np.roll(signal, shift)
return signal - cof * rolled_signal


@lru_cache()
def _create_frame_indices(numframes, frame_stride, frame_sample_length):
indices = np.tile(np.arange(0, frame_sample_length), (numframes, 1)) + np.tile(
np.arange(0, numframes * frame_stride, frame_stride), (frame_sample_length, 1)).T
return np.array(indices, dtype=np.int32)


def stack_frames(sig, sampling_frequency, frame_length=0.020, frame_stride=0.020, filter=lambda x: np.ones((x,)),
zero_padding=True):
"""Frame a signal into overlapping frames.
Expand All @@ -50,13 +40,14 @@ def stack_frames(sig, sampling_frequency, frame_length=0.020, frame_stride=0.020
array: stacked_frames-Array of frames of size (number_of_frames x frame_len).
"""

## Check dimension
assert sig.ndim == 1, "Signal dimention should be of the format of (N,) but it is %s instead" % str(sig.shape)

# Initial necessary values
length_signal = sig.shape[0]
frame_sample_length = int(sampling_frequency * frame_length + 0.5) # Defined by the number of samples
frame_stride = float(int(sampling_frequency * frame_stride + 0.5))
frame_sample_length = int(np.round(sampling_frequency * frame_length)) # Defined by the number of samples
frame_stride = float(np.round(sampling_frequency * frame_stride))

# Zero padding is done for allocating space for the last frame.
if zero_padding:
Expand All @@ -78,7 +69,9 @@ def stack_frames(sig, sampling_frequency, frame_length=0.020, frame_stride=0.020
signal = sig[0:len_sig]

# Getting the indices of all frames.
indices = _create_frame_indices(numframes, frame_stride, frame_sample_length)
indices = np.tile(np.arange(0, frame_sample_length), (numframes, 1)) + np.tile(
np.arange(0, numframes * frame_stride, frame_stride), (frame_sample_length, 1)).T
indices = np.array(indices, dtype=np.int32)

# Extracting the frames based on the allocated indices.
frames = signal[indices]
Expand Down

0 comments on commit 306ae67

Please sign in to comment.