wav_to_audio auxiliary function not working
1 次查看(过去 30 天)
显示 更早的评论
At my wit's end. This program used to work for me, but now for some reason I keep getting that I cannot open the file. (Was using the same file before and no problem). I tried to just switch to wavread only and it worked but it added all sorts of complications for me to debug throughout the rest of my program, so I'd really like to get wav_to_audio working again. ANY and all help is massively appreciated! If you need more info, just say so!
Error using wavread (line 70)
Invalid Wave File. Reason: Cannot open file.
Error in wav_to_audio (line 108)
[f_audio,fs,nbits] = wavread(strcat(dirAbs,dirRel,wavfilename));
Error in test_TempogramToolbox (line 61)
[audio,sideinfo] = wav_to_audio('',dirWav,filename);
clear
close all
dirWav = 'data_wav/';
filename = 'Debussy_SonataViolinPianoGMinor-02_111_20080519-SMD-ss135-189.wav';
% filename = '110-130bpm_click.wav';
% filename = 'Faure_Op015-01_126_20100612-SMD-0-12.wav';
% filename = 'Poulenc_Valse_114_20100518-SMD-0-15.wav';
% filename = 'Schumann_Op015-03_113_20080115-SMD-0-13.wav';
%%load wav file, automatically converted to Fs = 22050 and mono
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[audio,sideinfo] = wav_to_audio('',dirWav,filename);
Fs = sideinfo.wav.fs;
%wav_to_audio function--
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if parameter.message == 1
fprintf('wav_to_audio: processing %s, ',wavfilename);
end
[pathstr,name,ext] = fileparts(wavfilename);
if strcmp(ext,'.wav')
[f_audio,fs,nbits] = wavread(strcat(dirAbs,dirRel,wavfilename));
else
error(['Unknown file format ' ext]);
end
bConverted_to_mono = 0;
if parameter.convertToMono
if size(f_audio,2)>1
bConverted_to_mono = 1;
if parameter.message == 1
fprintf('converting to mono, ');
end
switch parameter.monoConvertMode
case 'leftmost_channel'
f_audio= f_audio(:,1);
case 'rightmost_channel'
f_audio= f_audio(:,size(f_audio,2));
case 'downmix'
% pay attention to energy loss due to differences in phase
% when using this method. This is often the case for bad
% stereo mixes
nChannels = size(f_audio,2);
f_audio = sum(f_audio,2);
f_audio = f_audio / nChannels;
otherwise
disp('wav_to_audio: monoConvertMode : Unknown method')
end
end
end
bResampled = 0;
if parameter.useResampling
if (fs ~= parameter.destSamplerate)
bResampled = 1;
if parameter.message == 1
fprintf('Resampling to %d, ', parameter.destSamplerate);
end
f_audio = resample (f_audio,parameter.destSamplerate,fs,100);
fs = parameter.destSamplerate;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Update sideinfo
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
sideinfo.wav.version = 1;
sideinfo.wav.filename = wavfilename;
sideinfo.wav.dirRel = dirRel;
sideinfo.wav.size = size(f_audio,1);
sideinfo.wav.duration = (sideinfo.wav.size-1)/fs;
sideinfo.wav.energy = sum(f_audio.^2);
sideinfo.wav.fs = fs;
sideinfo.wav.nbits = nbits;
sideinfo.wav.channels = size(f_audio,2);
sideinfo.wav.resampled = bResampled;
sideinfo.wav.monoConverted = bConverted_to_mono;
if bConverted_to_mono
sideinfo.wav.monoConvertMode = parameter.monoConvertMode;
else
sideinfo.wav.monoConvertMode = 'none';
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Saving data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if parameter.save == 1
if parameter.message == 1
fprintf('Saving to file, ');
end
filename = strcat(parameter.saveFilename,'_audio');
save(strcat(parameter.saveDir,filename),'f_audio','sideinfo');
end
if parameter.message == 1
fprintf('Done\n');
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Visualization
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if parameter.vis
figure;
for k=1:sideinfo.wav.channels
if sideinfo.wav.channels > 1
subplot(sideinfo.wav.channels,1,k);
end
plot( [0:sideinfo.wav.size-1] / sideinfo.wav.fs , f_audio(:,k));
axis tight;
end
end
end
0 个评论
采纳的回答
Dinesh Iyer
2015-8-14
If you are on R2012b and higher, I would recommend using audioread because it is an improvement to wavread and it supports a lot of other file formats. Also, wavread has been deprecated in the newer releases.
Looks like wav_to_audio is using wavread internally. I am surprised that wavread works and wav_to_audio does not.
Dinesh
4 个评论
Dinesh Iyer
2015-8-17
Am not sure what this code does but the variable names dirAbs and dirRel appear to be related to the path to the files. audioread can read any file on the MATLAB path. If the file is not on the path, then a full path to the file has to be provided. Additionally, audioread requires that u specify the extension as well unlike wavread which assumed that any file given was a WAV file and so tacked on the extension automatically.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Audio and Video Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!