17.01.2013 Views

musicdsp.org source code archive - WSInf

musicdsp.org source code archive - WSInf

musicdsp.org source code archive - WSInf

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

matlab/octave <strong>code</strong> for minblep table generation (click this to go back to the index)<br />

References : Posted by dfl[at]ccrma[dot]stanford[dot]edu<br />

Notes :<br />

When I tested this <strong>code</strong>, it was running with each function in a separate file... so it might need some tweaking (endfunction statements?) if you try and<br />

run it all as one file.<br />

Enjoy!<br />

PS There's a C++ version by Daniel Werner here.<br />

http://www.experimentalscene.com/?type=2&id=1<br />

Not sure if it the output is any different than my version.<br />

(eg no thresholding in minphase calculation)<br />

Code :<br />

% Octave/Matlab <strong>code</strong> to generate a minblep table for bandlimited synthesis<br />

%% original minblep technique described by Eli Brandt:<br />

%% http://www.cs.cmu.edu/~eli/L/icmc01/hardsync.html<br />

% (c) David Lowenfels 2004<br />

% you may use this <strong>code</strong> freely to generate your tables,<br />

% but please send me a free copy of the software that you<br />

% make with it, or at least send me an email to say hello<br />

% and put my name in the software credits :)<br />

% (IIRC: mps and clipdb functions are from Julius Smith)<br />

% usage:<br />

% fc = dilation factor<br />

% Nzc = number of zero crossings<br />

% omega = oversampling factor<br />

% thresh = dB threshold for minimum phase calc<br />

mbtable = minblep( fc, Nzc, omega, thresh );<br />

mblen = length( mbtable );<br />

save -binary mbtable.mat mbtable ktable nzc mblen;<br />

*********************************************<br />

function [out] = minblep( fc, Nzc, omega, thresh )<br />

out = filter( 1, [1 -1], minblip( fc, Nzc, omega, thresh ) );<br />

len = length( out );<br />

normal = mean( out( floor(len*0.7):len ) )<br />

out = out / normal; %% normalize<br />

%% now truncate so it ends at proper phase cycle for minimum discontinuity<br />

thresh = 1e-6;<br />

for i = len:-1:len-1000<br />

% pause<br />

a = out(i) - thresh - 1;<br />

b = out(i-1) - thresh - 1;<br />

%i<br />

if( (abs(a) < thresh) & (a > b) )<br />

break;<br />

endif<br />

endfor<br />

%out = out';<br />

out = out(1:i);<br />

*********************************************<br />

function [out] = minblip( fc, Nzc, omega, thresh )<br />

if (nargin < 4 )<br />

thresh = -100;<br />

end<br />

if (nargin < 3 )<br />

omega = 64;<br />

end<br />

if (nargin < 2 )<br />

Nzc = 16;<br />

end<br />

if (nargin < 1 )<br />

fc = 0.9;<br />

end<br />

blip = sinctable( omega, Nzc, fc );<br />

%% length(blip) must be nextpow2! (if fc < 1 );<br />

mag = fft( blip );<br />

out = real( ifft( mps( mag, thresh ) ) );<br />

*********************************************<br />

function [sm] = mps(s, thresh)<br />

% [sm] = mps(s)<br />

% create minimum-phase spectrum sm from complex spectrum s

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!