Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""Select appropriate microphone array"""
if array_type == 'random':
mic_array = rt.bbb_arrays.R_compactsix_random
elif array_type == 'circular':
mic_array = rt.bbb_arrays.R_compactsix_circular_1
"""define capture parameters accordingly"""
zero_padding = 50 # diameter/343*fs for either side
nfft = 2048 # seems that less than this is not reliable
buffer_size = nfft - zero_padding
num_channels = 6
"""Check for LED Ring"""
try:
import matplotlib.cm as cm
led_ring = rt.neopixels.NeoPixels(usb_port=led_ring_address,
colormap=cm.afmhot)
print("LED ring ready to use!")
except:
print("No LED ring available...")
led_ring = False
"""Setup"""
num_angles = 60 # for directivity
beam_shape = np.zeros(num_angles)
def init(buffer_frames, rate, channels, volume):
global stft, bf
# stft for filtering
stft = rt.transforms.STFT(buffer_size, rate, hop=buffer_size,
channels=channels, transform=transform)
sampling_freq = config['sampling_frequency']
led_ring_address = config['led_ring_address']
except:
# default when no hw config file is present
sampling_freq = 44100
led_ring_address = '/dev/cu.usbmodem1411'
fft_size = 2*buffer_size; hop = buffer_size
max_freq = min(sampling_freq/2, max_freq);
height = int(np.ceil(float(max_freq)/sampling_freq*fft_size))
num_channels=2
"""Check for LED Ring"""
try:
import matplotlib.cm as cm
led_ring = rt.neopixels.NeoPixels(usb_port=led_ring_address,
colormap=cm.summer, vrange=[min_val, max_val])
print("LED ring ready to use!")
except:
print("No LED ring available...")
led_ring = False
def init(buffer_frames, rate, channels, volume):
global stft
# create STFT object
stft = rt.transforms.STFT(fft_size, rate, hop, transform=transform)
def handle_data(audio):
global stft
# ideally pick a buffer size so that length of DFT (buffer_size*2) will be power of two
nfft = 2048
buffer_size = nfft - numtaps + 1
num_channels = 2
transform = 'mkl' # 'numpy', 'mlk', 'fftw'
""" Visualization parameters """
under = 100 # undersample otherwise too many points
num_sec = 5
viz = True # if false, playback instead
"""Check for LED Ring"""
try:
import matplotlib.cm as cm
led_ring = rt.neopixels.NeoPixels(usb_port=led_ring_address,
colormap=cm.jet, vrange=[70, 100.])
print("LED ring ready to use!")
except:
print("No LED ring available...")
led_ring = False
def log_bands(fmin, fmax, n, fs, nfft):
''' Creates logarithmically spaced bands '''
lfmin = np.log10(fmin)
lfmax = np.log10(fmax)
fc = np.logspace(lfmin, lfmax, n + 1, base=10)
fd = 10**(lfmax - lfmin) / n
"""
Select frequency range
"""
n_bands = 10
freq_range = [2000., 4000.]
f_min = int(np.round(freq_range[0] / sampling_freq*nfft))
f_max = int(np.round(freq_range[1] / sampling_freq*nfft))
range_bins = np.arange(f_min, f_max+1)
freq_bins = np.round(np.linspace(freq_range[0], freq_range[1], n_bands) / sampling_freq * nfft)
vrange = [-1.5, 1.0]
"""Check for LED Ring"""
try:
import matplotlib.cm as cm
led_ring = rt.neopixels.NeoPixels(usb_port=led_ring_address,
colormap=cm.afmhot, vrange=vrange)
print("LED ring ready to use!")
num_pixels = led_ring.num_pixels
except:
print("No LED ring available...")
led_ring = False
num_pixels = 60
led_rot_offset = 17 # mismatch of led ring and microphone array
# a Bell curve for visualization
sym_ind = np.concatenate((np.arange(0, 30), -np.arange(1,31)[::-1]))
P = np.zeros((num_pixels, 3), dtype=np.float)
source_hue = [0., 0.3]
source_sat = [0.9, 0.8]
background = np.array(colorsys.hsv_to_rgb(0.45, 0.2, 0.1))
source = np.array(colorsys.hsv_to_rgb(0.11, 0.9, 1.))
"""
Select frequency range
"""
n_bands = 20
freq_range = [2000., 3500.]
f_min = int(np.round(freq_range[0] / sampling_freq*nfft))
f_max = int(np.round(freq_range[1] / sampling_freq*nfft))
range_bins = np.arange(f_min, f_max+1)
use_bin = False
vrange = [-3., 1.]
"""Check for LED Ring"""
try:
import matplotlib.cm as cm
led_ring = rt.neopixels.NeoPixels(usb_port=led_ring_address,
colormap=cm.afmhot, vrange=vrange)
print("LED ring ready to use!")
num_pixels = led_ring.num_pixels
except:
print("No LED ring available...")
led_ring = False
num_pixels = 60
led_rot_offset = 17 # mismatch of led ring and microphone array
# a Bell curve for visualization
sym_ind = np.concatenate((np.arange(0, 30), -np.arange(1,31)[::-1]))
P = np.zeros((num_pixels, 3), dtype=np.float)
old_azimuths = np.zeros(num_src)
source_hue = [0.11, 0.5]
source_sat = [0.9, 0.8]
background = np.array(colorsys.hsv_to_rgb(0.45, 0.2, 0.1))
sampling_freq = config['sampling_frequency']
led_ring_address = config['led_ring_address']
except:
# default when no hw config file is present
sampling_freq = 44100
led_ring_address = '/dev/cu.usbmodem1421'
""" Visualization parameters """
under = 100 # undersample otherwise too many points
num_sec = 5
"""Check for LED Ring"""
try:
import matplotlib.cm as cm
led_ring = rt.neopixels.NeoPixels(usb_port=led_ring_address,
colormap=cm.afmhot)
print("LED ring ready to use!")
except:
print("No LED ring available...")
led_ring = False
def when_config(buffer_frames, rate, channels, volume):
global dft, vad
dft = rt.transforms.DFT(nfft=buffer_frames, transform=transform)
vad = rt.VAD(buffer_size, rate, 10, 40e-3, 3, 1.2)
# perform VAD
frame_num = 0
def apply_vad(audio):
# default when no hw config file is present
sampling_freq = 44100
array_type = 'random'
led_ring_address = '/dev/cu.usbmodem1421'
"""Select appropriate microphone array"""
if array_type == 'random':
mic_array = rt.bbb_arrays.R_compactsix_random
elif array_type == 'circular':
mic_array = rt.bbb_arrays.R_compactsix_circular_1
"""Check for LED Ring"""
try:
import matplotlib.cm as cm
led_ring = rt.neopixels.NeoPixels(
usb_port=led_ring_address,
colormap=cm.winter,
vrange=doa_algo_config[doa_algo]['vrange']
)
num_pixels = led_ring.num_pixels
print("LED ring ready to use!")
except:
print("No LED ring available...")
num_pixels = 60
led_ring = False
# Color stuff
sym_ind = np.concatenate((np.arange(0, 30), -np.arange(1,31)[::-1]))
P = np.zeros((num_pixels, 3), dtype=np.float)
background = np.array([1/6., 0.2, 0.1])
source = np.array([0., 0.9, 1.])