annotate src/matlab/chromsynth.m @ 0:c52bc3e8d3ad tip

user: boblsturm branch 'default' added README.md added assets/.DS_Store added assets/playButton.jpg added assets/stopButton.png added assets/swapButton.jpg added data/.DS_Store added data/fiveoctaves.mp3 added data/glock2.wav added data/sinScale.mp3 added data/speech_female.mp3 added data/sweep.wav added nimfks.m.lnk added src/.DS_Store added src/matlab/.DS_Store added src/matlab/AnalysisCache.m added src/matlab/CSS.m added src/matlab/DataHash.m added src/matlab/ExistsInCache.m added src/matlab/KLDivCost.m added src/matlab/LoadFromCache.m added src/matlab/SA_B_NMF.m added src/matlab/SaveInCache.m added src/matlab/Sound.m added src/matlab/SynthesisCache.m added src/matlab/chromagram_E.m added src/matlab/chromagram_IF.m added src/matlab/chromagram_P.m added src/matlab/chromsynth.m added src/matlab/computeSTFTFeat.m added src/matlab/controller.m added src/matlab/decibelSliderReleaseCallback.m added src/matlab/drawClickCallBack.m added src/matlab/fft2chromamx.m added src/matlab/hz2octs.m added src/matlab/ifgram.m added src/matlab/ifptrack.m added src/matlab/istft.m added src/matlab/nimfks.fig added src/matlab/nimfks.m added src/matlab/nmfFn.m added src/matlab/nmf_beta.m added src/matlab/nmf_divergence.m added src/matlab/nmf_euclidean.m added src/matlab/prune_corpus.m added src/matlab/rot_kernel.m added src/matlab/templateAdditionResynth.m added src/matlab/templateDelCb.m added src/matlab/templateScrollCb.m
author boblsturm
date Sun, 18 Jun 2017 06:26:13 -0400
parents
children
rev   line source
boblsturm@0 1 function [x,CF,CM] = chromsynth(F,bp,sr)
boblsturm@0 2 % [x,CF,CM] = chromsynth(F,bp,sr)
boblsturm@0 3 % Resynthesize a chroma feature vector to audio
boblsturm@0 4 % F is 12 rows x some number of columns, one per beat
boblsturm@0 5 % bp is the period of one beat in sec (or a vector of beat times)
boblsturm@0 6 % sr is the sampling rate of the output waveform
boblsturm@0 7 % x is returned as a 12 semitone-spaced sines modulated by F
boblsturm@0 8 % CF,CM return actual sinusoid matrices passed to synthtrax
boblsturm@0 9 % Actual Shepard tones now implemented! 2007-04-19
boblsturm@0 10 % 2006-07-14 dpwe@ee.columbia.edu
boblsturm@0 11
boblsturm@0 12 if nargin < 2; bp = 0.5; end % 120 bpm
boblsturm@0 13 if nargin < 3; sr = 22050; end
boblsturm@0 14
boblsturm@0 15 [nchr,nbts] = size(F);
boblsturm@0 16
boblsturm@0 17 % resynth
boblsturm@0 18 if length(bp) == 1
boblsturm@0 19 bups = 8; % upsampling factor
boblsturm@0 20 framerate = bups/bp;
boblsturm@0 21 ncols = nbts*bups;
boblsturm@0 22 CMbu = zeros(nchr, ncols);
boblsturm@0 23 for i = 1:bups
boblsturm@0 24 CMbu = CMbu + upsample(F', bups, i-1)';
boblsturm@0 25 end
boblsturm@0 26 else
boblsturm@0 27 % vector of beat times - quantize
boblsturm@0 28 framerate = 50; % frames per sec
boblsturm@0 29 nbeats = length(bp);
boblsturm@0 30 lastbeat = bp(nbeats) + (bp(nbeats) - bp(nbeats-1));
boblsturm@0 31 ncols = round(lastbeat * framerate);
boblsturm@0 32 CMbu = zeros(nchr, ncols);
boblsturm@0 33 xF = [zeros(12,1),F];
boblsturm@0 34 for i = 1:ncols
boblsturm@0 35 CMbu(:,i) = xF(:,max(find(i/framerate >= [0,bp])));
boblsturm@0 36 end
boblsturm@0 37 end
boblsturm@0 38
boblsturm@0 39 %CFbu = repmat(440*2.^([0:(nchr-1)]'/nchr),1,ncols);
boblsturm@0 40 %x = synthtrax(CFbu,CMbu,sr,round(sr/framerate));
boblsturm@0 41 octs = 7;
boblsturm@0 42 basefrq = 27.5; % A1; +6 octaves = 3520
boblsturm@0 43 CFbu = repmat(basefrq*2.^([0:(nchr-1)]'/nchr),1,ncols);
boblsturm@0 44 CF = [];
boblsturm@0 45 CM = [];
boblsturm@0 46 % what bin is the center freq?
boblsturm@0 47 f_ctr = 440;
boblsturm@0 48 f_sd = 0.5;
boblsturm@0 49 f_bins = basefrq*2.^([0:(nchr*octs - 1)]/nchr);
boblsturm@0 50 f_dist = log(f_bins/f_ctr)/log(2)/f_sd;
boblsturm@0 51 % actually just = ([0:(nchr*octs - 1)]/nchr-log2(f_ctr/basefrq))/f_sd
boblsturm@0 52 % Gaussian weighting centered of f_ctr, with f_sd
boblsturm@0 53 f_wts = exp(-0.5*f_dist.^2);
boblsturm@0 54 for oct = 1:octs
boblsturm@0 55 CF = [CF;(2^oct)*CFbu];
boblsturm@0 56 % pick out particular weights
boblsturm@0 57 CM = [CM;diag(f_wts((oct-1)*nchr+[1:nchr]))*CMbu];
boblsturm@0 58 end
boblsturm@0 59 % Remove sines above nyquist
boblsturm@0 60 CFok = (CF(:,1) < sr/2);
boblsturm@0 61 CF = CF(CFok,:);
boblsturm@0 62 CM = CM(CFok,:);
boblsturm@0 63 % Synth the sines
boblsturm@0 64 x = synthtrax(CF,CM,sr,round(sr/framerate));
boblsturm@0 65
boblsturm@0 66 % Playing synth along with audio:
boblsturm@0 67 %>> rdc = chromsynth(Dy.F(:,160+[1:300]),Dy.bts(160+[1:300]) - Dy.bts(160),sr);
boblsturm@0 68 %>> Dy.bts(161)*sr
boblsturm@0 69 %ans =
boblsturm@0 70 % 279104
boblsturm@0 71 %>> size(rdc)
boblsturm@0 72 %ans =
boblsturm@0 73 % 1 498401
boblsturm@0 74 %>> ddd = db(279104+[1:498401]);
boblsturm@0 75 %>> soundsc([ddd,rdc'/40],sr)