From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS22989 208.118.235.0/24 X-Spam-Status: No, score=-2.4 required=3.0 tests=AWL,BAYES_00 shortcircuit=no autolearn=unavailable version=3.3.2 X-Original-To: dtas-all@80x24.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 4AF51633819 for ; Mon, 29 Dec 2014 04:26:19 +0000 (UTC) Received: from localhost ([::1]:60140 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y5RuM-0002KO-EL for dtas-all@80x24.org; Sun, 28 Dec 2014 23:26:18 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34915) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y5RuK-0002KE-9t for dtas-all@nongnu.org; Sun, 28 Dec 2014 23:26:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y5RuI-0007f2-2q for dtas-all@nongnu.org; Sun, 28 Dec 2014 23:26:16 -0500 Received: from dcvr.yhbt.net ([64.71.152.64]:60652) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y5RuH-0007ek-To for dtas-all@nongnu.org; Sun, 28 Dec 2014 23:26:14 -0500 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 8D37F633819 for ; Mon, 29 Dec 2014 04:26:10 +0000 (UTC) From: Eric Wong To: Subject: [PATCH] trimfx: comments and cleanups Date: Mon, 29 Dec 2014 04:26:09 +0000 Message-Id: <1419827169-20555-4-git-send-email-e@80x24.org> X-Mailer: git-send-email 2.2.1.202.g55b961f X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 64.71.152.64 X-BeenThere: dtas-all@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dtas-all-bounces+dtas-all=80x24.org@nongnu.org Sender: dtas-all-bounces+dtas-all=80x24.org@nongnu.org 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