b@4: function clipfade(folder, starttime, endtime, fadetime, fs, bitdepth) b@0: % CLIPFADE clips and fades a fragment [start end] of all audio files in b@0: % a folder. b@0: % b@0: % folder: path to all audio files (automatically selected) b@0: % start: start time in seconds b@0: % end: end time in seconds b@0: % b@0: % by Brecht De Man at Centre for Digital Music on 25 October 2013 b@0: b@4: if nargin < 6 b@6: bitdepth = 24; b@0: end b@4: slash = '/'; b@0: b@0: % list all audio files b@0: list = dir([folder slash '*.wav']); b@0: b@4: % remove hidden files from list b@4: % see http://www.mathworks.co.uk/matlabcentral/newsreader/view_thread/258220 b@4: for k = length(list):-1:1 b@4: fname = list(k).name; b@4: if fname(1) == '.' b@4: list(k) = [ ]; b@4: end b@4: end b@0: b@0: for i = 1:length(list) b@13: [audio,fsfile] = audioread([folder slash list(i).name], [floor(starttime*fs)+1 ceil(endtime*fs)]); % read part of file b@0: assert(fsfile == fs); % check file has expected sampling rate b@0: b@6: Nfade = fadetime*fs; % make fade vector (based on sampling rate) b@6: fadevector = [(1:Nfade)/Nfade ones(1,length(audio)-2*Nfade) (Nfade:-1:1)/Nfade]; b@0: b@0: % apply fading and write to new folder b@0: if size(audio,2) == 2 % if stereo b@0: audiowrite([folder slash list(i).name], ... %[folder slash newFolder slash list(i).name] b@6: [fadevector'.*audio(:,1) fadevector'.*audio(:,2)], fs, 'BitsPerSample', bitdepth); b@0: else % if mono b@0: audiowrite([folder slash list(i).name], ... %[folder slash newFolder slash list(i).name] b@6: fadevector'.*audio, fs, 'BitsPerSample', bitdepth); b@0: end b@0: end