노현욱

feat : 현 상태 확인을 위한 여러 mode들 표현

......@@ -8,11 +8,15 @@ from scipy.fft import fft, fftfreq
import math
import time
TARGET = "frequency" # frequency, amplitude, decibel
EFFECT = "pitch_shift" # echo, pitch_shift, low_filter
RATE = 44100
CHUNK = 1024
MAX_FREQ = 40 # max freq for pitch shifting
MAX_AMPLITUDE = 10000 # max amplitude for pitch shifting
MAX_DECIBEL = 50 # max decibel for decibel shifting
MAX_DECIBEL = 150 # max decibel for decibel shifting
MIN_DECIBEL = 50
EFFECT_LEVEL = 20 # number of effect level
INPUT_DEVICE_INDEX = 0
......@@ -69,8 +73,8 @@ class Effector:
self.sound = np.concatenate((self.sound, np.zeros(CHUNK - len(sound)%CHUNK, dtype=np.int16)))
self.target = "frequency"
self.effect = "pitch_shift"
self.target = TARGET
self.effect = EFFECT
self.echoed_sounds = list()
for i in range(EFFECT_LEVEL):
......@@ -109,7 +113,7 @@ class Effector:
return np.array(echoed_audio, dtype=np.int16)
def pitch_shift(self, shift):
sound = librosa.effects.pitch_shift(y=np.array(self.sound, np.float32), sr=RATE, n_steps=shift*3, bins_per_octave=1)
sound = librosa.effects.pitch_shift(y=np.array(self.sound, np.float32), sr=RATE, n_steps=shift*3-1, bins_per_octave=1)
return np.array(sound, dtype=np.int16)
def low_filter(self, param):
......@@ -133,13 +137,12 @@ class Effector:
def get_distortion_rate(self, db, main_frequency, amplitude):
print("current target is ", self.target)
param = 0
print(MAX_FREQ, main_frequency)
if self.target == "frequency":
param = min(MAX_FREQ-1, main_frequency) / MAX_FREQ
elif self.target == "amplitude":
param = min(MAX_AMPLITUDE-1, amplitude) / MAX_AMPLITUDE
elif self.target == "decibel":
param = min(MAX_DECIBEL-1, db) / MAX_DECIBEL
param = min(MAX_DECIBEL-MIN_DECIBEL, db-MIN_DECIBEL) / MAX_DECIBEL-MIN_DECIBEL
param = max(param, 0)
return param
......@@ -170,7 +173,7 @@ class Effector:
db, main_frequency, amplitude = self.get_decibel_freq_amplitude(active_sound)
print("touched, db {}, main_frequency {}, amplitude {}".format(db, main_frequency, amplitude))
param = self.get_distortion_rate(db, main_frequency, amplitude)
print("param : ", param)
print("effect 정도 :", param)
for i in range(0, len(self.sound), CHUNK):
temp_chunk = self.augumented_sound[self.effect][int(param*EFFECT_LEVEL)][i:i+CHUNK]
Q.put(temp_chunk)
......@@ -218,8 +221,6 @@ def callback(in_data, frame_count, time_info, status):
if Q.qsize() == 1:
Q.put(np.zeros(CHUNK, dtype=np.int16))
else:
print(Q.qsize())
return (Q.get(), pyaudio.paContinue)
stream = pa.open(format=pa.get_format_from_width(2),
......