b@4
|
1 function clipfade(folder, starttime, endtime, fadetime, fs, bitdepth)
|
b@0
|
2 % CLIPFADE clips and fades a fragment [start end] of all audio files in
|
b@0
|
3 % a folder.
|
b@0
|
4 %
|
b@0
|
5 % folder: path to all audio files (automatically selected)
|
b@0
|
6 % start: start time in seconds
|
b@0
|
7 % end: end time in seconds
|
b@0
|
8 %
|
b@0
|
9 % by Brecht De Man at Centre for Digital Music on 25 October 2013
|
b@0
|
10
|
b@4
|
11 if nargin < 6
|
b@4
|
12 bitDepth = 24;
|
b@0
|
13 end
|
b@4
|
14 slash = '/';
|
b@0
|
15
|
b@0
|
16 % list all audio files
|
b@0
|
17 list = dir([folder slash '*.wav']);
|
b@0
|
18
|
b@4
|
19 % remove hidden files from list
|
b@4
|
20 % see http://www.mathworks.co.uk/matlabcentral/newsreader/view_thread/258220
|
b@4
|
21 for k = length(list):-1:1
|
b@4
|
22 fname = list(k).name;
|
b@4
|
23 if fname(1) == '.'
|
b@4
|
24 list(k) = [ ];
|
b@4
|
25 end
|
b@4
|
26 end
|
b@0
|
27
|
b@0
|
28 for i = 1:length(list)
|
b@0
|
29 if strcmp(list(i).name, 'bounce.wav')
|
b@0
|
30 %disp([' ' folder slash list(i).name]); % DEBUG
|
b@0
|
31
|
b@0
|
32 [audio,fsfile] = audioread([folder slash list(i).name], [startTime*fs+1 endTime*fs]); % read part of file
|
b@0
|
33 assert(fsfile == fs); % check file has expected sampling rate
|
b@0
|
34
|
b@0
|
35 Nfade = fadeTime*fs; % make fade vector (based on sampling rate)
|
b@0
|
36 fadeVector = [(1:Nfade)/Nfade ones(1,length(audio)-2*Nfade) (Nfade:-1:1)/Nfade];
|
b@0
|
37
|
b@0
|
38 % apply fading and write to new folder
|
b@0
|
39 if size(audio,2) == 2 % if stereo
|
b@0
|
40 audiowrite([folder slash list(i).name], ... %[folder slash newFolder slash list(i).name]
|
b@0
|
41 [fadeVector'.*audio(:,1) fadeVector'.*audio(:,2)], fs, 'BitsPerSample', bitDepth);
|
b@0
|
42 else % if mono
|
b@0
|
43 audiowrite([folder slash list(i).name], ... %[folder slash newFolder slash list(i).name]
|
b@0
|
44 fadeVector'.*audio, fs, 'BitsPerSample', bitDepth);
|
b@0
|
45 end
|
b@0
|
46
|
b@0
|
47 end
|
b@0
|
48 end |