Struct cpal::Voice
[−]
[src]
pub struct Voice { /* fields omitted */ }
Controls a sound output. A typical application has one Voice
for each sound
it wants to output.
A voice must be periodically filled with new data by calling append_data
, or the sound
will stop playing.
Each Voice
is bound to a specific number of channels, samples rate, and samples format,
which can be retreived by calling get_channels
, get_samples_rate
and get_samples_format
.
If you call append_data
with values different than these, then cpal will automatically
perform a conversion on your data.
If you have the possibility, you should try to match the format of the voice.
Methods
impl Voice
[src]
fn new(endpoint: &Endpoint,
format: &Format,
event_loop: &EventLoop)
-> Result<(Voice, SamplesStream), CreationError>
format: &Format,
event_loop: &EventLoop)
-> Result<(Voice, SamplesStream), CreationError>
Builds a new channel.
fn format(&self) -> &Format
Returns the format used by the voice.
fn get_channels(&self) -> ChannelsCount
DEPRECATED: use format
instead. Returns the number of channels.
You can add data with any number of channels, but matching the voice's native format will lead to better performances.
fn get_samples_rate(&self) -> SamplesRate
DEPRECATED: use format
instead. Returns the number of samples that are played per second.
You can add data with any samples rate, but matching the voice's native format will lead to better performances.
fn get_samples_format(&self) -> SampleFormat
DEPRECATED: use format
instead. Returns the format of the samples that are accepted by the backend.
You can add data of any format, but matching the voice's native format will lead to better performances.
fn play(&mut self)
Sends a command to the audio device that it should start playing.
Has no effect is the voice was already playing.
Only call this after you have submitted some data, otherwise you may hear some glitches.
fn pause(&mut self)
Sends a command to the audio device that it should stop playing.
Has no effect is the voice was already paused.
If you call play
afterwards, the playback will resume exactly where it was.