HArrayAudio

A collection of methods that can be applied to float 1D or 2D HArrays which represents audio data.

Methods

nchannels

nchannels() -> integer source

Returns the number of channels.

This is the same as the number of rows of a 1D or 2D HArray.

Returns

An integer.

Examples

library(harmonium)
arr = array(c(1,2,3,4,5,6,7,8,9,10,11,12), c(3,4))
dtype = HDataType$Float32
harray = HArray$new_from_values(arr, dtype)
HArrayAudio$nchannels(harray)

nframes

nframes() -> integer source

Returns the number of frames.

This is the same as the number of cols of a 1D or 2D HArray.

The number of frames is equivalent to the number of samples divided by the number of channels.

Returns

An integer.

Examples

library(harmonium)
arr = array(c(1,2,3,4,5,6,7,8,9,10,11,12), c(3,4))
dtype = HDataType$Float32
harray = HArray$new_from_values(arr, dtype)
HArrayAudio$nframes(harray)

db_to_amplitude

db_to_amplitude(harray: HArray, reference: double) source

Converts the HArray input from dB to amplitude.

\(db_to_amplitude(x) = reference * (10.0**(x * 0.1))**power\)

The operation is done in-place.

Arguments

  • harray

A 1D or 2D float HArray.

  • reference

A double that scales the output.

  • power

A double. If 1.0, will compute DB to power. If 0.5, will compute DB to amplitude.

Examples

library(harmonium)
arr = array(c(1,2,3,4,5,6,7,8,9,10,11,12), c(3,4))
dtype = HDataType$Float32
harray = HArray$new_from_values(arr, dtype)
HArrayAudio$db_to_amplitude(harray, 2, 1)

to_mono

to_mono(harray: HArray) source

Convert to 1 channel by taking the average across channels.

The operation is done in-place. A new inner array is created.

Arguments

  • harray

A 2D float HArray.

Examples

library(harmonium)
arr = array(c(1,2,3,4,5,6,7,8,9,10,11,12), c(3,4))
dtype = HDataType$Float32
harray = HArray$new_from_values(arr, dtype)
HArrayAudio$to_mono(harray)