}
}
- pub fn from_camera (&mut self) {
+ pub fn read_camera (&mut self) {
let frame = self.camera.frame().unwrap();
println!("{}", frame.resolution());
- self.camera_buffer = frame.buffer()[..].try_into().expect("Image is wrong size");
+ self.camera_buffer = frame.buffer()[..].into();
unsafe {
ProcessCapture (
}
}
- pub fn from_buffer (&mut self, buffer: &Vec<Complex<f32>>) -> () {
+ pub fn read_buffer (&mut self, buffer: &[Complex<f32>]) {
let mut r: f32;
let mut theta: f32;
let mut amplitude: f32;
}
}
- pub fn to_buffer (&mut self, buffer: &mut Vec<Complex<f32>>) -> () {
+ pub fn write_buffer (&mut self, buffer: &mut [Complex<f32>]) {
let mut r: f32;
let mut amplitude: f32;
use rustfft::{Fft, FftDirection};
use rustfft::num_complex::Complex;
use show_image::{ImageView, ImageInfo, create_window, event};
-use hound;
use cpal::{StreamConfig, BufferSize, SampleRate};
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
use std::sync::{Arc, Mutex};
let stream = device.build_output_stream(
&StreamConfig{
channels: 2,
- sample_rate: SampleRate{0: file_rate},
+ sample_rate: SampleRate(file_rate),
buffer_size: BufferSize::Fixed(WINDOW_SIZE as u32)
},
move |data: &mut [i16], _: &cpal::OutputCallbackInfo| {
for x in buffer.iter_mut() {
*x *= 1f32 / WINDOW_SIZE as f32;
}
- image_array.from_buffer(&mut buffer);
+ image_array.read_buffer(&buffer);
// show the image on screen
let image = ImageView::new(ImageInfo::rgb8(WINDOW_SIZE as u32, CHUNK_SIZE as u32), &image_array.data);
display_window.set_image ("image", image)?;
// capture and transform camera view to image
- image_array.from_camera();
+ image_array.read_camera();
// make and display debug image
if DEBUG_MODE {
}
// convert image to audio
- image_array.to_buffer(&mut buffer);
- inverse_transform.process_with_scratch(&mut *buffer, &mut scratch);
+ image_array.write_buffer(&mut buffer);
+ inverse_transform.process_with_scratch(&mut buffer, &mut scratch);
// when a "true" is receved by rx, get lock for sample buffer and fill the last half with the audio
if rx.recv().unwrap() {
i = 0;
}
- let value = match sample {
- Ok(t) => t,
- Err(_) => 0i16
- };
+ let value = sample.unwrap_or_default();
// if buffer is not full convert value and add to buffer
buffer[i] = Complex{re: value as f32, im: 0f32};
i += 1;