Class: AudioPlayback::Playback::Mixer

Inherits:
Object
  • Object
show all
Defined in:
lib/audio-playback/playback/mixer.rb

Overview

Mix sound data

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sounds_data) ⇒ Mixer

Returns a new instance of Mixer.

Parameters:

  • sounds_data (Array<Array<Array<Integer>>>)


17
18
19
20
# File 'lib/audio-playback/playback/mixer.rb', line 17

def initialize(sounds_data)
  @data = sounds_data
  populate
end

Class Method Details

.mix(sounds_data) ⇒ Array<Array<Integer>>

Mix multiple sounds at equal amplitude

Parameters:

  • sounds_data (Array<Array<Array<Integer>>>)

Returns:

  • (Array<Array<Integer>>)


11
12
13
14
# File 'lib/audio-playback/playback/mixer.rb', line 11

def self.mix(sounds_data)
  mixer = new(sounds_data)
  mixer.mix
end

Instance Method Details

#mixArray<Array<Integer>>

Mix multiple sounds at equal amplitude

Returns:

  • (Array<Array<Integer>>)


24
25
26
# File 'lib/audio-playback/playback/mixer.rb', line 24

def mix
  (0..@length-1).to_a.map { |index| mix_frame(index) }
end