Given a set of audio recordings made from an array of microphones, compute a space map of the location of sound sources.
using SoundLocalizer, GLMakie
# define the positions of the microphones. (x,y,z) x channel
mic_pos = Float32[0 0 1 1
1 0 1 0
0 0 0 0]
# define the position of the source
source_pos = [0.125
0.25
0]
# define the density of the spatial sampling in the spacemap
grid_spacing = 0.001
# define the speed of sound and sampling rate
v, fs = 343, 48_000
# preallocate an array for the space map, plus its axes
icx, gridx, gridy, gridz = SoundLocalizer.alloc_spacemap(Array{Float32}, mic_pos, grid_spacing)
# generate the sound
s0 = randn(3000)
# calculate the distance between each mic and the source
ipart, _ = SoundLocalizer.distance2mics(mic_pos, source_pos..., v, fs)
# calculate the sound heard at each mic
s = hcat((s0[1000-x:1000-x+2000] for x in ipart)...)
# calculate the steered response power at all points in the spacemap
winlen = 1000
beamform!(s, mic_pos, icx, gridx, gridy, gridz, v, fs, winlen)
# plot the space map
fig, ax, img = image(extrema(gridx), extrema(gridy), icx[:,:,1], interpolate=false)
scatter!(ax, mic_pos[1,:], mic_pos[2,:], markersize=18, color=:fuchsia)
scatter!(ax, source_pos[1], source_pos[2], markersize=18,
color=:transparent, strokecolor=:fuchsia, strokewidth=2)
colsize!(fig.layout, 1, Aspect(1, 1.0))
hidedecorations!(ax)At some point binary executables might be offered in the releases page of the github website. Until then you'll need to run SoundLocalizer on the Julia command line.
Install Julia with juliup and then in Julia:
]add https://github.com/JaneliaSciComp/SoundLocalizerBen Arthur, arthurb@hhmi.org
Scientific Computing
Janelia Farm Research Campus
Howard Hughes Medical Institute
