resonator 0.3.2

This crate allows 2 devices to send live PCM audio data to each other through a server
Documentation
use super::parsable::Parsable;

pub struct AudioSample {
    pub value: f32
}

impl AudioSample {
    /**

     * Parses a vector of bytes into a vector of AudioSamples
     */
    pub fn parse_samples(bytes: &[u8]) -> Vec<AudioSample> {
        bytes.chunks_exact(4).map(|chunk| {
            AudioSample::from_bytes(chunk)
        }).collect()
    }
}

impl Parsable<AudioSample> for AudioSample {
    /**

     * Parses a new AudioSample using the provided byte data
     * Will ignore any bytes after the ones needed (4)
     */
    fn from_bytes(bytes: &[u8]) -> AudioSample {
        let sample = f32::from_le_bytes(bytes[0..4].try_into().unwrap());

        AudioSample {
            value: sample
        }
    }
}