<commit_before>"""
Filename: mainConvReverb.py

See README.md

Developed under the Apache License 2.0
"""
#______________________________________________________________________________
#Header Imports


import array
import contextlib
import wave
import matplotlib.pyplot as plt
import numpy as np
import sys

sys.path.append('../Utilities')
import utilities as ut

#______________________________________________________________________________
#Start mainConvReverb.py

# Global parameters
dirIn = "../../Original-Audio-Samples/"
dirOut = "../../Output-Audio-Samples/ConvolutionReverb/"

numChannels = 1                      # mono
sampleWidth = 2                      # in bytes, a 16-bit short
sampleRate = 44100
mulFactor = sampleRate * 10
maxAmp = (2**(8*sampleWidth - 1) - 1)    #maximum amplitude is 2**15 - 1  = 32767
minAmp = -(2**(8*sampleWidth - 1))       #min amp is -2**15


def FFT(X, N):
    return np.fft.rfft(X, N)
    
def IFFT(X, N):
    return np.fft.ifft(X, N)
    
def convolve(X, Y):
    return np.convolve(X, Y)

#______________________________________________________________________________

def convReverb(signal, location, preDelay = 0, Decay = 1, trim = True):
    """fileName: name of file in string form
        preDelay: delay befor reverb begins (seconds)
        Decay: hang time of signal (seconds)        
    """    
    signal = [int(x) for x in signal]
    
    print("signal acquired")
        
    
    pdSamples = preDelay * sampleRate
    dSamples = Decay * sampleRate
    
    if trim: #trim to 10 seconds
        signal = signal[:441000]
        print("trimmed")
    
    clap = ut.readWaveFile(dirIn+"Reverb_Samples/Clap.wav")
    
    kernel1 = np.fft.fft(location) #use FFT on location sound
    kernel2 = convolve(clap,location)
    kernel3 = []
    for i in range(0, len(clap)-1):
        kernel3 += [clap[i] * location[i]]
    
    print("got kernel")
    
    new = []
    for i in signal:
        new += [int(signal[i] * kernel1[i])]
    
        
    new2 = []
    for i in signal:
        new2 += [int(signal[i] * kernel2[i])]
        
    new3 = []
    for i in signal:
        new3 += [int(signal[i] * kernel3[i])]

    #return new? is new needed?
        
    print("got new")
    
    #according to https://en.wikipedia.org/wiki/Overlap%E2%80%93add_method#The_algorithm
    #this is the way Overlap-add should work,which is an efficient way of convolving<commit_msg>commit<commit_after>"""
Filename: mainConvReverb.py

See README.md

Developed under the Apache License 2.0
"""
#______________________________________________________________________________
#Header Imports


import array
import contextlib
import wave
import matplotlib.pyplot as plt
import numpy as np
import sys

sys.path.append('../Utilities')
import utilities as ut

#______________________________________________________________________________
#Start mainConvReverb.py

# Global parameters
dirIn = "../../Original-Audio-Samples/"
dirOut = "../../Output-Audio-Samples/ConvolutionReverb/"

numChannels = 1                      # mono
sampleWidth = 2                      # in bytes, a 16-bit short
sampleRate = 44100
mulFactor = sampleRate * 10
maxAmp = (2**(8*sampleWidth - 1) - 1)    #maximum amplitude is 2**15 - 1  = 32767
minAmp = -(2**(8*sampleWidth - 1))       #min amp is -2**15


def FFT(X, N):
    return np.fft.rfft(X, N)
    
def IFFT(X, N):
    return np.fft.ifft(X, N)
    
def convolve(X, Y):
    return np.convolve(X, Y)

#______________________________________________________________________________

def convReverb(signal, location, preDelay = 0, Decay = 1, trim = True):
    """fileName: name of file in string form
        preDelay: delay befor reverb begins (seconds)
        Decay: hang time of signal (seconds)        
    """    
    signal = [int(x) for x in signal]
    
    print("signal acquired")
        
    
    pdSamples = preDelay * sampleRate
    dSamples = Decay * sampleRate
    
    if trim: #trim to 10 seconds
        signal = signal[:441000]
        print("trimmed")
    
    clap = ut.readWaveFile(dirIn+"Reverb_Samples/Clap.wav")
    
    kernel1 = np.fft.fft(location) #use FFT on location sound
    kernel2 = convolve(clap,location)
    kernel3 = []
    for i in range(0, len(clap)-1):
        kernel3 += [clap[i] * location[i]]
    
    print("got kernel")
    '''
    new = []
    for i in signal:
        new += [int(signal[i] * kernel1[i])]
    
        
    new2 = []
    for i in signal:
        new2 += [int(signal[i] * kernel2[i])]
        
    new3 = []
    for i in signal:
        new3 += [int(signal[i] * kernel3[i])]

    #return new? is new needed?

    print("got new")
    '''
    #according to https://en.wikipedia.org/wiki/Overlap%E2%80%93add_method#The_algorithm
    #this is the way Overlap-add should work,which is an efficient way of convolving
{'fraction_non_alphanumeric': 0.11439190584348544, 'fraction_numerical': 0.024778030146603344, 'mean_word_length': 2.7405405405405405, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6811215', 'n_tokens_mistral': 1604, 'n_tokens_neox': 1500, 'n_words': 423}