Struct BasicSong

Source
pub struct BasicSong {
    pub notes: Vec<Note>,
    pub bpm: BPMChoice,
}
Expand description

§Deprecated

This feature has been deprecated in the latest update. Please use the new player, not the legacy one.

Basic songs are collections of Notes. Each song can export to a .wav file.

Example:

use rs_audio::*;

let mut song = BasicSong::default();
song.play().unwrap();

let mut second_song = BasicSong::new(vec![
Note { freq: 880.0, dur: 1.0, vol: 0.20, wave: WaveForm::Sine },
Note { freq: 220.0, dur: 1.0, vol: 0.20, wave: WaveForm::Square },
Note { freq: 880.0, dur: 1.0, vol: 0.20, wave: WaveForm::Sine },
Note { freq: 220.0, dur: 1.0, vol: 0.20, wave: WaveForm::Triangle },
], BPMChoice::Default);

second_song.play().unwrap(); // Uses the main thread.
second_song.export_to_wav("test.wav".to_string());

Fields§

§notes: Vec<Note>§bpm: BPMChoice

Implementations§

Source§

impl BasicSong

Source

pub fn new(notes: Vec<Note>, bpm: BPMChoice) -> Self

Source

pub fn play(&mut self) -> Result<(), Error>

Source§

impl BasicSong

Source

pub fn export_to_wav(&self, filename: String) -> Result<(), Box<dyn Error>>

§Deprecated

This feature has been deprecated in the latest update. Please use the new player, not the legacy one.

Exports a Song struct to a .wav file.
It creates a .wav file in the current directory.
Usage:

use rs_audio::*;
use rs_audio::{legacyplayer::BasicSong};

let song = BasicSong::default();
song.export_to_wav("test.wav".to_string());
Source

pub fn play_wav(file_path: &str) -> Result<(), Error>

§Deprecated

This feature has been deprecated in the latest update. Please use the new player, not the legacy one.

Plays a .wav file.

Usage:

use rs_audio::*;
use rs_audio::{legacyplayer::BasicSong};

BasicSong::play_wav("test.wav").unwrap();

Trait Implementations§

Source§

impl Default for BasicSong

Source§

fn default() -> Self

§Deprecated

This feature has been deprecated in the latest update. Please use the new player, not the legacy one.

Creates a default song that is useful for debugging purposes.

It contains a single default sine wave.
Usage:

use rs_audio::*;
let song = BasicSong::default();

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,