everything related to duct tape audio suite (dtas)
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: <dtas-all@nongnu.org>
Subject: [PATCH] trimfx: comments and cleanups
Date: Mon, 29 Dec 2014 04:26:09 +0000	[thread overview]
Message-ID: <1419827169-20555-4-git-send-email-e@80x24.org> (raw)

It's been a while, and I've lost my train of thought regarding
this system a bit :<
---
 lib/dtas/trimfx.rb | 38 ++++++++++++++++++++++++++++++--------
 1 file changed, 30 insertions(+), 8 deletions(-)

diff --git a/lib/dtas/trimfx.rb b/lib/dtas/trimfx.rb
index d94d52a..d875c75 100644
--- a/lib/dtas/trimfx.rb
+++ b/lib/dtas/trimfx.rb
@@ -59,15 +59,16 @@ class DTAS::TrimFX
     end
   end
 
+  # tries to interpret "trim" time args the same way the sox trim effect does
+  # This takes _time_ arguments only, not sample counts;
+  # otherwise, deviations from sox are considered bugs in dtas
   def parse_trim!(args)
     tbeg = parse_time(args.shift)
     if args[0] =~ /\A=?[\d\.]+\z/
       tlen = args.shift
       is_stop_time = tlen.sub!(/\A=/, "") ? true : false
       tlen = parse_time(tlen)
-      if is_stop_time
-        tlen = tlen - tbeg
-      end
+      tlen = tlen - tbeg if is_stop_time
     else
       tlen = nil
     end
@@ -87,7 +88,20 @@ class DTAS::TrimFX
     end
   end
 
-  # there'll be multiple epochs if ranges overlap
+  # sorts and converts an array of TrimFX objects into non-overlapping arrays
+  # of epochs
+  #
+  # input:
+  #   [ tfx1, tfx2, tfx3, ... ]
+  #
+  # output:
+  #   [
+  #     [ tfx1 ],         # first epoch
+  #     [ tfx2, tfx3 ],   # second epoch
+  #     ...
+  #   ]
+  # There are multiple epochs only if ranges overlap,
+  # There is only one epoch if there are no overlaps
   def self.schedule(ary)
     sorted = []
     ary.each_with_index { |tfx, i| sorted << TFXSort[tfx, i] }
@@ -96,40 +110,48 @@ class DTAS::TrimFX
     epoch = 0
     prev_end = 0
     defer = []
+
     begin
       while tfxsort = sorted.shift
         tfx = tfxsort.tfx
         if tfx.tbeg >= prev_end
+          # great, no overlap, append to the current epoch
           prev_end = tfx.tbeg + tfx.tlen
           (rv[epoch] ||= []) << tfx
         else
+          # overlapping region, we'll need a new epoch
           defer << tfxsort
         end
       end
-      if defer[0]
+
+      if defer[0] # do we need another epoch?
         epoch += 1
         sorted = defer
         defer = []
         prev_end = 0
       end
     end while sorted[0]
+
     rv
   end
 
+  # like schedule, but fills in the gaps with pass-through (no-op) TrimFX objs
+  # This does not change the number of epochs.
   def self.expand(ary, total_len)
     rv = []
-    schedule(ary).each_with_index do |sary, i|
+    schedule(ary).each_with_index do |sary, epoch|
       tip = 0
-      dst = rv[i] = []
+      dst = rv[epoch] = []
       while tfx = sary.shift
         if tfx.tbeg > tip
+          # fill in the previous gap
           nfx = new(%W(trim #{tip} =#{tfx.tbeg}))
           dst << nfx
           dst << tfx
           tip = tfx.tbeg + tfx.tlen
         end
       end
-      if tip < total_len
+      if tip < total_len # fill until the last chunk
         nfx = new(%W(trim #{tip} =#{total_len}))
         dst << nfx
       end
-- 
EW



                 reply	other threads:[~2014-12-29  4:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://80x24.org/dtas/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1419827169-20555-4-git-send-email-e@80x24.org \
    --to=e@80x24.org \
    --cc=dtas-all@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/dtas.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).