63 lines
1.2 KiB
Rust
63 lines
1.2 KiB
Rust
#![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::<Vec<String>>();
|
|
if argv.len() != 6
|
|
{
|
|
eprintln!("no. <length> <start> <stop> <sin.dat> <cos.dat>");
|
|
return;
|
|
}
|
|
let length = argv[1].parse::<usize>().unwrap();
|
|
let start_freq = argv[2].parse::<f32>().unwrap();
|
|
let stop_freq = argv[3].parse::<f32>().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<u8> = Vec::with_capacity(length * 4);
|
|
let mut cos_buffer:Vec<u8> = 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();
|
|
}
|