b@0: function clipfade(folder, startTime, endTime, fs) 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@0: if nargin < 4 b@0: fs = 96000; b@0: end b@0: b@0: fadeTime = 1; % fade time in seconds b@0: bitDepth = 16; b@0: slash = '/'; % depending on OS b@0: b@0: %newFolder = 'Clips'; % folder where output files will be stored b@0: % MODIFICATION: store in place, do not keep unclipped files! b@0: b@0: % list all audio files b@0: list = dir([folder slash '*.wav']); b@0: b@0: % make new folder if not present yet b@0: % if ~exist([folder slash newFolder], 'dir') % make output folder if not there b@0: % mkdir(folder, newFolder); b@0: % end b@0: b@0: for i = 1:length(list) b@0: if strcmp(list(i).name, 'bounce.wav') b@0: %disp([' ' folder slash list(i).name]); % DEBUG b@0: b@0: [audio,fsfile] = audioread([folder slash list(i).name], [startTime*fs+1 endTime*fs]); % read part of file b@0: assert(fsfile == fs); % check file has expected sampling rate b@0: b@0: Nfade = fadeTime*fs; % make fade vector (based on sampling rate) b@0: 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@0: [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@0: fadeVector'.*audio, fs, 'BitsPerSample', bitDepth); b@0: end b@0: b@0: end b@0: end