Coder Social home page Coder Social logo

Generating wav about pyroomacoustics HOT 7 CLOSED

lcav avatar lcav commented on August 23, 2024
Generating wav

from pyroomacoustics.

Comments (7)

fakufaku avatar fakufaku commented on August 23, 2024

Hi @maelp , I'll answer in order.

  1. That's a perfectly valid thing to want! I think it should be possible to do this without too much effort. I will try to write an example in the next few days.
  2. Wether one wants to use 2D or 3D is entirely dependent on the situation I guess. The situation in research in acoustical signal processing is that many people validate their algorithms in 2D room environments. Now I think this has more to do with ease of implementation than accuracy. You can imagine that a 2D room is like a room without floor or ceiling (an infinite elevator shaft). If you are interested in realistic rendering, I would use a 3D room. Then again, the image source model is not the most life-like simulator to use.
  3. I have not used the simulator from Eric Lehmann, but if I recall correctly, it uses a more sophisticated method to improve the rendering of the tail of the RIR, but has the drawback of only handling shoebox rooms and requires Matlab.

from pyroomacoustics.

fakufaku avatar fakufaku commented on August 23, 2024

Closed by mistake. I'll close the issue when the example is added :)

from pyroomacoustics.

maelp avatar maelp commented on August 23, 2024

from pyroomacoustics.

fakufaku avatar fakufaku commented on August 23, 2024

Finally, I could do this quickly. I have added room_simulation.py in the examples folder. I hope this helps.

'''
A simple example of using pyroomacoustics to simulate
sound propagation in a shoebox room and record the result
to a wav file.
'''

import numpy as np
import pyroomacoustics as pra
import matplotlib.pyplot as plt
from scipy.io import wavfile

fs, audio_anechoic = wavfile.read('examples/samples/guitar_16k.wav')

# room dimension
room_dim = [5, 4, 6]

# Create the shoebox
shoebox = pra.ShoeBox(
    room_dim,
    absorption=0.2,
    fs=fs,
    max_order=15,
    )

# source and mic locations
shoebox.add_source([2, 3.1, 2], signal=audio_anechoic)
shoebox.add_microphone_array(
        pra.MicrophoneArray(
            np.array([[2, 1.5, 2]]).T, 
            shoebox.fs)
        )

# run ism
shoebox.simulate()

audio_reverb = shoebox.mic_array.to_wav('examples/samples/guitar_16k_reverb.wav', norm=True, bitdepth=np.int16)

from pyroomacoustics.

maelp avatar maelp commented on August 23, 2024

Thanks @fakufaku, would this be correct to simulate the reverb:

  • create the room
  • create a source which emits a single sample with amplitude 1.0
  • get the audio_reverb
  • convolve wav with it

from pyroomacoustics.

fakufaku avatar fakufaku commented on August 23, 2024

Dear @maelp , as I understand, you are interested to look at the room impulse response of the room. There is a simpler way to do this. When you run the shoebox.simulate() line above, all room impulse responses will be computed and stored in shoebox.rir. Then, the impulse response between the m-th microphone and the s-th source can be accessed at shoebox.rir[m][s].

In case you are only interested in getting the impulse response (as opposed to simulate the propagation of a particular sound sample), you can omit the source signal specification and call shoebox.compute_rir() instead of simulate(). Here is the modified example.

'''
A simple example of using pyroomacoustics to compute
the room impulse response between one source and one microphone.
'''

import numpy as np
import pyroomacoustics as pra
import matplotlib.pyplot as plt

# room dimension
room_dim = [5, 4, 6]

# Create the shoebox
shoebox = pra.ShoeBox(
    room_dim,
    absorption=0.2,
    fs=fs,
    max_order=15,
    )

# source and mic locations
shoebox.add_source([2, 3.1, 2])
shoebox.add_microphone_array(
        pra.MicrophoneArray(
            np.array([[2, 1.5, 2]]).T, 
            shoebox.fs)
        )

# run ism
shoebox.compute_rir()

# this plots the RIR between the 1st source and the 1st microphone
rir_time = np.arange(len(shoebox.rir[0][0])) / shoebox.fs
plt.plot(rir_time, shoebox.rir[0][0])

from pyroomacoustics.

maelp avatar maelp commented on August 23, 2024

Thanks !

from pyroomacoustics.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.