Skip to content

Commit 6002632

Browse files
committed
Minor tweaking here and there
1 parent 5be6611 commit 6002632

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

src/main.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,17 @@ fn main() {
7171

7272
let (glossary, keys) = sound::build_glossary(input_filename, &detectors);
7373

74-
74+
let sum: usize = keys
75+
.iter()
76+
.map(|opt|
77+
match opt {
78+
&Some(ref key) => key.bits().iter().map(|b| b as usize).sum(),
79+
&None => 0,
80+
}
81+
)
82+
.sum();
83+
84+
println!("total key length {}", sum);
7585

7686
// for (key, value) in dictionary.iter() {
7787
// //println!("{:?} -> {:?}\n", key, value);

src/memory.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ impl FragmentKey {
132132
pub fn from_bitvec(bits: BitVec) -> FragmentKey {
133133
FragmentKey(SparseBitVec::from_bitvec(bits))
134134
}
135+
136+
pub fn bits(&self) -> &BitVec {
137+
self.0.bits()
138+
}
135139
}
136140

137141
/// Amount of spectrum slices per single fragment
@@ -279,7 +283,7 @@ impl<'a> Dictionary<'a> {
279283
let phase = spectrum[index].arg();
280284

281285
let compress = |a| {
282-
if a > -60. && a < -15. {
286+
if a > -50. && a < -15. {
283287
a + 10.
284288
} else {
285289
a

src/sound.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
use num_complex::*;
33
use num_traits::Float;
44

5+
use std::rc::Rc;
56
use std::f32::consts::PI;
67
use std::io::{Read};
78
use dft;
@@ -203,13 +204,13 @@ const SLICE_OFFSET: usize = (NUM_POINTS / 2) / SLICES_PER_FRAME;
203204
const SLICES_PER_FRAGMENT: usize = SLICES_PER_FRAME / FRAGMENTS_PER_FRAME;
204205
const FRAGMENT_WINDOW: (f32, f32) = (350., 500.);
205206

206-
const SIMILARITY: usize = 80;
207+
const SIMILARITY: usize = 60;
207208

208209
type KeyVec = Vec<Option<FragmentKey>>;
209210

210211
pub fn build_glossary<'d>(filename: &str, detectors: &'d [Detector]) -> (Glossary<'d>, KeyVec) {
211212
// (100, 199), (200, 299), ... (1900, 1999)
212-
let regions: Vec<_> = (1 .. 13).into_iter().map(|i: u32| (i as f32 * 100., i as f32 * 100. + 99.)).collect();
213+
let regions: Vec<_> = (1 .. 33).into_iter().map(|i: u32| (i as f32 * 100., i as f32 * 100. + 99.)).collect();
213214
let mut dictionaries: Vec<_> = regions.iter().map(|r| Dictionary::new(detectors, r.0, r.1)).collect();
214215

215216
let plan = dft::Plan::new(dft::Operation::Forward, NUM_POINTS);
@@ -225,7 +226,8 @@ pub fn build_glossary<'d>(filename: &str, detectors: &'d [Detector]) -> (Glossar
225226
.samples::<i16>()
226227
.map(|s| Cplx::new(s.unwrap() as f32 / i16::max_value() as f32, 0.0))
227228
.collect_chunks::<Samples>(NUM_POINTS / 2)
228-
.tuple_windows() // FIXME eliminate cloning. Rc<Samples> maybe?
229+
.map(|chunk| Rc::new(chunk)) // Wrap into Rc for cheap cloning
230+
.tuple_windows()
229231
{
230232
if first.len() < NUM_POINTS / 2 || second.len() < NUM_POINTS / 2 {
231233
break;

0 commit comments

Comments
 (0)