Example #1
0
wav_distortion[wav_distortion < -1] = -1

# %% plot
plt.figure()
plt.plot(t, wav_glasno)
plt.plot(t, wav_distortion)
plt.grid()

# %% normalisation
# to +/-1
wav_norm = wav_glasno / np.max(np.abs(wav_glasno))
wav_norm2 = wav_short / np.max(np.abs(wav_short))
np.all(wav_norm == wav_norm2)


# %% normalization func
def normalise(wav, level_dB=0):
    # level_dB = 20*np.log10(level)
    level = 10**(level_dB/20)
    wav_norm = wav / np.max(np.abs(wav)) * level
    return wav_norm


wav_norm0 = normalise(wav_short)
wav_norm3 = normalise(wav_short, -3)
wav_norm18 = normalise(wav_short, -18)

# %% move functuion to dedicated utility module
import das
wav_norm = das.normalise(wav_short, -60)
Example #2
0
import matplotlib.pyplot as plt
from scipy.io import wavfile
import os
import das

# %% load wave
path = 'audio/'
file_name = 'Mara.wav'
os.system('play '+path+file_name)
fs, wav = wavfile.read(path+file_name)
t = np.arange(wav.size) / fs

# %% genrate tremolo sine
amp = 0.5
offset = 1
f = 50
tremolo = amp * np.sin(2*np.pi*f*t) + offset
plt.plot(t, tremolo)

# %% apply tremolo
wav_tremolo = wav * tremolo
wav_tremolo = das.normalise(wav_tremolo, -3)

# %% wav write and play
wav_tremolo_int16 = wav_tremolo * 2**15
wav_tremolo_int16 = wav_tremolo_int16.astype('int16')
wavfile.write(path+file_name+'_tremolo.wav', fs, wav_tremolo_int16)
os.system('play '+path+file_name+'_tremolo.wav')


# %% filter signal
wav_lp = sig.lfilter(b_lp, a_lp, wav)
wav_bp = sig.lfilter(b_bp, a_bp, wav)
wav_hp = sig.lfilter(b_hp, a_hp, wav)

# %% gains
G_lp = 24  # dB
G_bp = -24  # dB
G_hp = 24  # dB

g_lp = 10**(G_lp/20)
g_bp = 10**(G_bp/20)
g_hp = 10**(G_hp/20)

# %% mix
wav_out = wav_lp * g_lp + wav_bp * g_bp + wav_hp * g_hp

wav_out = das.normalise(wav_out)

# %% play
wavfile.write('audio/Mara_eq.wav', fs,
              np.array(wav_out*2**15, dtype='int16'))
os.system('play audio/Mara_eq.wav')

# %% compare to original
os.system('play audio/Mara.wav')

# %% compare spectrograms
das.get_spectrogram(fs, wav)
das.get_spectrogram(fs, wav_out)
Example #4
0
# %% load wav
folder = 'audio/'
file_name = 'Pato_8k.wav'
fs, wav = wavfile.read(folder + file_name)
wav = wav / 2**15
t = np.arange(wav.shape[0]) / fs
os.system('play ' + folder + file_name)

# %% brum
brum = np.sin(2*np.pi*50*t) + \
       .05 * np.sin(2*np.pi*100*t) + \
       .01 * np.sin(2*np.pi*150*t)

# %% add brum
wav_brum = wav + .02 * brum
wav_brum = das.normalise(wav_brum)

# %% plot
plt.figure()
plt.plot(t, wav)
plt.plot(t, wav_brum)

# %% play
wavfile.write('audio/Pato_brum.wav', fs,
              np.array(wav_brum * 2**15, dtype='int16'))
os.system('play audio/Pato_brum.wav')

# %% design notch filter
r = 0.99
f0 = 50
w0 = f0 / (fs / 2) * np.pi
Example #5
0
    b, a = sig.iirfilter(order, [f_l, f_h],
                         btype='bandpass', ftype='butter', fs=fs)
    b_frame.append(b)
    a_frame.append(a)

# %% window + wah
win = sig.get_window('hann', n_win)
t_win = n_win / fs
pos = 0
i = 0
wav_wah = np.zeros(wav_pad.size)
while pos <= wav_pad.size - n_win:
    frame = wav_pad[pos : pos+n_win]
    frame = frame * win
    frame_wah = sig.lfilter(b_frame[i], a_frame[i], frame)
    wav_wah[pos : pos+n_win] += frame_wah * win
    pos += n_hop
    i += 1

# %% wav write and play
wav_wah = 0.1*wav_pad + 0.9*wav_wah
wav_wah = das.normalise(wav_wah, -3)
wav_wah_int16 = wav_wah * 2**15
wav_wah_int16 = wav_wah_int16.astype('int16')
wavfile.write(path+file_name+'_wah.wav', fs, wav_wah_int16)
os.system('play '+path+file_name+'_wah.wav')

# %% plot spectrogram
__ = das.get_spectrogram(fs, wav_pad, 2048, win_type='hann', plot=True)
__ = das.get_spectrogram(fs, wav_wah, 2048, win_type='hann', plot=True)