Introduction
Introduction Statistics Contact Development Disclaimer Help
Update to KissFFT, fix memory corruption - warvox - VoIP based wardialing tool,…
Log
Files
Refs
README
---
commit 2fa86135084bce9519f207f26a5a084d24902bb0
parent ebfa9cc7945f832c08fdcf59f33c2271c1a550b9
Author: HD Moore <[email protected]>
Date: Thu, 5 Mar 2009 19:01:10 +0000
Update to KissFFT, fix memory corruption
Diffstat:
M src/ruby-kissfft/main.c | 29 ++++++++---------------------
M src/ruby-kissfft/test_kissfft.rb | 34 +++++++++++++++++++++--------…
2 files changed, 31 insertions(+), 32 deletions(-)
---
diff --git a/src/ruby-kissfft/main.c b/src/ruby-kissfft/main.c
@@ -42,9 +42,7 @@ rbkiss_s_fftr(VALUE class, VALUE r_nfft, VALUE r_rate, VALUE …
int n;
int sidx;
int avgctr=0;
- int remove_dc=0;
int nrows=0;
- float * vals=NULL;
int stereo=0;
int nfft;
@@ -91,9 +89,9 @@ rbkiss_s_fftr(VALUE class, VALUE r_nfft, VALUE r_rate, VALUE …
nfreqs=nfft/2+1;
CHECKNULL( cfg=kiss_fftr_alloc(nfft,0,0,0) );
- CHECKNULL( tbuf=(kiss_fft_scalar*)malloc(sizeof(kiss_fft_scalar)*nfft …
- CHECKNULL( fbuf=(kiss_fft_cpx*)malloc(sizeof(kiss_fft_cpx)*nfreqs ) );
- CHECKNULL( mag2buf=(float*)malloc(sizeof(float)*nfreqs ) );
+ CHECKNULL( tbuf=(kiss_fft_scalar*)malloc(sizeof(kiss_fft_scalar)*(nfft…
+ CHECKNULL( fbuf=(kiss_fft_cpx*)malloc(sizeof(kiss_fft_cpx)*(nfft + 2))…
+ CHECKNULL( mag2buf=(float*)malloc(sizeof(float)*(nfft + 2) ));
memset(mag2buf,0,sizeof(mag2buf)*nfreqs);
@@ -115,13 +113,6 @@ rbkiss_s_fftr(VALUE class, VALUE r_nfft, VALUE r_rate, VAL…
}
}
- // Handle DC
- if (remove_dc) {
- float avg = 0;
- for (i=0;i<nfft;++i) avg += tbuf[i];
- avg /= nfft;
- for (i=0;i<nfft;++i) tbuf[i] -= (kiss_fft_scalar)avg;
- }
/* do FFT */
kiss_fftr(cfg,tbuf,fbuf);
@@ -131,19 +122,17 @@ rbkiss_s_fftr(VALUE class, VALUE r_nfft, VALUE r_rate, VA…
}
if (++avgctr == navg) {
+ float eps = 1;
avgctr=0;
++nrows;
- vals = (float*)realloc(vals,sizeof(float)*nrows*nfreqs…
- float eps = 1;
- set = rb_ary_new();
// RESULTS
+ set = rb_ary_new();
for (i=0;i<nfreqs;++i) {
- vals[(nrows - 1) * nfreqs + i] = 10 * log10( m…
-
+ float pwr = 10 * log10( mag2buf[i] / navg + ep…
tmp = rb_ary_new();
rb_ary_push(tmp, rb_float_new( (float)i * ( ( …
- rb_ary_push(tmp, rb_float_new( vals[(nrows - 1…
+ rb_ary_push(tmp, rb_float_new( pwr));
rb_ary_push(set, tmp);
}
rb_ary_push(res, set);
@@ -152,10 +141,8 @@ rbkiss_s_fftr(VALUE class, VALUE r_nfft, VALUE r_rate, VAL…
inp_idx += nfft;
}
- cleanup:
- if(vals) free(vals);
free(cfg);
- free(tbuf);
+ free(tbuf);
free(fbuf);
free(mag2buf);
return(res);
diff --git a/src/ruby-kissfft/test_kissfft.rb b/src/ruby-kissfft/test_kissfft.rb
@@ -17,19 +17,31 @@ class KissFFT::UnitTest < Test::Unit::TestCase
puts "KissFFT version: #{KissFFT.version}"
end
def test_fftr
- data = ( [*(1..100)] * 1000).flatten
+ data = File.read('sample.data').unpack('s*')
- r = KissFFT.fftr(8192, 8000, 1, data)
- r.each do |x|
- mf = 0
- mp = 0
- x.each do |o|
- if(o[1] > mp)
- mp = o[1]
- mf = o[0]
- end
+ min = 1
+ res = KissFFT.fftr(8192, 8000, 1, data)
+
+ tones = {}
+ res.each do |x|
+ rank = x.sort{|a,b| a[1].to_i <=> b[1].to_i }.reverse
+ rank[0..10].each do |t|
+ f = t[0].round
+ p = t[1].round
+ next if f == 0
+ next if p < min
+ tones[ f ] ||= []
+ tones[ f ] << t
end
- puts "#{mf} @ #{mp}"
end
+
+ tones.keys.sort.each do |t|
+ next if tones[t].length < 2
+ puts "#{t}hz"
+ tones[t].each do |x|
+ puts "\t#{x[0]}hz @ #{x[1]}"
+ end
+ end
+
end
end
You are viewing proxied material from jay.scot. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.