Skip to content

Commit

Permalink
import submodules
Browse files Browse the repository at this point in the history
  • Loading branch information
cnheider committed Oct 3, 2022
1 parent 60fc81e commit bc9350f
Show file tree
Hide file tree
Showing 25 changed files with 309 additions and 217 deletions.
1 change: 1 addition & 0 deletions modulation/classification/architecture/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
"""

from .m5 import *
from .cepstral_a import *
3 changes: 3 additions & 0 deletions modulation/classification/metrics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@
Created on 13-01-2021
"""


from .lwlrap import *
2 changes: 2 additions & 0 deletions modulation/classification/seperation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
Created on 18-12-2020
"""

from .audio_unet import *
8 changes: 6 additions & 2 deletions modulation/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
# -*- coding: utf-8 -*-

__author__ = "Christian Heider Nielsen"
__doc__ = """ description """
__doc__ = r"""
from modulation.data.audio.speech import *
Created on 04-05-2021
"""

from .audio import *
from .signal_generator import *
10 changes: 10 additions & 0 deletions modulation/data/audio/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

__author__ = "Christian Heider Nielsen"
__doc__ = r"""
Created on 04-05-2021
"""

from .speech import *
11 changes: 11 additions & 0 deletions modulation/data/audio/speech/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

__author__ = "Christian Heider Nielsen"
__doc__ = r"""
Created on 04-05-2021
"""

from .seperation import *
from .recognition import *
8 changes: 7 additions & 1 deletion modulation/data/audio/speech/recognition/libri_speech.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@
from enum import Enum
from pathlib import Path

from draugr import FilterModeEnum, symbol_filter
from draugr.numpy_utilities import SplitEnum, SplitIndexer
from torchaudio.datasets import LIBRISPEECH
from warg import FilterModeEnum, symbol_filter


class LibriSpeech(LIBRISPEECH):
"""description"""

class LibriSpeechSubsets(Enum):
'''
'''
dev_clean = "dev-clean"
dev_other = "dev-other"
test_clean = "test-clean"
Expand All @@ -29,6 +32,9 @@ class LibriSpeechSubsets(Enum):
train_other_500 = "train-other-500"

class CustomSubsets(Enum):
'''
'''
male = "M"
female = "F"
# TODO: add more like Splits ...
Expand Down
2 changes: 2 additions & 0 deletions modulation/data/audio/speech/seperation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
Created on 04-05-2021
"""

from .dsd100 import *
151 changes: 76 additions & 75 deletions modulation/data/signal_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,96 +16,97 @@
__all__ = ["SignalGenerator", "multifreq", "triangle", "sawtooth"]


def multifreq(x) -> numpy.ndarray:
return (
2
+ numpy.sin(x * numpy.pi)
+ 0.5 * numpy.sin(2 * x * numpy.pi)
- 0.2 * numpy.cos(5 * x * numpy.pi)
)


def triangle(x, section_length=0.5) -> numpy.ndarray:

section0 = x < section_length
section1 = (x >= section_length) & (x < 2 * section_length)
section2 = (x >= 2 * section_length) & (x < 3 * section_length)
section3 = x >= 3 * section_length
output = numpy.zeros_like(x)
output[section0] = x[section0]
output[section1] = 2 * section_length - x[section1]
output[section2] = x[section2] - 2 * section_length
output[section3] = 4 * section_length - x[section3]
return output


def sawtooth(x, section_length=0.5) -> numpy.ndarray:

section0 = x < section_length
section1 = (x >= section_length) & (x < 2 * section_length)
section2 = (x >= 2 * section_length) & (x < 3 * section_length)
section3 = x >= 3 * section_length
output = numpy.zeros_like(x)
output[section0] = x[section0]
output[section1] = x[section1] - section_length
output[section2] = x[section2] - 2 * section_length
output[section3] = x[section3] - 3 * section_length
return output
def multifreq(x: numpy.ndarray) -> numpy.ndarray:
return (
2
+ numpy.sin(x * numpy.pi)
+ 0.5 * numpy.sin(2 * x * numpy.pi)
- 0.2 * numpy.cos(5 * x * numpy.pi)
)


def triangle(x: numpy.ndarray, section_length: float = 0.5) -> numpy.ndarray:

section0 = x < section_length
section1 = (x >= section_length) & (x < 2 * section_length)
section2 = (x >= 2 * section_length) & (x < 3 * section_length)
section3 = x >= 3 * section_length
output = numpy.zeros_like(x)
output[section0] = x[section0]
output[section1] = 2 * section_length - x[section1]
output[section2] = x[section2] - 2 * section_length
output[section3] = 4 * section_length - x[section3]
return output


def sawtooth(x: numpy.ndarray, section_length: float = 0.5) -> numpy.ndarray:

section0 = x < section_length
section1 = (x >= section_length) & (x < 2 * section_length)
section2 = (x >= 2 * section_length) & (x < 3 * section_length)
section3 = x >= 3 * section_length
output = numpy.zeros_like(x)
output[section0] = x[section0]
output[section1] = x[section1] - section_length
output[section2] = x[section2] - 2 * section_length
output[section3] = x[section3] - 3 * section_length
return output


class SignalGenerator:
"""description"""
"""description"""

def __init__(self, *funcs: Union[Callable, Number], delta_time: float = 1.0):
self.reset_internal_time()
self.delta_time = delta_time
self.funcs = (0, *funcs)
def __init__(self, *funcs: Union[Callable, Number], delta_time: float = 1.0):
self.reset_internal_time()
self.delta_time = delta_time
self.funcs = (0, *funcs)

def __iter__(self):
self.reset_internal_time()
return self
def __iter__(self):
self.reset_internal_time()
return self

def __next__(self):
self.t += self.delta_time
return self.apply(self.t)
def __next__(self):
self.t += self.delta_time
return self.apply(self.t)

def apply(self, t: float) -> float:
"""
def apply(self, t: float) -> float:
"""
:param t:
:type t:
:return:
:rtype:
"""
return reduce(lambda x, y: x + y(t), self.funcs)
:param t:
:type t:
:return:
:rtype:
"""
return reduce(lambda x, y: x + y(t), self.funcs)

def __call__(self, t: Iterable[Number]) -> Sequence:
return [self.apply(i) for i in t]
def __call__(self, t: Iterable[Number]) -> Sequence:
return [self.apply(i) for i in t]

def reset_internal_time(self):
"""description"""
self.t = 0.0
def reset_internal_time(self):
"""description"""
self.t = 0.0

def set_internal_time(self, t):
"""
def set_internal_time(self, t):
"""
:param t:
:type t:
"""
self.t = t
:param t:
:type t:
"""
self.t = t

def __enter__(self):
self.reset_internal_time()
return True
def __enter__(self):
self.reset_internal_time()
return True


if __name__ == "__main__":

def asidjashdya():
"""
counts
"""
for _, i in zip(range(10), SignalGenerator(identity)):
print(i)
def asidjashdya():
"""
counts
"""
for _, i in zip(range(10), SignalGenerator(identity)):
print(i)


asidjashdya()
asidjashdya()
4 changes: 4 additions & 0 deletions modulation/regression/denoising/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@
Created on 02-12-2020
"""


from .band_pass import *
from .finger_print import *
6 changes: 5 additions & 1 deletion modulation/regression/linear_predictive_coding.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@

import numpy

__all__ =['lpc_simple']


def lpc_simple(y: numpy.ndarray, m: int) -> numpy.ndarray:
"Return m linear predictive coefficients for sequence y using Levinson-Durbin prediction algorithm"
'''
Return m linear predictive coefficients for sequence y using Levinson-Durbin prediction algorithm
'''

# step 1: compute autoregression coefficients R_0, ..., R_m
r = [y.dot(y)]
Expand Down
2 changes: 2 additions & 0 deletions modulation/regression/spectral_denoise.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import numpy


__all__=['fft_denoise']

def fft_denoise(
noisy_signal: numpy.ndarray, num_time_steps: int, cutoff_threshold: float = 100
) -> numpy.ndarray:
Expand Down
2 changes: 2 additions & 0 deletions modulation/signal_utilities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@
from .chopping import *
from .segmentation import *
from .splitting import *
from .audio_utilities import *
from .noise_generation import *
4 changes: 4 additions & 0 deletions modulation/signal_utilities/audio_utilities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@
Created on 11-01-2021
"""


from .persistence import *
from .filtering import *
1 change: 1 addition & 0 deletions modulation/signal_utilities/audio_utilities/filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from scipy.signal import hilbert, lfilter
from warg import next_pow_2

__all__= ['mel_scale','in_mel_scale','pre_emphasise','pre_emphasise_torch','de_emphasise',"fft_frequencies","hilbert_envelope"]

def mel_scale(x: numpy.ndarray) -> numpy.ndarray:
"""
Expand Down
5 changes: 5 additions & 0 deletions modulation/signal_utilities/audio_utilities/persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import numpy
import soundfile

__all__=['audio_read','audio_write']

def audio_read(
path: str, norm: bool = True, start: int = 0, stop: int = None
Expand Down Expand Up @@ -81,3 +82,7 @@ def audio_write(
os.makedirs(destdir)

soundfile.write(dest_path, data, fs)


if __name__ == '__main__':
pass
2 changes: 2 additions & 0 deletions modulation/signal_utilities/noise_generation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@

from .babble_noise import *
from .shaped_noise import *
from .gaussian_noise import *
from .additive_noise import *
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

from modulation.signal_utilities import mask_split_non_zero_concat

__all__ = ['sample_noise','compute_additive_noise_samples']

def sample_noise(
noise,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def generate_babble_noise(
export_path: Path = None,
) -> Iterable:
"""
Generates babble noise from samples
:param samples:
:type samples:
Expand Down
Loading

0 comments on commit bc9350f

Please sign in to comment.