You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: pixtone.rs
    path of file: ./repos/doukutsu-rs/src/sound
    
    the code of the file until where you have to start completion: use std::collections::HashMap;

use lazy_static::lazy_static;
use vec_mut_scan::VecMutScan;

use crate::sound::pixtone_sfx::DEFAULT_PIXTONE_TABLE;
use crate::sound::stuff::cubic_interp;

lazy_static! {
    static ref WAVEFORMS: [[i8; 0x100]; 6] = {
        let mut sine = [0i8; 0x100];
        let mut triangle = [0i8; 0x100];
        let mut saw_up = [0i8; 0x100];
        let mut saw_down = [0i8; 0x100];
        let mut square = [0i8; 0x100];
        let mut random = [0i8; 0x100];

        let ref_data = include_bytes!("pixtone_ref.dat");

        unsafe {
            sine.copy_from_slice(std::mem::transmute(&ref_data[0..0x100]));
            triangle.copy_from_slice(std::mem::transmute(&ref_data[0x100..0x200]));
            saw_up.copy_from_slice(std::mem::transmute(&ref_data[0x200..0x300]));
            saw_down.copy_from_slice(std::mem::transmute(&ref_data[0x300..0x400]));
            square.copy_from_slice(std::mem::transmute(&ref_data[0x400..0x500]));
            random.copy_from_slice(std::mem::transmute(&ref_data[0x500..0x600]));
        }

        [sine, triangle, saw_up, saw_down, square, random]
    };
}

#[derive(Copy, Clone)]
pub struct Waveform {
    pub pitch: f32,
    pub level: i32,
    pub offset: i32,
    pub waveform_type: u8,

    
    pub fn synth(&self) -> Vec<i16> {
        let length = self.channels.iter().map(|c| c.length as usize).max().unwrap_or(0);
        if length == 0 {
            return Vec::new();
        }

        let mut samples = vec![0i16; length];

        for channel in &self.channels {
            if !channel.enabled {
                continue;
            }

            let mut phase = channel.carrier.offset as f32;
            let delta = 256.0 * channel.carrier.pitch as f32 / channel.length as f32;
            let carrier_wave = channel.carrier.get_waveform();
            let frequency_wave = channel.frequency.get_waveform();
            let amplitude_wave = channel.amplitude.get_waveform();

            for (i, result) in samples.iter_mut().enumerate() {
                if i == channel.length as usize {
                    break;
                }

                let s = |p: f32| -> f32 { 256.0 * p * i as f32 / channel.length as f32 };

                let carrier = carrier_wave[0xff & phase as usize] as i32 * channel.carrier.level;
                let freq = frequency_wave
                    [0xff & (channel.frequency.offset as f32 + s(channel.frequency.pitch)) as usize]
                    as i32
                    * channel.frequency.level;
                let amp = amplitude_wave[0xff & (channel.amplitude.offset as f32 + s(channel.amplitude.pitch)) as usize]
                    as i32
                    * channel.amplitude.level;

                *result = ((*result as i32)
                    + (carrier * (amp + 4096) / 4096 * channel.envelope.evaluate(s(1.0) as i32) / 4096) * 256)
                    .clamp(-32767, 32767) as i16;

                phase += delta * (1.0 + (freq as f32 / (if freq < 0 { 8192.0 } else { 2048.0 })));
            }
        }

        samples
    }