Hi,
Make sure you have installed dependencies :
pip install scipy
pip install matplotlib
pip install peakutils
Then you will be able to execute the script : python ir2dsp.py test.wav
test_model -20 100. You will find attached the script that allowed me to
build dsp files for cabinet impulses.
With the Guitarix project on Faust, you will have opportunities to work
on your timbre and make cool sounds. If you wish, you can listen to my
latest creation : https://soundcloud.com/s-bastien-clara/phantom-limb
Cheers,
Sébastien
Le 13/01/2019 à 23:13, Virginie YK a écrit :
Hi
I'm trying to use ir2dsp although I don't know Python at all.
Anyway, I could finally install it on my PC. Now, in the Windows
command line, I type :
python ir2dsp.py test.wav test_model.dsp -20 100
where test.wav is a short file supposed to be a kind of Impusionnal
Response, test_model.dsp is the resulting model file ; -20 ("Minimum
value of peaks in dB (between -infinity and 0)" and 100 Hz (Minimum
distance between two peaks in Hertz).
The result is the following message :
C:\Users\User\AppData\Roaming\Python\Python37\site-packages\scipy\io\wavfile.py:273:
*WavFileWarning: Chunk (non-data) not understood, skipping it.*
WavFileWarning)
Traceback (most recent call last):
* File "ir2dsp.py", line 32, in <module>
x = x/max(x)
ValueError: The truth value of an array with more than one element is
ambiguous. Use a.any() or a.all()*
Is it a bug or are there any condition on the input file (the wave
file) that I don't know ? I chose a very short and easy input file of
345 Ko.
In fact, I can't use ir2dsp ........ could you help me please ?
Thanks
Virginie
_______________________________________________
Faudiostream-users mailing list
Faudiostream-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/faudiostream-users
#!/usr/bin/env python
# id2dsp.py
# Copyright Pierre-Amaury Grumiaux, Pierre Jouvelot, Emilio Jesus Gallego Arias,
# and Romain Michon
from __future__ import division
import math
import numpy as np
import matplotlib.pyplot as plt
from sys import argv
import subprocess
from scipy.io.wavfile import read
import peakutils
import peakutils.plot as pkplt
import operator
import argparse
# Help for use of the script
parser = argparse.ArgumentParser(description = "IR2dsp.py is a python script that generates a .dsp file from an impulse response file (a .wav file).The impulse response is analyzed in order to rebuild the sound of the vibration of the object based on this impulse response.", epilog = "See http://faust.grame.fr/images/faust-tutorial2.pdf for more information about Faust")
parser.add_argument("soundFile", type = str, help = "Path of the sound file")
parser.add_argument("modelName", help = "The name of the model created in the .dsp file")
parser.add_argument("peakThreshold", help = "Minimum value of peaks in dB (between -infinity and 0)")
parser.add_argument("peakDistance", help = "Minimum distance between two peaks in Hertz")
ars = parser.parse_args ()
# Arguments
script, soundFile, modelName, peakThreshold, peakDistance = argv
# Reading file
(fs, x) = read(soundFile)
# Normalizing sound
x = x/max(x)
# FFT
X = np.abs(np.fft.fft(x))
X = X/(max(X))
# computing corresponding frequencies
time_step = 1/fs
freqs = np.fft.fftfreq(x.size, time_step)
idx = np.argsort(freqs)
# plot for debug
# plt.plot(freqs[idx],20*np.log(X[idx]))
# plt.show()
# detecting peaks
threshold = math.pow(10, float(peakThreshold)/20) # from dB to X unit
distance = int(peakDistance)/(fs/x.size)
indexes = peakutils.indexes(X[idx], thres = threshold, min_dist = distance)
# Storing frequencies and modes for each bp filters
peaksFreq = []
peaksGains = []
nbOfPeaks = 0
for i in indexes :
if freqs[idx][i] > 0:
peaksFreq.append(freqs[idx][i])
peaksGains.append(X[idx][i])
nbOfPeaks += 1
peaksGains = peaksGains/(max(peaksGains))
#Computing t60 values
peakst60 = []
for i in range(0, nbOfPeaks) :
offset = pow(10, -3/20) # conversion of -3 dB in X unit
peakIndex = indexes[len(indexes) - nbOfPeaks + i]
n = peakIndex
while X[idx][n] > (X[idx][peakIndex]*offset):
n = n-1
a = n
n = peakIndex
while X[idx][n] > (X[idx][peakIndex]*offset):
n = n+1
b = n
bandwidth = (b-a)/(fs/x.size) # bandwidth in Hz
print(bandwidth)
peakst60.append(6.91/fs/(1-math.exp(-math.pi*bandwidth/fs)))
print(" peaks frequencies : ")
print(peaksFreq)
print(" corresponding gains : ")
print(peaksGains)
print(" corresponding t60 : ")
print(peakst60)
# Writing the dsp file #
# #######################
file = open(modelName + ".dsp", "w")
file.write("declare name \"" + modelName + "\";\n")
file.write("declare description \"Generated by tools/physicalModeling/ir2dsp.py\";\n")
file.write("\n");
file.write("import(\"stdfaust.lib\");\n")
file.write("\n");
file.write("pi = 4*atan(1.0);\n")
file.write("nModes = ")
file.write(str(len(peaksGains)))
file.write(";\n")
file.write("\n");
file.write("modeFrequencies=("); # writing the frequencies list
k = 0
for i in peaksFreq:
file.write(str(i))
if (k+1<len(peaksGains)):
file.write(",")
k += 1
file.write(");\n");
file.write("massEigenValues=("); # writing the masses list
k = 0
for i in peaksGains:
file.write(str(i))
if (k+1 < len(peaksGains)):
file.write(",")
k += 1
file.write(");\n");
file.write("t60=("); # writing the t60 list
k = 0
for i in peakst60:
file.write(str(i))
if (k+1 < len(peaksGains)):
file.write(",")
k += 1
file.write(");\n");
file.write("\n");
file.write("modeFreqs=par(i,nModes,ba.take(i+1, modeFrequencies));\n")
file.write("modeGains=par(i,nModes,ba.take(i+1, massEigenValues));\n")
file.write("modeT60 = par(i,nModes,ba.take(i+1,t60));\n")
file.write("\n");
file.write(modelName)
file.write("=modalModel(nModes,modeFrequencies,modeT60,modeGains);\n");
file.write("\n");
file.write("modalModel(n,modeFreqs,modeRes,modeGains) = _ <: par(i,n,pm.modeFilter(freqs(i),res(i),gain(i))) :> _\n");
file.write("with {\n");
file.write(" freqs(i) = ba.take(i+1,modeFreqs);\n");
file.write(" res(i) = ba.take(i+1,modeRes);\n");
file.write(" gain(i) = ba.take(i+1,modeGains);\n");
file.write("};\n");
file.write("\n");
file.write("\ncab = " + modelName + ";\n")
file.write("\n");
file.write("wet = vslider(\"[2] dryWet[style:knob]\", 1, 0, 1, 0.01);\n")
file.write("dry = 1 - wet;\n")
file.write("\n");
file.write("process = _ <: _*dry, (_*wet:cab) :> _;\n")
file.close();
_______________________________________________
Faudiostream-users mailing list
Faudiostream-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/faudiostream-users