def test_add_source_mic_obj(): room = pra.ShoeBox(room_size) source0 = pra.SoundSource(source_loc0, signal=sig) source1 = pra.SoundSource(source_loc1, signal=sig) mic_array0 = pra.MicrophoneArray(np.c_[mic0], fs=room.fs) mic_array1 = pra.MicrophoneArray(np.c_[mic1], fs=room.fs) room.add(source0).add(mic_array0) assert len(room.sources) == 1 assert np.allclose(room.sources[0].position, source_loc0) assert len(room.mic_array) == 1 assert room.mic_array.R.shape == (3, 1) assert np.allclose(room.mic_array.R[:, 0], mic0) room.add(mic_array1).add(source1) assert len(room.sources) == 2 assert np.allclose(room.sources[1].position, source_loc1) assert len(room.mic_array) == 2 assert np.allclose(room.mic_array.R[:, 0], mic0) assert np.allclose(room.mic_array.R[:, 1], mic1) assert room.mic_array.R.shape == (3, 2)
def test_add_source_mic_ndarray_2(): source0 = pra.SoundSource(source_loc0, signal=sig) source1 = pra.SoundSource(source_loc1, signal=sig) mic_array = np.c_[mic0, mic1] room = pra.ShoeBox(room_size).add(source0).add(source1).add_microphone( mic_array) assert len(room.sources) == 2 assert np.allclose(room.sources[0].position, source_loc0) assert np.allclose(room.sources[1].position, source_loc1) assert len(room.mic_array) == 2 assert np.allclose(room.mic_array.R[:, 0], mic0) assert np.allclose(room.mic_array.R[:, 1], mic1) assert room.mic_array.R.shape == (3, 2)
def test_soundsource_basic(): the_signal = np.ones(10) source = pra.SoundSource([1.0, 1.0], signal=the_signal) the_signal_2 = np.zeros(10) source.add_signal(the_signal_2)
def get_room_constructor_args(): """ When provided with sources and microphones, the constructor should try to compute the RIR immediately """ source = pra.SoundSource(position=source_position) mics = pra.MicrophoneArray(np.array([mic_position]).T, fs) shoebox = pra.ShoeBox( room_dim, materials=pra.Material(e_abs), fs=fs, max_order=max_order, sources=[source], mics=mics, ) shoebox.image_source_model() shoebox.compute_rir() return shoebox
def generate(min_side, max_side, min_height, max_height, n_mics, fs=16000, max_order=2, min_abs=0.1, max_abs=0.9, signal=None): np.random.seed() floor_shape = generate_floor_shape(min_side, max_side) n_walls = len(floor_shape.boundary.xy[0]) - 1 height = np.random.uniform(min_height, max_height) absorption = np.random.rand(n_walls, 1) * (max_abs - min_abs) + min_abs vertices = floor_shape.exterior.coords x_coords = vertices.xy[0][:-1] y_coords = vertices.xy[1][:-1] room = pra.Room.from_corners([x_coords, y_coords], fs=fs, max_order=max_order, absorption=absorption) room.extrude(height, absorption=absorption) visible = False while not visible: mic_pos = find_valid_pos(floor_shape, height, n_mics) source_pos = find_valid_pos(floor_shape, height, n_pos=1) source_pos = sum(source_pos, []) room.mic_array = pra.MicrophoneArray(mic_pos, room.fs) room.sources = [pra.SoundSource(source_pos, signal=signal, delay=0)] visibility_list = [] for pos in np.array(mic_pos).T: visibility_list.append(room.is_visible(room.sources[0], pos)) visible = all(visibility_list) return room
# finally place the array in the room room.add_microphone_array(mic_array) ## Add source # specify signal source fs = 44100 signal = np.zeros((1, fs*3)) signal[0] = 1 #fs, signal = wavfile.read("arctic_a0010.wav") # add source to 2D room #room = pra.Room.from_corners(corners, fs=fs) my_source = pra.SoundSource([1, 1, 1], signal=signal, delay=1.3) room.add_source(my_source) fig, ax = room.plot() ## Add receiver R = pra.circular_2D_array(center=[2.,2.], M=6, phi0=0, radius=0.1) room.add_microphone_array(pra.MicrophoneArray(R, room.fs)) fig, ax = room.plot() # compute image sources room.image_source_model(use_libroom=True)