lib/beats/audio_engine.rb
# Generates the sample data for a single track, using the specified sound's sample data.
Generates the sample data for a single track, using the specified sound's sample data.
Generates the sample data for a single track using the specified sound ' s sample data .
def generate_track_sample_data(track, sound)
      trigger_step_lengths = track.trigger_step_lengths
      if trigger_step_lengths == [0]
        return {primary: [], overflow: []}    
      end
      fill_value = (@kit.num_channels == 1) ? 0 : Array.new(@kit.num_channels, 0)
      primary_sample_data = [].fill(fill_value, 0, AudioUtils.step_start_sample(track.step_count, @step_sample_length))
      step_index = trigger_step_lengths[0]
      trigger_sample_length = 0
      trigger_step_lengths[1...(trigger_step_lengths.length)].each do |trigger_step_length|
        start_sample = AudioUtils.step_start_sample(step_index, @step_sample_length)
        end_sample = [(start_sample + sound.length), primary_sample_data.length].min
        trigger_sample_length = end_sample - start_sample
        primary_sample_data[start_sample...end_sample] = sound[0...trigger_sample_length]
        step_index += trigger_step_length
      end
      overflow_sample_data = (sound == [] || trigger_step_lengths.length == 1) ? [] : sound[trigger_sample_length...(sound.length)]
      {primary: primary_sample_data, overflow: overflow_sample_data}
    end
def generate_track_sample_data ( track , sound ) trigger_step_lengths = track . trigger_step_lengths if trigger_step_lengths == [ 0 ] return { primary : [ ] , overflow : [ ] } end fill_value = ( @kit . num_channels == 1 ) ? 0 : Array . new ( @kit . num_channels , 0 ) primary_sample_data = [ ] . fill ( fill_value , 0 , AudioUtils . step_start_sample ( track . step_count , @step_sample_length ) ) step_index = trigger_step_lengths [ 0 ] trigger_sample_length = 0 trigger_step_lengths [ 1 ... ( trigger_step_lengths . length ) ] . each do | trigger_step_length | start_sample = AudioUtils . step_start_sample ( step_index , @step_sample_length ) end_sample = [ ( start_sample + sound . length ) , primary_sample_data . length ] . min trigger_sample_length = end_sample - start_sample primary_sample_data [ start_sample ... end_sample ] = sound [ 0 ... trigger_sample_length ] step_index += trigger_step_length end overflow_sample_data = ( sound == [ ] || trigger_step_lengths . length == 1 ) ? [ ] : sound [ trigger_sample_length ... ( sound . length ) ] { primary : primary_sample_data , overflow : overflow_sample_data } end
Generates the sample data for a single track, using the specified sound's sample data.
Generates the sample data for a single track using the specified sound ' s sample data .
# Is this really what should happen? Why throw away overflow?
track
sound