question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

File for generating room simulator does not work

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
cli0commented, Feb 12, 2020

Yes, this works just fine. Thank you.

0reactions
fakufakucommented, Feb 12, 2020

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:

rir = (2**15 - 1) * room.rir[0][0]
wavfile.write('rir.wav', 16000, np.array(np.clip(rir),-2 ** 15, 2 ** 15 - 1), dtype=np.int16))
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found