File for generating room simulator does not work
See original GitHub issueI am using a custom file to generate room reverberations for existing sound files. The script generates an empty sound file. I went through the tutorial for the library but I can’t find what’s wrong.
import numpy as np
import matplotlib.pyplot as plt
from scipy.io import wavfile
from scipy.signal import fftconvolve
import pyroomacoustics as pra
import random
import pickle, os
import pandas as pd
def clip(signal, high, low):
'''
Clip a signal from above at high and from below at low.
'''
s = signal.copy()
s[np.where(s > high)] = high
s[np.where(s < low)] = low
return s
def normalize(signal, bits=None):
'''
normalize to be in a given range.
'''
s = signal.copy()
s /= np.abs(s).max()
# if one wants to scale for bits allocated
if bits is not None:
s *= 2 ** (bits - 1) - 1
s = clip(s, 2 ** (bits - 1) - 1, -2 ** (bits - 1))
return s
# name of the rir
name = "sample.wav"
# read one audio
fs, signal = wavfile.read("../audio/"+ name)
temp = 0
room_settings = []
# set the number of room reverberations that you want to create
num_rooms = 100
for i in range(num_rooms):
print("Saved room reverberation: " + str(i))
width = random.randint(3, 5)
length = random.randint(4, 6)
height = random.randint(2, 4)
room_dim = [width, length, height]
x_source = random.randint(0, width*10)/10.
y_source = random.randint(0, length*10)/10.
z_source = random.randint(0, height*10)/10.
x_mic = random.randint(0, width*10)/10.
y_mic = random.randint(0, length*10)/10.
z_mic = random.randint(0, height*10)/10.
source = [x_source, y_source, z_source]
microphone = np.array([[x_mic], [y_mic], [z_mic]])
room_setting = [width, length, height, x_source, y_source, z_source, x_mic, y_mic, z_mic]
if room_setting not in room_settings:
temp += 1
room_settings.append(room_setting)
max_order =10
# set max_order to a low value for a quick (but less accurate) RIR
room = pra.ShoeBox(room_dim, max_order=max_order, absorption=0.2, fs=fs)
# add source and set the signal to WAV file content
room.add_source(source, signal=signal)
# add two-microphone array
room.add_microphone_array(pra.MicrophoneArray(microphone, room.fs))
# compute image sources
room.image_source_model(use_libroom=True)
room.compute_rir()
rir = room.rir[0][0]
# save the room reverberations
wavfile.write("../audio/reverberations/" +"_rir_" + str(temp) + '.wav', 16000, rir)
The wav outputs I get here are empty wav-s. They dont play, they’re not even 1 second long. Am I doing anything wrong here in generating the reverberations?
Issue Analytics
- State:
- Created 4 years ago
- Comments:6
Top Results From Across the Web
Unable to Boot the Simulator (Xcode 13.3) - Apple Developer
Just open xcode -> windows -> devices and simulators, click on the Simulators tab , click New, click on the OS Version dropdown...
Read more >Guide :: Adding Custom Textures - Steam Community
A guide how to best implement custom textures into your game. From small changes like added writing to complete texture replacements....
Read more >Escape Simulator - Room Editor Basic Tutorial - YouTube
Your browser can 't play this video. Learn more. Switch camera.
Read more >Xcode compiles my App, but can't run it in the simulator
I fixed my problem by I making a new blank project and importing all the old files. It must have ...
Read more >Troubleshooting - OpenSimulator
5.1 I can't find any build files or solution files; 5.2 VS2005 won't open the .sln file. 6 Running OpenSimulator. 6.1 Running OpenSim.exe ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yes, this works just fine. Thank you.
Because all the values in
rir
are in[-1, 1]
, when you cast to integer, they are rounded to zero. As explained above, you should first multiply by a constant to adjust the range.Can you try: