Class Audio::Sound
In: lib/audio.rb
Parent: NArray

A Sound is a NArray with some audio convenience methods. It should always have the shape [frames,channels]. (Even when m=1)

Notice for NArray users: because most audio libraries do not agree with NArray on type names, Sound.float has a different meaning than NArray.float. Also, the shape of a new Sound is different than you might expect:

  s = Sound.float(10)
  n = NArray.float(10)
  s.shape                   #=> [10,1]
  n.shape                   #=> [10]
  s.typecode                #=> 4
  n.typecode                #=> 5

Methods

Constants

TYPES = [nil,:char,:short,:long,:float,:double]   Mapping from typecode to type symbols

External Aliases

char -> byte
short -> sint
long -> int
float -> sfloat

Public Class methods

Creates a new Sound with the specified number of channels from the interleaved data in narray. narray should be evenly divisible by channels.

typecode:Same as NArray, or a member of TYPES
frames:Number of frames
channels:Number of channels

Note that the resulting shape is always [frames,channels].

Public Instance methods

Returns a new Sound with the data from channel i

The number of channels

A frame, i.e. an array containing the samples at position i from each channel. For a two-channel sound:

  sound.frame(i) #=> [0.42, 0.12]

You may prefer to do this the NArray way: s[i,false]

The number of frames

Return a Sound with the channels interleaved.

  Sound[[0,1],[2,3]].interleaved #=> Sound[[0,2,1,3]]

Fill this Sound‘s channels with deinterleaved data.

  Sound[[0,0],[0,0]].interleaved = NArray[0,2,1,3] #=> Sound[[0,1],[2,3]]
interleaved()

Alias for interleave

interleaved=(o)

Alias for interleave=

For a two-channel sound:

  s.set_frame(i,[0.42,0.24])
  s.set_frame(i,0.42) #=> s.set_frame(i,[0.42,0.42])

You may prefer to do this the NArray way: s[i,false] = val

One of TYPES

[Validate]