Mercurial > hg > may
changeset 477:e23b26580c98
Slightly lower filter cutoff when downsampling
author | Chris Cannam |
---|---|
date | Fri, 01 Nov 2013 10:45:41 +0000 |
parents | fb39f266d810 |
children | b4a47848d274 493d7bfc58ca |
files | src/may/stream/resample.yeti src/may/stream/test/test_resample.yeti |
diffstat | 2 files changed, 8 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/src/may/stream/resample.yeti Thu Oct 31 18:25:33 2013 +0000 +++ b/src/may/stream/resample.yeti Fri Nov 01 10:45:41 2013 +0000 @@ -70,10 +70,9 @@ adjuster = durationAdjusterFor (1/factor) s; bandwidth = 0.02; fparams = { -// n = factor / (1 - bandwidth/2), - n = factor, + n = factor / (1 - bandwidth/2), attenuation = 80, - bandwidth = 0.02, + bandwidth, samplerate = 1, }; filter = kaiserSincFilterFor fparams; @@ -81,8 +80,9 @@ (convolve.convolvedWith [Framesize 1024] (mat.newMatrix (RowMajor ()) (map \filter [1..s.channels])) s); delay = -(int ((vec.length filter) / 4)); + scaleFactor = 1 / fparams.n; out = adjuster - (manip.scaledBy (1/factor) + (manip.scaledBy scaleFactor (manip.delayedBy delay (manip.picked factor filtered))); out with { get sampleRate () = s.sampleRate / factor }; @@ -144,8 +144,7 @@ // slightly lower (depending on the bandwidth) bandwidth = 0.02; { -// n = peakToPole / (1 - bandwidth/2), - n = peakToPole, + n = peakToPole / (1 - bandwidth/2), attenuation = 100, bandwidth, samplerate = (higher / g), @@ -331,7 +330,7 @@ read n = (rowdata = array (map \(new double[n]) [1..s.channels]); obtained = fill rowdata n; - scaleFactor = min 1.0 (targetRate / sourceRate); + scaleFactor = (targetRate / g) / fparams.n; result = mat.newMatrix (RowMajor ()) (map do r: bf.scaled scaleFactor (vec.vector r) done rowdata); if obtained < n then mat.columnSlice result 0 obtained
--- a/src/may/stream/test/test_resample.yeti Thu Oct 31 18:25:33 2013 +0000 +++ b/src/may/stream/test/test_resample.yeti Fri Nov 01 10:45:41 2013 +0000 @@ -164,9 +164,9 @@ outform = resample.resampledTo outrate forms[1]; incount = inrate; outcount = outrate; - // We don't compare bins within 1% of the Nyquist freq speclen = (min incount outcount) / 2; - speclen = speclen - int (speclen / 100); + // We don't compare bins within 4% of the Nyquist freq + speclen = speclen - int (speclen / 25); inmag = specOf (sigOf inform incount) incount speclen; outmag = specOf (sigOf outform outcount) outcount speclen; compareMatrices 1e-7