@@ -50,6 +50,13 @@ pub struct Detector {
50
50
pub phase : f32 , // phase
51
51
}
52
52
53
+ pub fn detector_freq ( index : usize ) -> f32 {
54
+ let ideal_freq = 15. + 5. * index as f32 + ( ( index as f32 - 5. ) / 16. ) . exp ( ) ;
55
+ let fft_freq = ( ideal_freq / BASE_FREQUENCY ) . trunc ( ) * BASE_FREQUENCY ;
56
+
57
+ fft_freq
58
+ }
59
+
53
60
impl Detector {
54
61
pub fn new ( freq : f32 , band : f32 , amp : f32 , phase : f32 ) -> Detector {
55
62
Detector {
@@ -204,14 +211,19 @@ const SLICE_OFFSET: usize = (NUM_POINTS / 2) / SLICES_PER_FRAME;
204
211
const SLICES_PER_FRAGMENT : usize = SLICES_PER_FRAME / FRAGMENTS_PER_FRAME ;
205
212
const FRAGMENT_WINDOW : ( f32 , f32 ) = ( 350. , 500. ) ;
206
213
207
- const SIMILARITY : usize = 60 ;
214
+ const SIMILARITY : usize = 40 ;
208
215
209
216
type KeyVec = Vec < Option < FragmentKey > > ;
210
217
211
218
pub fn build_glossary < ' d > ( filename : & str , detectors : & ' d [ Detector ] ) -> ( Glossary < ' d > , KeyVec ) {
212
219
// (100, 199), (200, 299), ... (1900, 1999)
213
- let regions: Vec < _ > = ( 1 .. 33 ) . into_iter ( ) . map ( |i : u32 | ( i as f32 * 100. , i as f32 * 100. + 99. ) ) . collect ( ) ;
214
- let mut dictionaries: Vec < _ > = regions. iter ( ) . map ( |r| Dictionary :: new ( detectors, r. 0 , r. 1 ) ) . collect ( ) ;
220
+ //let regions: Vec<_> = (1 .. 33).into_iter().map(|i: u32| (i as f32 * 100., i as f32 * 100. + 99.)).collect();
221
+ //let mut dictionaries: Vec<_> = regions.iter().map(|r| Dictionary::new(detectors, r.0, r.1)).collect();
222
+
223
+ let mut dictionaries: Vec < _ > = ( 1 .. 14 ) . into_iter ( )
224
+ . map ( |i| ( detector_freq ( i* 10 ) , detector_freq ( ( i+1 ) * 10 ) ) )
225
+ . map ( |( low, high) | Dictionary :: new ( detectors, low, high) )
226
+ . collect ( ) ;
215
227
216
228
let plan = dft:: Plan :: new ( dft:: Operation :: Forward , NUM_POINTS ) ;
217
229
let mut reader = hound:: WavReader :: open ( filename) . unwrap ( ) ;
@@ -305,7 +317,7 @@ pub fn reconstruct(filename: &str, glossary: &Glossary, keys: &KeyVec) {
305
317
let mut writer = hound:: WavWriter :: create ( filename, wav_header) . unwrap ( ) ;
306
318
307
319
let plan = dft:: Plan :: new ( dft:: Operation :: Backward , NUM_POINTS ) ;
308
- let mut max_sample = 0. ;
320
+ let mut max_sample = 0.6 ;
309
321
310
322
let mut output = Vec :: with_capacity ( NUM_POINTS ) ;
311
323
output. resize ( NUM_POINTS , Cplx :: default ( ) ) ;
0 commit comments