HAudioSink
Handle to a device that outputs sounds.
Methods
new
new() -> HAudioSink
source
Creates a new HAudioSink
instance.
The sink is set on “play” mode from the start.
Returns
An HAudioSink
.
Examples
library(harmonium)
= HAudioSink$new() haudiosink
append_from_harray
append_from_harray(harray: HArray, sr: integer)
source
Appends a sound to the queue of sounds to play.
Arguments
harray
An HArray
.
sr
An integer. The audio sampling rate.
Examples
library(harmonium)
= HAudioSink$new()
haudiosink = HFile$decode(fpath = "./r-harmonium/testfiles/gs-16b-2c-44100hz.wav", dtype = HDataType$Float32)
hdecodedaudio = hdecodedaudio$harray()
harray = hdecodedaudio$sr()
sr $append_from_harray(harray, sr) haudiosink
append_from_file
append_from_file(fpath: string)
source
Appends a sound to the queue of sounds to play.
Arguments
fpath
The file path as a string
.
Examples
library(harmonium)
= HAudioSink$new()
haudiosink $append_from_file(fpath = "./r-harmonium/testfiles/gs-16b-2c-44100hz.wav") haudiosink
audio_default_device
audio_default_device() -> string
source
Informs the default audio output device.
Returns
A string
.
Examples
library(harmonium)
$audio_default_device() HAudioSink
audio_output_devices
audio_output_devices() -> characteratomicvector
source
Provides a list of available audio output devices.
Returns
A character atomic vector.
Examples
library(harmonium)
$audio_output_devices() HAudioSink
audio_supported_configs
audio_supported_configs() -> atomicvector
source
Provides the supported configurations for the default audio output device.
The following informations are given:
Number of channels.
Minimum and maximum value for the sampling rate.
Minimum and maximum value for the buffer size.
Type of data expected by the device.
Returns
A character atomic vector.
Examples
library(harmonium)
$audio_supported_configs() HAudioSink
clear
clear()
source
Removes all currently loaded Source
s from the Sink
and pauses it.
Examples
library(harmonium)
= HAudioSink$new()
haudiosink $append_from_file(fpath = "./r-harmonium/testfiles/gs-16b-2c-44100hz.wav")
haudiosink$clear()
haudiosink$is_empty() # TRUE
haudiosink$is_paused() # TRUE haudiosink
get_pos
get_pos() -> double
source
Returns the position of the sound that’s being played. This takes into account any speedup or delay applied. Example: if you apply a speedup of 2 to an mp3 decoder source and get_pos()
returns 5s then the position in the mp3 recording is 10s from its start.
Returns
A double
.
Examples
library(harmonium)
= HAudioSink$new()
haudiosink $append_from_file(fpath = "./r-harmonium/testfiles/gs-16b-2c-44100hz.wav")
haudiosink$get_pos() haudiosink
is_empty
is_empty() -> bool
source
Returns true if this sink has no more sounds to play.
Returns
A bool
.
Examples
library(harmonium)
= HAudioSink$new()
haudiosink $is_empty() # TRUE haudiosink
is_paused
is_paused() -> bool
source
Gets if a sink is paused.
Sinks can be paused and resumed using pause() and play(). This returns true if the sink is paused .
Returns
A bool
.
Examples
library(harmonium)
= HAudioSink$new()
haudiosink $append_from_file(fpath = "./r-harmonium/testfiles/gs-16b-2c-44100hz.wav")
haudiosink$is_paused() # FALSE
haudiosink$pause()
haudiosink$is_paused() # TRUE haudiosink
len
len() -> integer
source
Returns the number of sounds currently in the queue.
Returns
An integer
.
Examples
library(harmonium)
= HAudioSink$new()
haudiosink $len() == 0 # TRUE
haudiosink$append_from_file(fpath = "./r-harmonium/testfiles/gs-16b-2c-44100hz.wav")
haudiosink$append_from_file(fpath = "./r-harmonium/testfiles/gs-16b-2c-44100hz.wav")
haudiosink$len() == 2 # TRUE haudiosink
pause
pause()
source
Pauses playback of this sink.
No effect if already paused.
A paused sink can be resumed with play().
Examples
library(harmonium)
= HAudioSink$new()
haudiosink $append_from_file(fpath = "./r-harmonium/testfiles/gs-16b-2c-44100hz.wav")
haudiosink$is_paused() # FALSE
haudiosink$pause()
haudiosink$is_paused() # TRUE haudiosink
play
play()
source
Resumes playback of a paused sink.
No effect if not paused.
Examples
library(harmonium)
= HAudioSink$new()
haudiosink $append_from_file(fpath = "./r-harmonium/testfiles/gs-16b-2c-44100hz.wav")
haudiosink$pause()
haudiosink$is_paused() # TRUE
haudiosink$play()
haudiosink$is_paused() # FALSE haudiosink
set_speed
set_speed(value: double)
source
Changes the speed of the sound.
The value 1.0 is the “normal” speed (unfiltered input). Any value other than 1.0 will change the play speed of the sound.
Arguments
value
A double
.
Examples
library(harmonium)
= HAudioSink$new()
haudiosink $append_from_file(fpath = "./r-harmonium/testfiles/gs-16b-2c-44100hz.wav")
haudiosink$set_speed(2)
haudiosink$speed() == 2 # TRUE haudiosink
set_volume
set_volume(value: double)
source
Changes the volume of the sound.
The value 1.0 is the “normal” volume (unfiltered input). Any value other than 1.0 will multiply each sample by this value.
Arguments
value
A double
.
Examples
library(harmonium)
= HAudioSink$new()
haudiosink $append_from_file(fpath = "./r-harmonium/testfiles/gs-16b-2c-44100hz.wav")
haudiosink$set_volume(2)
haudiosink$volume() == 2 # TRUE haudiosink
skip_one
skip_one()
source
Skips to the next Source
in the Sink
.
If there are more Source
s appended to the Sink
at the time, it will play the next one. Otherwise, the Sink
will finish as if it had finished playing a Source
all the way through.
Examples
library(harmonium)
= HAudioSink$new()
haudiosink $append_from_file(fpath = "./r-harmonium/testfiles/gs-16b-2c-44100hz.wav")
haudiosink$append_from_file(fpath = "./r-harmonium/testfiles/gs-16b-2c-44100hz.wav")
haudiosink$len() == 2 # TRUE
haudiosink$skip_one()
haudiosink$len() == 1 # TRUE haudiosink
sleep_until_end
sleep_until_end()
source
Sleeps the current thread until the sound ends.
Examples
library(harmonium)
= HAudioSink$new()
haudiosink $append_from_file(fpath = "./r-harmonium/testfiles/gs-16b-2c-44100hz.wav")
haudiosink$sleep_until_end() haudiosink
speed
speed() -> double
source
Gets the speed of the sound.
The value 1.0 is the “normal” speed (unfiltered input). Any value other than 1.0 will change the play speed of the sound.
Returns
A double
.
Examples
library(harmonium)
= HAudioSink$new()
haudiosink $append_from_file(fpath = "./r-harmonium/testfiles/gs-16b-2c-44100hz.wav")
haudiosink$speed() haudiosink
stop
stop()
source
Stops the sink by emptying the queue.
The sink will keep its previous state (play or pause).
Examples
library(harmonium)
= HAudioSink$new()
haudiosink $append_from_file(fpath = "./r-harmonium/testfiles/gs-16b-2c-44100hz.wav")
haudiosink$append_from_file(fpath = "./r-harmonium/testfiles/gs-16b-2c-44100hz.wav")
haudiosink$len() == 2 # TRUE
haudiosink$stop()
haudiosink$len() == 0 # TRUE
haudiosink$is_paused() # FALSE haudiosink
try_seek
try_seek(pos: f64)
source
Attempts to seek to a given position in the current source.
This blocks between 0 and ~5 milliseconds.
As long as the duration of the source is known, seek is guaranteed to saturate at the end of the source. For example given a source that reports a total duration of 42 seconds calling try_seek()
with 60 seconds as argument will seek to 42 seconds.
This function will return an error if:
one of the underlying sources does not support seeking.
an implementation ran into one during the seek.
when seeking beyond the end of a source when the duration of the source is not known.
Arguments
pos
A double
. The time to seek to in seconds.
Examples
library(harmonium)
= HAudioSink$new()
haudiosink $append_from_file(fpath = "./r-harmonium/testfiles/gs-16b-2c-44100hz.wav")
haudiosink$try_seek(2) haudiosink
volume
volume() -> double
source
Gets the volume of the sound.
The value 1.0 is the “normal” volume (unfiltered input). Any value other than 1.0 will multiply each sample by this value.
Returns
A double
.
Examples
library(harmonium)
= HAudioSink$new()
haudiosink $append_from_file(fpath = "./r-harmonium/testfiles/gs-16b-2c-44100hz.wav")
haudiosink$volume() haudiosink
invalidate
invalidate()
source
Replaces the inner value of the external pointer, invalidating it. This function is useful to drop the HAudioSink
without having to calling rm()
and gc()
.
Examples
library(harmonium)
= HAudioSink$new()
haudiosink $append_from_file(fpath = "./r-harmonium/testfiles/gs-16b-2c-44100hz.wav")
haudiosink$invalidate() haudiosink