[][src]Struct wavetable::wavetable::Wavetable

pub struct Wavetable {
    pub num_tables: usize,
    pub num_octaves: usize,
    pub num_values: usize,
    pub num_samples: usize,
    pub table: Vec<Vec<Float>>,
}

Fields

num_tables: usizenum_octaves: usizenum_values: usizenum_samples: usizetable: Vec<Vec<Float>>

Implementations

impl Wavetable[src]

pub fn new(
    num_tables: usize,
    num_octaves: usize,
    num_samples: usize
) -> Wavetable
[src]

Creates a new Wavetable instance.

This function allocates the memory required for storing the given number of tables.

use wavetable::Wavetable;

// Allocate a table for 4 waveshapes, each containing bandlimited
// sub-tables for 11 octaves, with each table holding 2048 samples.
let wt = Wavetable::new(4, 11, 2048);

pub fn new_from_vector(
    num_tables: usize,
    num_octaves: usize,
    num_samples: usize,
    table: Vec<Vec<Float>>
) -> WavetableRef
[src]

Create a new Wavetable using the provided sample memory.

use wavetable::Wavetable;

let num_tables = 4;
let num_octaves = 11;
let num_samples = 2048;
let num_values = num_samples + 1;
let table = vec!(vec!(0.0; num_values * num_octaves); num_tables);
let wt = Wavetable::new_from_vector(num_tables, num_octaves, num_samples, table);

pub fn get_wave(&self, wave_id: usize) -> &Vec<Float>[src]

Return the waveshape at the given index.

This will return the vector containing all octave tables for a single waveshape in the Wavetable.

use wavetable::Wavetable;
 
let wt = Wavetable::new(4, 11, 2048); // Allocate a Wavetable for 4 waveshapes
let first_wave = wt.get_wave(0);      // Get the vector holding the first waveshape

pub fn get_wave_mut(&mut self, wave_id: usize) -> &mut Vec<Float>[src]

Return a mutable vector for the selected waveshape.

This will return a mutable vector containing all octave tables for a single waveshape in the Wavetable.

use wavetable::Wavetable;

let mut wt = Wavetable::new(4, 11, 2048);    // Allocate a Wavetable for 4 waveshapes
let mut second_wave = wt.get_wave_mut(1); // Get the vector holding the second waveshape

pub fn calc_num_harmonics(base_freq: Float, sample_freq: Float) -> usize[src]

Calculates the number of non-aliasing harmonics for one octave.

Calculates all the harmonics for the octave starting at base_freq that do not exceed the Nyquist frequency.

use wavetable::Wavetable;

let num_harmonics = Wavetable::calc_num_harmonics(20.0, 100.0);
assert_eq!(num_harmonics, 1);

pub fn convert_to_harmonics(&self, num_harmonics: usize) -> Vec<Vec<Float>>[src]

Convert a wavetable to a vector of harmonics lists.

Creates one harmonic list for each waveshape in the table. The result will contain at most <num_harmonics> harmonics in the list.

use wavetable::Wavetable;
use wavetable::WtManager;

let mut wt_manager = WtManager::new(44100.0, "data");
wt_manager.add_basic_tables(0);
let wt = if let Some(table) = wt_manager.get_table(0) { table } else { panic!(); };
let harmonics = wt.convert_to_harmonics(1300);

pub fn add_sine_wave(table: &mut [Float], freq: Float, amplitude: Float)[src]

Add a sine wave with given frequency and amplitude to the buffer.

use wavetable::Wavetable;

let mut wt = Wavetable::new(4, 11, 2048);
let mut first_wave = wt.get_wave_mut(0);
let frequency = 1.0; // wavelength = buffer size
let amplitude = 1.0;
Wavetable::add_sine_wave(&mut first_wave, frequency, amplitude);

pub fn add_cosine_wave(table: &mut [Float], freq: Float, amplitude: Float)[src]

Add a cosine wave with given frequency and amplitude to the buffer.

use wavetable::Wavetable;

let mut wt = Wavetable::new(4, 11, 2048);
let mut first_wave = wt.get_wave_mut(0);
let frequency = 1.0; // wavelength = buffer size
let amplitude = 1.0;
Wavetable::add_cosine_wave(&mut first_wave, frequency, amplitude);

pub fn insert_tables(
    &mut self,
    table_id: usize,
    start_freq: Float,
    sample_freq: Float,
    insert_wave: fn(_: &mut [Float], _: Float, _: Float)
)
[src]

Create octave tables with given insert function.

Divides the given table into NUM_TABLES subtables and uses the given insert function to insert waveforms into them. Each table serves the frequency range of one octave.

pub fn get_start_frequency(base_freq: Float) -> Float[src]

Calculate the start frequency to use for wave creation.

pub fn insert_harmonics(
    &mut self,
    harmonics: &[Vec<Float>],
    sample_freq: Float
) -> Result<(), ()>
[src]

Insert a wave from a list of harmonic amplitudes.

The list of harmonics containes their relative amplitude. After adding the harmonics to the wavetable, the total amplitude will be normalized.

use wavetable::Wavetable;

let harmonics = vec![vec![0.0; 2048]];
let mut wt = Wavetable::new(1, 11, 2048);
wt.insert_harmonics(&harmonics, 44100.0);

pub fn combine_tables(
    &mut self,
    table_id: usize,
    table_a: &[Float],
    table_b: &[Float],
    offset_b: Float
)
[src]

Combine two tables by subtracting one from the other.

\param table_id ID of the target table to write to \param table_a Source table that is subtracted from \param table_b Source table that gets subtracted from table_a \param offset_b Offset into source table_b (0.0 - 1.0)

pub fn normalize(table: &mut [Float])[src]

Normalizes samples in a table to the range [-1.0,1.0].

Searches the maximum absolute value and uses it to calculate the required scale. Assumes that the values are centered around 0.0.

pub fn shift(table: &mut [Float], num_values: usize, offset: usize)[src]

Shifts all values in a table by the given offset.

pub fn expand(table: &mut [Float])[src]

Expand the samples in a table to the rage [-1.0, 1.0].

Scales and shifts a wave to fit into the target range. Uses the minimum and the maximum of the values to calculate scale factor and offset.

pub fn show(&self)[src]

Print all values of a table to the logfile.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.