Thanks a lot Sebastien. Well, all the dependancies are installed ... In between, Pierre Amaury Grumiaux - who wrote the script - answered me and gave me a new version of the ir2dsp file, that I attach to this mail. He encountered the same problem as me, and I am very surprised that you didn't encounter it and could make the creation I could here on Soundcloud (thanx for the link).
So, with this new Python file, I can create my dsp file now. But now, when I run it (on the Faust Online Editor ... I'm a windows user ;-) .... ) the following error message appears : *BoxIdent[take] is defined here : https://faust.grame.fr/tools/editor/libraries/basics.lib:589 <https://faust.grame.fr/tools/editor/libraries/basics.lib:589>* As I understand it, the compiler is trying to redefine *ba.take *which is a function already known in the standard lib. So, it doesn't want to do it.... but I can't see why the compiler is considering that using a loop is re-defining a function !!! The only time ba.take is used is in this case : modeT60 = par(i,nModes,ba.take(i+1,t60)); I attached the (simple) dsp file. Any Faust-user has an idea ? Thanks Virginie Le lun. 21 janv. 2019 à 00:05, Sébastien Clara <[email protected]> a écrit : > 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 > >
#!/usr/bin/env python # -*- coding: utf-8 -*- # id2dsp.py # Copyright Pierre-Amaury Grumiaux, Pierre Jouvelot, Emilio Jesus Gallego Arias, # Romain Michon and Jakob Dübel 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 print("Reading wav file...") (fs, x) = read(soundFile) if x.shape[1] == 2: x = x[:, 0] # Normalizing sound x = x/np.max(x) # FFT print("Computing FFT...") X = np.abs(np.fft.fft(x)) X = X/(np.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 print("Detecting FFT 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/(np.max(peaksGains)) #Computing t60 values print("Calculating 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 peakst60.append(6.91/fs/(1-math.exp(-math.pi*bandwidth/fs))) print("Frequency peaks and corresponding gains and T60 has been successfully calculated.") # Writing the dsp file # # ####################### print("Writing the dsp file...") file = open(modelName + ".dsp", "w") file.write("// -*-Faust-*-\n") file.write("// generated with ir2dsp.py {0} {1} {2}\n".format(modelName, peakThreshold, peakDistance)) file.write("declare name \"{0}\";\n".format(modelName)) file.write("import(\"stdfaust.lib\");\n") file.write("nModes = ") file.write(str(len(peaksGains))) 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("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(modelName) file.write("=pm.modalModel(nModes,modeFreqs,modeT60,modeGains);"); file.write('\ngate = button("gate");') file.write("\nprocess = pm.impulseExcitation(gate) : " + modelName + " <: _,_; ") file.close(); print(modelName + ".dsp has been successfully created!")
test_model2.dsp
Description: Binary data
_______________________________________________ Faudiostream-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/faudiostream-users
