Skip to main content

Synthesizer

Struct Synthesizer 

#[non_exhaustive]
pub struct Synthesizer {
Show 14 fields pub(crate) sound_font: Arc<SoundFont>, pub(crate) sample_rate: i32, pub(crate) block_size: usize, pub(crate) maximum_polyphony: usize, preset_lookup: HashMap<i32, usize>, default_preset: usize, channels: Vec<Channel>, voices: VoiceCollection, block_left: Vec<f32>, block_right: Vec<f32>, inverse_block_size: f32, block_read: usize, master_volume: f32, effects: Option<Effects>,
}
Expand description

An instance of the SoundFont synthesizer.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§sound_font: Arc<SoundFont>§sample_rate: i32§block_size: usize§maximum_polyphony: usize§preset_lookup: HashMap<i32, usize>§default_preset: usize§channels: Vec<Channel>§voices: VoiceCollection§block_left: Vec<f32>§block_right: Vec<f32>§inverse_block_size: f32§block_read: usize§master_volume: f32§effects: Option<Effects>

Implementations§

§

impl Synthesizer

pub const CHANNEL_COUNT: usize = 16

The number of channels.

pub const PERCUSSION_CHANNEL: usize = 9

The percussion channel.

pub fn new( sound_font: &Arc<SoundFont>, settings: &SynthesizerSettings, ) -> Result<Synthesizer, SynthesizerError>

Initializes a new synthesizer using a specified SoundFont and settings.

§Arguments
  • sound_font - The SoundFont instance.
  • settings - The settings for synthesis.

pub fn process_midi_message( &mut self, channel: i32, command: i32, data1: i32, data2: i32, )

Processes a MIDI message.

§Arguments
  • channel - The channel to which the message will be sent.
  • command - The type of the message.
  • data1 - The first data part of the message.
  • data2 - The second data part of the message.

pub fn note_off(&mut self, channel: i32, key: i32)

Stops a note.

§Arguments
  • channel - The channel of the note.
  • key - The key of the note.

pub fn note_on(&mut self, channel: i32, key: i32, velocity: i32)

Starts a note.

§Arguments
  • channel - The channel of the note.
  • key - The key of the note.
  • velocity - The velocity of the note.

pub fn note_off_all(&mut self, immediate: bool)

Stops all the notes in the specified channel.

§Arguments
  • immediate - If true, notes will stop immediately without the release sound.

pub fn note_off_all_channel(&mut self, channel: i32, immediate: bool)

Stops all the notes in the specified channel.

§Arguments
  • channel - The channel in which the notes will be stopped.
  • immediate - If true, notes will stop immediately without the release sound.

pub fn reset_all_controllers(&mut self)

Resets all the controllers.

pub fn reset_all_controllers_channel(&mut self, channel: i32)

Resets all the controllers of the specified channel.

§Arguments
  • channel - The channel to be reset.

pub fn reset(&mut self)

Resets the synthesizer.

pub fn render(&mut self, left: &mut [f32], right: &mut [f32])

Renders the waveform.

§Arguments
  • left - The buffer of the left channel to store the rendered waveform.
  • right - The buffer of the right channel to store the rendered waveform.
§Remarks

The output buffers for the left and right must be the same length.

pub fn get_sound_font(&self) -> &SoundFont

Gets the SoundFont used as the audio source.

pub fn get_sample_rate(&self) -> i32

Gets the sample rate for synthesis.

pub fn get_block_size(&self) -> usize

Gets the block size for rendering waveform.

pub fn get_maximum_polyphony(&self) -> usize

Gets the number of maximum polyphony.

pub fn get_enable_reverb_and_chorus(&self) -> bool

Gets the value indicating whether reverb and chorus are enabled.

pub fn get_master_volume(&self) -> f32

Gets the master volume.

pub fn set_master_volume(&mut self, value: f32)

Sets the master volume.

§Arguments
  • value - The new value of the master volume.

Trait Implementations§

§

impl Debug for Synthesizer

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Component for T
where T: 'static,

§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> DowncastSend for T
where T: Any + Send,

§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Sync + Send>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send> ⓘ

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
§

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

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

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

§

fn into_sample(self) -> T

§

impl<T> MaybeSync for T
where T: Sync + ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
§

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

§

fn to_sample_(self) -> U

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for T
where T: Sync,

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more