# Path: pambox/speech/material.py
# class Material(object):
#     def __init__(self,
#                  fs=22050,
#                  path_to_sentences='../stimuli/clue/sentencesWAV22',
#                  path_to_maskers=None,
#                  path_to_ssn='../stimuli/clue/SSN_CLUE22.wav',
#                  ref_level=74,
#                  name='CLUE',
#                  force_mono=False):
#     def files(self):
#     def files(self, f):
#     def path_to_ssn(self):
#     def path_to_ssn(self, path):
#     def load_file(self, filename):
#     def files_list(self):
#     def load_files(self, n=None):
#     def _load_ssn(self):
#     def pick_section(signal, section=None):
#     def ssn(self, x=None):
#     def set_level(self, x, level):
#     def average_level(self):
#     def create_ssn(self, files=None, repetitions=200):
#     def create_filtered_ssn(self, files=None, duration=5):
#         LONG_TERM_SPEC = reduce(lambda x, y: (x + np.fft.rfft(y, n_fft)) / 2,
#                                 files,
#                                 0)
#         NOISE = np.fft.rfft(np.random.randn(*noise_shape), n_fft_noise)
# 
# Path: pambox/utils.py
# def dbspl(x, ac=False, offset=0.0, axis=-1):
# def setdbspl(x, lvl, ac=False, offset=0.0):
# def rms(x, ac=False, axis=-1):
# def hilbert(x, N=None, axis=-1):
# def next_pow_2(x):
# def fftfilt(b, x, n=None):
# def write_wav(fname, fs, x, normalize=False):
# def make_same_length(a, b, extend_first=True):
# def add_signals(a, b):
# def int2srt(x, y, srt_at=50.0):
# def psy_fn(x, mu=0., sigma=1.):
# def noctave_center_freq(lowf, highf, width=3):
# def impz(b, a=1):
# def mfreqz(b, a=1, fs=22050.0):
# def read_wav_as_float(path):
#         N = x.shape[axis]
#             N = 2 ** arange(ceil(log2(N_b)), 27)
#     L = int(N_fft - N_b + 1)
#     B = fft(b, N_fft)
#         B = np.tile(B, (x.shape[0], 1))


import os.path
import numpy as np
from numpy.testing import assert_allclose, dec, TestCase
from pambox.speech import material
from pambox import utils
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function



__DATA_ROOT__ = os.path.join(os.path.dirname(__file__), 'data')


def test_set_level():
    # Set the reference level to 100 dB
    ref_level = 100
    c = material.Material(path_to_ssn=os.path.join(__DATA_ROOT__,
                                                   'dummy_ssn.wav'),
                          ref_level=ref_level)
    # But actually create a 97 dB signal.
    sentence_level = 97  # dB SPL
    target = sentence_level
    x = np.random.randn(100)
    x = utils.setdbspl(x, sentence_level)
    # So when setting the level to the reference, we should get the actual
    # sentence level.

# Path: pambox/speech/material.py
# class Material(object):
#     def __init__(self,
#                  fs=22050,
#                  path_to_sentences='../stimuli/clue/sentencesWAV22',
#                  path_to_maskers=None,
#                  path_to_ssn='../stimuli/clue/SSN_CLUE22.wav',
#                  ref_level=74,
#                  name='CLUE',
#                  force_mono=False):
#     def files(self):
#     def files(self, f):
#     def path_to_ssn(self):
#     def path_to_ssn(self, path):
#     def load_file(self, filename):
#     def files_list(self):
#     def load_files(self, n=None):
#     def _load_ssn(self):
#     def pick_section(signal, section=None):
#     def ssn(self, x=None):
#     def set_level(self, x, level):
#     def average_level(self):
#     def create_ssn(self, files=None, repetitions=200):
#     def create_filtered_ssn(self, files=None, duration=5):
#         LONG_TERM_SPEC = reduce(lambda x, y: (x + np.fft.rfft(y, n_fft)) / 2,
#                                 files,
#                                 0)
#         NOISE = np.fft.rfft(np.random.randn(*noise_shape), n_fft_noise)
# 
# Path: pambox/utils.py
# def dbspl(x, ac=False, offset=0.0, axis=-1):
# def setdbspl(x, lvl, ac=False, offset=0.0):
# def rms(x, ac=False, axis=-1):
# def hilbert(x, N=None, axis=-1):
# def next_pow_2(x):
# def fftfilt(b, x, n=None):
# def write_wav(fname, fs, x, normalize=False):
# def make_same_length(a, b, extend_first=True):
# def add_signals(a, b):
# def int2srt(x, y, srt_at=50.0):
# def psy_fn(x, mu=0., sigma=1.):
# def noctave_center_freq(lowf, highf, width=3):
# def impz(b, a=1):
# def mfreqz(b, a=1, fs=22050.0):
# def read_wav_as_float(path):
#         N = x.shape[axis]
#             N = 2 ** arange(ceil(log2(N_b)), 27)
#     L = int(N_fft - N_b + 1)
#     B = fft(b, N_fft)
#         B = np.tile(B, (x.shape[0], 1))


# Path: pambox/tests/test_speech_material.py
import os.path
import numpy as np
from numpy.testing import assert_allclose, dec, TestCase
from pambox.speech import material
from pambox import utils

# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function



__DATA_ROOT__ = os.path.join(os.path.dirname(__file__), 'data')


def test_set_level():
    # Set the reference level to 100 dB
    ref_level = 100
    c = material.Material(path_to_ssn=os.path.join(__DATA_ROOT__,
                                                   'dummy_ssn.wav'),
                          ref_level=ref_level)
    # But actually create a 97 dB signal.
    sentence_level = 97  # dB SPL
    target = sentence_level
    x = np.random.randn(100)
    x = utils.setdbspl(x, sentence_level)
    # So when setting the level to the reference, we should get the actual
    # sentence level.

    level = utils.dbspl(c.set_level(x, ref_level))