Skip to content

Commit

Permalink
Merge pull request #1 from JonnyBurger/main
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxPower15 committed Feb 10, 2024
2 parents bd690fe + 8e4f9d5 commit b290490
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
9 changes: 7 additions & 2 deletions calculations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def get_closest_aligned_time(target_time)
nearest_frame_index_for_target_time * frame_duration
end

def generate_command_and_directives_for_segment(index, target_start, target_end)
def generate_command_and_directives_for_segment(index, target_start, target_end, is_last)
puts "--- segment #{index + 1} ---"

start_time = get_closest_aligned_time(target_start)
Expand Down Expand Up @@ -51,7 +51,12 @@ def generate_command_and_directives_for_segment(index, target_start, target_end)

# inpoint is inclusive and outpoint is exclusive. To avoid overlap, we subtract
# the duration of one frame from the outpoint.
outpoint = inpoint + real_duration - frame_duration
# we don't have to subtract a frame if this is the last segment.
subtract = frame_duration
if is_last
subtract = 0
end
outpoint = inpoint + real_duration - subtract

puts "inpoint: #{inpoint}, outpoint: #{outpoint}"

Expand Down
5 changes: 3 additions & 2 deletions run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# Feel free to change these constants for your own testing.
SINE_WAVE_DURATION = 10.to_f
SINE_FREQUENCY = 1000.to_f
SINE_FREQUENCY = 10.to_f
TARGET_SEGMENT_DURATION = 1.0.to_f
SINE_WAVE_FILE_NAME = "sine-wave-#{SINE_WAVE_DURATION.to_i}-seconds.wav"

Expand All @@ -18,7 +18,8 @@
commands_and_directives = (SINE_WAVE_DURATION / TARGET_SEGMENT_DURATION).ceil.to_i.times.map do |i|
start_time = (i * TARGET_SEGMENT_DURATION * 1000000).round.to_i
end_time = [((i + 1) * TARGET_SEGMENT_DURATION * 1000000).round, SINE_WAVE_DURATION * 1000000].min.to_i
generate_command_and_directives_for_segment(i, start_time, end_time)
is_last = i == (SINE_WAVE_DURATION / TARGET_SEGMENT_DURATION).ceil.to_i - 1
generate_command_and_directives_for_segment(i, start_time, end_time, is_last)
end

all_directives = commands_and_directives.map { |cmd, directives| directives }.join("\n")
Expand Down

0 comments on commit b290490

Please sign in to comment.