📄 load_sound.sci
字号:
function [x,fs] = load_sound(name, n0, options)// load_sound - load a sound from a file.//// [x,fs] = load_sound(name, n0, options);//// Load from a .wav (windows), .au (mac) or .asc (Wavelab)// sound file.//// Some cool built in examples include// spectrogram.wav, tiger.au, bell.wav//// Copyright (c) 2006 Gabriel Peyr巈options.null = [];if argn(2)<2 n0 = [];endname = lower(name);rep = getoptions(options, 'rep', './toolbox_signal/');// find extension I = strfind(name, '.');if isempty(I) ext = []; if exist( strcat([rep name '.wav']) )==2 ext = 'wav'; end if exist( strcat([rep name '.asc']))==2 ext = 'asc'; end if exist( strcat([rep name '.au']))==2 ext = 'au'; end if isempty(ext) error('Unable to determine extension'); endelse I = I(end); ext = name(I+1:end); name = name(1:I-1);endfs = 22000/2; // sampling rateif strcmp(ext, 'asc') fid = fopen(strcat([rep name]), 'r'); if fid<0 error(['Unknown file ' name '.' ext]); end x = fscanf(fid,'%g'); fclose(fid);elseif strcmp(ext, 'wav') // MS files [x,fs,nbits] = wavread(strcat([rep name '.' ext]));elseif strcmp(ext, '.au') // Sun files [x,fs,nbits] = auread(strcat([rep name '.' ext]));else x = load_signal(name,n);endif size(x,1)<size(x,2) x = x';endif size(x,2)>1 // mono signal x = x(:,1);endx = x(:);// specific cropping to remov blankif strcmp(name, 'bird')// sel = [1:9400 6500:9000 16500:18700 26000:28500]; sel = [1:6000 12500:15000 22500:24000 32500:3400]; x(sel) = [];endif strcmp(name, 'spectrogram') x = x(5800:end);endif strcmp(name, 'aeio') x = x(15000:end);endif strcmp(name, 'acha') x = x(14000:end);endif strcmp(name,'aherohasfallen') x = x(5000:2^14+5000);endif strcmp(name,'sentence') x = x(3300:end);end// specific croppingif strcmp(name, 'tiger') x = x(2000:end);endif strcmp(name, 'drums') x = x(4800:12500);endn = size(x,1);subsampling = getoptions(options, 'subsampling', 1);if subsampling~=1 // sub-sampling 1/10 fs = fs*subsampling; t = linspace(0,1,n); ti = linspace(0,1,round(n*subsampling)); x = interp1( t,x,ti ); x = x(:);endif not(isempty(n0)) & n0<n x = x(1:n0);end// rescale to [-1,1]x = x/max(abs(x));endfunction
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -