#![allow(unused_parens)] use std::io::prelude::*; use std::fs::File; use std::env::args; use std::f32::consts::PI; fn main() { let argv = args().collect::>(); if argv.len() != 6 { eprintln!("no. "); return; } let length = argv[1].parse::().unwrap(); let start_freq = argv[2].parse::().unwrap(); let stop_freq = argv[3].parse::().unwrap(); let mut sin_file = File::create(&argv[4]).unwrap(); let mut cos_file = File::create(&argv[5]).unwrap(); let delta_freq = ( (stop_freq - start_freq) / ( 2.0 * (length as f32) ) ); let mut sin_buffer:Vec = Vec::with_capacity(length * 4); let mut cos_buffer:Vec = Vec::with_capacity(length * 4); for i in 0..length { sin_buffer.extend_from_slice( &( (i as f32) * PI * (start_freq + delta_freq * (i as f32)) / (length as f32) ) .sin() .to_be_bytes() ); cos_buffer.extend_from_slice( &( (i as f32) * PI * (start_freq + delta_freq * (i as f32)) / (length as f32) ) .cos() .to_be_bytes() ); } sin_file.write_all(&sin_buffer).unwrap(); cos_file.write_all(&cos_buffer).unwrap(); }