Help with Auditory Chimera Toolbox (Audio Analysis)

Hello I'm trying to understand Bertrand Delgutte's Auditory Chimera Toolbox for audio analysis & resynthesis, but the problem is the code is over 20 years old, hasn't been updated, and I'm a brand new Matlab user. This toolbox essentially analyses two waveforms and resynthesizes them. I changed wavread to audioread in the code due to wavread no longer being supported, but I can't figure out why I'm getting this error:
I understand enough of this code to know I have to fill in some of the purple strings with arguments but I'm not really sure what the green instructions on top is asking for, and specificialy where it wants me to name the two .wav files...
If anyone can clarify to me what arguments I need to fill in to run this code properly, specifically in the % areas and in the purple string areas, it would save me hours of troubleshooting this code as it already has... and if there's any more code that is outdated needs to be changed? Thanks!
Here's the code:
function make_band_chimeras(name1, name2, Nbands, do_play, do_plot)
% Synthesize and store single or multi-band auditory chimeras from pair of original signals.
% Usage: make_band_chimeras(name1, name2, Nbands, do_play, do_plot)
% name1, name2 Original signals (WAV files), Mono or Stereo.
% If the second signal is 'noise' or is not specified,
% random noise with same power spectrum as NAME1 is used
% Nbands Number of frequency bands used for synthesis.
% Can be scalar or vector, in which case one pair of
% chimeras is synthesized for each element of Nbands.
% By default Nbands = [1 8 32];
% do_play Set flag to play chimeras (default no play)
% do_plot Set flag to plot stimulus waveforms (default no plot)
%
% The function creates two WAV files to store the chimeras
% for each value of Nbands. Files are named
% 'name1_env+name2_fts-nb#' and 'name2_env+name1_fts-nb#',
% where # is the number if bands.
% The files are stored in a folder specified by the Matlab global variable
% 'ChimeraFolder'. By default, this is set to the current folder '.'
%
% Copyright Bertrand Delgutte, 1999-2000
%
if nargin == 0, error('Give names of two WAV files'); end
if nargin < 3, Nbands = [1 8 32]; end
if nargin < 4, do_play = 0; end
if nargin < 5, do_plot = 0; end
refilter = 0;
if refilter, refilt_code = '_f2'; else refilt_code = ''; end
global ChimeraFolder;
if isempty(ChimeraFolder), ChimeraFolder = '.'; end
% read original waveforms
[orig1, Fs] = audioread('motioncapturesound.wav');
nchan = size(orig1,2);
if nargin >= 2 & ~strcmp(name2, 'noise'),
[orig2, Fs2] = audioread('Rec21092812h00m48s.wav');
if Fs ~= Fs2, error('Incompatible sampling rates'); end
if size(orig2,2) ~= nchan, error('Inconsistent numbers of channels'); end
if length(orig2) < length(orig1),
orig2 = [orig2; zeros(length(orig1)-length(orig2),nchan)];
elseif length(orig2) > length(orig1),
orig1 = [orig1; zeros(length(orig2)-length(orig1),nchan)];
end
else % synthesize noise with same power spectrum as original
name2 = 'noise';
orig2 = psd_matched_noise(orig1);
orig2 = orig2/max(abs(orig2(:)));
end
if do_play, % play original sounds
disp('Playing original sounds')
tmp = [orig1; orig2];
if strcmp(computer, 'SUN4'), sunsound(tmp, Fs);
else sound(tmp, Fs); end
pause(ceil(length(tmp)/Fs))
end
if do_plot, % plot waveforms of original signals
t=[0:length(orig1)-1]*1000/Fs;
figure(1)
clf
subplot(2,1,1)
plot(t, orig1);
title(sprintf('Original "%s" Sound', name1))
subplot(2,1,2)
plot(t, orig2)
title(sprintf('Original "%s" Sound', name2))
xlabel('Time (ms)')
drawnow
end
Fmin = 80; % lower frequency of filterbank in Hz
Fmax = .4*Fs; % upper frequency of filterbank (.8 * Nyquist)
for nb = Nbands,
% determine band cutoffs equally spaced on basilar membrane
Fco = equal_xbm_bands(Fmin, Fmax, nb);
% compute multi-band chimeras
[env1_fts2, env2_fts1] = multi_band_chimera(orig1, orig2, Fco, Fs, refilter);
% normalize and save
env1_fts2 = env1_fts2./max(abs(env1_fts2(:)));
env2_fts1 = env2_fts1./max(abs(env2_fts1(:)));
chimfileA = sprintf('%s_env+%s_fts-nb%d%s.wav', name1, name2, nb, refilt_code);
chimfileB = sprintf('%s_env+%s_fts-nb%d%s.wav', name2, name1, nb, refilt_code);
audiowrite(env1_fts2, Fs, 16, [ChimeraFolder '\' chimfileA]);
audiowrite(env2_fts1, Fs, 16, [ChimeraFolder '\' chimfileB]);
if do_play, % play band chimeras
disp(sprintf('Playing %d-band chimeras', nb))
tmp = [env1_fts2; env2_fts1];
if strcmp(computer, 'SUN4'), sunsound(tmp, Fs);
else sound(tmp, Fs); end
pause(ceil(length(tmp)/Fs))
end
if do_plot, % plot waveforms of band chimeras
figure(2)
clf
subplot(2,1,1)
plot(t, env1_fts2)
xlabel('Time (ms)')
title(sprintf('%d-band Chimera ("%s" envelope, "%s" fine structure)', ...
nb, name1, name2))
subplot(2,1,2)
plot(t, env2_fts1)
xlabel('Time (ms)')
title(sprintf('%d-band Chimera ("%s" envelope, "%s" fine structure)', ...
nb, name2, name1))
drawnow
end % if do_plot
end % loop over Nbands

1 comentario

Hi Steven,
do you have a copy of the Chimera Toolbox? Im really keen to use it ... so that I can avoid having to learn Python!
Thanks in advance,
Matthew

Iniciar sesión para comentar.

Respuestas (1)

Example:
filename1 = fullfile(matlabroot, 'toolbox', 'audio', 'samples', 'Rainbow-16-8-mono-114secs.wav');
filename2 = fullfile(matlabroot, 'toolbox', 'audio', 'samples', 'RainbowNoisy-16-8-mono-114secs.wav');
make_band_chimeras(filename1, filename2)
That is, you need to pass in the path to two .wav files.

15 comentarios

Steven Rudolph
Steven Rudolph el 9 de Oct. de 2021
Editada: Steven Rudolph el 9 de Oct. de 2021
Thanks for your reply!
Not understanding, can you maybe explain this in the context of the code I provided and where to implement this? The two .wav files I'm using are in the current folder with the rest of the code, It just wants me to give a name to them somewhere in one of the arguments... ?
[orig1, Fs] = audioread('motioncapturesound.wav');
change that to
[orig1, Fs] = audioread(name1);
and change
[orig2, Fs2] = audioread('Rec21092812h00m48s.wav');
into
[orig2, Fs2] = audioread(name2);
Steven Rudolph
Steven Rudolph el 9 de Oct. de 2021
Editada: Steven Rudolph el 9 de Oct. de 2021
Hmm, still getting the error... but maybe this will help...
Here's a pic, is MATLAB not finding my .wav files in the current folder?
(I know I'm hopeless, but like I said I'm a newb and don't study Matlab for a living)
make_band_chimeras('motioncapturesound.wav', 'Rec21092812h00m48s.wav')
Gotcha so add the code you sent me in the first comment to this code? Sorry for the dumb questions, I’m a day one user and not very savvy, Where do I add this in the code so it doesn’t break anything?
do_chim_21092812
function do_chim_21092812
make_band_chimeras('motioncapturesound.wav', 'Rec21092812h00m48s.wav')
end
function make_band_chimeras(name1, name2, Nbands, do_play, do_plot)
% Synthesize and store single or multi-band auditory chimeras from pair of original signals.
% Usage: make_band_chimeras(name1, name2, Nbands, do_play, do_plot)
% name1, name2 Original signals (WAV files), Mono or Stereo.
% If the second signal is 'noise' or is not specified,
% random noise with same power spectrum as NAME1 is used
% Nbands Number of frequency bands used for synthesis.
% Can be scalar or vector, in which case one pair of
% chimeras is synthesized for each element of Nbands.
% By default Nbands = [1 8 32];
% do_play Set flag to play chimeras (default no play)
% do_plot Set flag to plot stimulus waveforms (default no plot)
%
% The function creates two WAV files to store the chimeras
% for each value of Nbands. Files are named
% 'name1_env+name2_fts-nb#' and 'name2_env+name1_fts-nb#',
% where # is the number if bands.
% The files are stored in a folder specified by the Matlab global variable
% 'ChimeraFolder'. By default, this is set to the current folder '.'
%
% Copyright Bertrand Delgutte, 1999-2000
%
if nargin == 0, error('Give names of two WAV files'); end
if nargin < 3, Nbands = [1 8 32]; end
if nargin < 4, do_play = 0; end
if nargin < 5, do_plot = 0; end
refilter = 0;
if refilter, refilt_code = '_f2'; else refilt_code = ''; end
global ChimeraFolder;
if isempty(ChimeraFolder), ChimeraFolder = '.'; end
% read original waveforms
[orig1, Fs] = audioread(name1);
nchan = size(orig1,2);
if nargin >= 2 & ~strcmp(name2, 'noise'),
[orig2, Fs2] = audioread(name2);
if Fs ~= Fs2, error('Incompatible sampling rates'); end
if size(orig2,2) ~= nchan, error('Inconsistent numbers of channels'); end
if length(orig2) < length(orig1),
orig2 = [orig2; zeros(length(orig1)-length(orig2),nchan)];
elseif length(orig2) > length(orig1),
orig1 = [orig1; zeros(length(orig2)-length(orig1),nchan)];
end
else % synthesize noise with same power spectrum as original
name2 = 'noise';
orig2 = psd_matched_noise(orig1);
orig2 = orig2/max(abs(orig2(:)));
end
if do_play, % play original sounds
disp('Playing original sounds')
tmp = [orig1; orig2];
if strcmp(computer, 'SUN4'), sunsound(tmp, Fs);
else sound(tmp, Fs); end
pause(ceil(length(tmp)/Fs))
end
if do_plot, % plot waveforms of original signals
t=[0:length(orig1)-1]*1000/Fs;
figure(1)
clf
subplot(2,1,1)
plot(t, orig1);
title(sprintf('Original "%s" Sound', name1))
subplot(2,1,2)
plot(t, orig2)
title(sprintf('Original "%s" Sound', name2))
xlabel('Time (ms)')
drawnow
end
Fmin = 80; % lower frequency of filterbank in Hz
Fmax = .4*Fs; % upper frequency of filterbank (.8 * Nyquist)
for nb = Nbands,
% determine band cutoffs equally spaced on basilar membrane
Fco = equal_xbm_bands(Fmin, Fmax, nb);
% compute multi-band chimeras
[env1_fts2, env2_fts1] = multi_band_chimera(orig1, orig2, Fco, Fs, refilter);
% normalize and save
env1_fts2 = env1_fts2./max(abs(env1_fts2(:)));
env2_fts1 = env2_fts1./max(abs(env2_fts1(:)));
chimfileA = sprintf('%s_env+%s_fts-nb%d%s.wav', name1, name2, nb, refilt_code);
chimfileB = sprintf('%s_env+%s_fts-nb%d%s.wav', name2, name1, nb, refilt_code);
audiowrite(env1_fts2, Fs, 16, [ChimeraFolder '\' chimfileA]);
audiowrite(env2_fts1, Fs, 16, [ChimeraFolder '\' chimfileB]);
if do_play, % play band chimeras
disp(sprintf('Playing %d-band chimeras', nb))
tmp = [env1_fts2; env2_fts1];
if strcmp(computer, 'SUN4'), sunsound(tmp, Fs);
else sound(tmp, Fs); end
pause(ceil(length(tmp)/Fs))
end
if do_plot, % plot waveforms of band chimeras
figure(2)
clf
subplot(2,1,1)
plot(t, env1_fts2)
xlabel('Time (ms)')
title(sprintf('%d-band Chimera ("%s" envelope, "%s" fine structure)', ...
nb, name1, name2))
subplot(2,1,2)
plot(t, env2_fts1)
xlabel('Time (ms)')
title(sprintf('%d-band Chimera ("%s" envelope, "%s" fine structure)', ...
nb, name2, name1))
drawnow
end % if do_plot
end % loop over Nbands
end
Steven Rudolph
Steven Rudolph el 9 de Oct. de 2021
Editada: Steven Rudolph el 9 de Oct. de 2021
First of all, thanks so much for accomodating me with this
When I literally copy and paste your new code, I'm now receiving this error:
changed the name and then it gave me more errors???
renamed the file do_chim_21092812.m
and then got this error:
im trying all sorts of things just can't get anything to work...
One of your wav files is mono and the other is stereo, but the program refuses to work unless both are mono or both are stereo.
Steven Rudolph
Steven Rudolph el 10 de Oct. de 2021
Editada: Steven Rudolph el 10 de Oct. de 2021
Changed them both to stereo... Now looking at this...
Don't know what the second error is referring 2 as there is only 130 lines of code in this one?
Everytime I modify something, i'm getting even more errors FML
Here's the full code again as I have it with your mods and some of my mods in case your as lost as me:
function do_chim_21092812
make_band_chimeras('Rec21092414h41m56s.wav', 'Rec21092812h00m48s.wav')
end
function make_band_chimeras(name1, name2, Nbands, do_play, do_plot)
% Synthesize and store single or multi-band auditory chimeras from pair of original signals.
% Usage: make_band_chimeras(name1, name2, Nbands, do_play, do_plot)
% name1, name2 Original signals (WAV files), Mono or Stereo.
% If the second signal is 'noise' or is not specified,
% random noise with same power spectrum as NAME1 is used
% Nbands Number of frequency bands used for synthesis.
% Can be scalar or vector, in which case one pair of
% chimeras is synthesized for each element of Nbands.
% By default Nbands = [1 8 32];
% do_play Set flag to play chimeras (default no play)
% do_plot Set flag to plot stimulus waveforms (default no plot)
%
% The function creates two WAV files to store the chimeras
% for each value of Nbands. Files are named
% 'name1_env+name2_fts-nb#' and 'name2_env+name1_fts-nb#',
% where # is the number if bands.
% The files are stored in a folder specified by the Matlab global variable
% 'ChimeraFolder'. By default, this is set to the current folder '.'
%
% Copyright Bertrand Delgutte, 1999-2000
%
if nargin == 0, error('Give names of two WAV files'); end
if nargin < 3, Nbands = [1 8 32]; end
if nargin < 4, do_play = 0; end
if nargin < 5, do_plot = 0; end
refilter = 0;
if refilter, refilt_code = '_f2'; else refilt_code = ''; end
global ChimeraFolder;
if isempty(ChimeraFolder), ChimeraFolder = '.'; end
% read original waveforms
[orig1, Fs] = audioread(name1);
nchan = size(orig1,2);
if nargin >= 2 & ~strcmp(name2, 'noise'),
[orig2, Fs2] = audioread(name2);
if Fs ~= Fs2, error('Incompatible sampling rates'); end
if size(orig2,2) ~= nchan, error('Inconsistent numbers of channels'); end
if length(orig2) < length(orig1),
orig2 = [orig2; zeros(length(orig1)-length(orig2),nchan)];
elseif length(orig2) > length(orig1),
orig1 = [orig1; zeros(length(orig2)-length(orig1),nchan)];
end
else % synthesize noise with same power spectrum as original
name2 = 'noise';
orig2 = psd_matched_noise(orig1);
orig2 = orig2/max(abs(orig2(:)));
end
if do_play, % play original sounds
disp('Playing original sounds')
tmp = [orig1; orig2];
if strcmp(computer, 'SUN4'), sunsound(tmp, Fs);
else sound(tmp, Fs); end
pause(ceil(length(tmp)/Fs))
end
if do_plot, % plot waveforms of original signals
t=[0:length(orig1)-1]*1000/Fs;
figure(1)
clf
subplot(2,1,1)
plot(t, orig1);
title(sprintf('Original "%s" Sound', name1))
subplot(2,1,2)
plot(t, orig2)
title(sprintf('Original "%s" Sound', name2))
xlabel('Time (ms)')
drawnow
end
Fmin = 80; % lower frequency of filterbank in Hz
Fmax = .4*Fs; % upper frequency of filterbank (.8 * Nyquist)
for nb = Nbands,
% determine band cutoffs equally spaced on basilar membrane
Fco = equal_xbm_bands(Fmin, Fmax, nb);
% compute multi-band chimeras
[env1_fts2, env2_fts1] = multi_band_chimera(orig1, orig2, Fco, Fs, refilter);
% normalize and save
env1_fts2 = env1_fts2./max(abs(env1_fts2(:)));
env2_fts1 = env2_fts1./max(abs(env2_fts1(:)));
chimfileA = sprintf('%s_env+%s_fts-nb%d%s.wav', name1, name2, nb, refilt_code);
chimfileB = sprintf('%s_env+%s_fts-nb%d%s.wav', name2, name1, nb, refilt_code);
audiowrite(env1_fts2, Fs, 16, [ChimeraFolder '\' chimfileA]);
audiowrite(env2_fts1, Fs, 16, [ChimeraFolder '\' chimfileB]);
if do_play, % play band chimeras
disp(sprintf('Playing %d-band chimeras', nb))
tmp = [env1_fts2; env2_fts1];
if strcmp(computer, 'SUN4'), sunsound(tmp, Fs);
else sound(tmp, Fs); end
pause(ceil(length(tmp)/Fs))
end
if do_plot, % plot waveforms of band chimeras
figure(2)
clf
subplot(2,1,1)
plot(t, env1_fts2)
xlabel('Time (ms)')
title(sprintf('%d-band Chimera ("%s" envelope, "%s" fine structure)', ...
nb, name1, name2))
subplot(2,1,2)
plot(t, env2_fts1)
xlabel('Time (ms)')
title(sprintf('%d-band Chimera ("%s" envelope, "%s" fine structure)', ...
nb, name2, name1))
drawnow
end % if do_plot
end % loop over Nbands
end
Walter Roberson
Walter Roberson el 10 de Oct. de 2021
Editada: Walter Roberson el 10 de Oct. de 2021
Change
chimfileA = sprintf('%s_env+%s_fts-nb%d%s.wav', name1, name2, nb, refilt_code);
chimfileB = sprintf('%s_env+%s_fts-nb%d%s.wav', name2, name1, nb, refilt_code);
audiowrite(env1_fts2, Fs, 16, [ChimeraFolder '\' chimfileA]);
audiowrite(env2_fts1, Fs, 16, [ChimeraFolder '\' chimfileB]);
into
chimfileA = fullfile(ChimeraFolder, sprintf('%s_env+%s_fts-nb%d%s.wav', name1, name2, nb, refilt_code));
chimfileB = fullfile(ChimeraFolder, sprintf('%s_env+%s_fts-nb%d%s.wav', name2, name1, nb, refilt_code));
audiowrite(chimfileA, env1_fts2, Fs, 'BitsPerSample', 16);
audiowrite(chimfileB, env2_fts1, Fs, 'BitsPerSample', 16);
its not liking env1_fts1?
Fixed in the posting.
You are a mad man! That worked!! : )
Now on to the rest of the toolbox.... Will start a new post if I have any more questions on that...
THANK YOU

Iniciar sesión para comentar.

Categorías

Más información sobre Audio I/O and Waveform Generation en Centro de ayuda y File Exchange.

Preguntada:

el 9 de Oct. de 2021

Comentada:

el 20 de Mayo de 2024

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by