From 4f1a73ed584f0f74d6b32241f02ae871f3415f4a Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 9 Oct 2013 09:03:39 +0000 Subject: dtas-partstats: initial implementation dtas-partstats divides large audio files into small partitions (10 seconds by default) and runs the "stats" effect of sox(1) against each partition. Currently it emits space-delimited output, but configurable output options (including Sequel/SQLite) support is coming. The intended use of this tool is for quickly finding the loudest portions of a given recording without the need for a graphical viewer. This can be useful for selectively applying (and testing the results of) dynamic range compression filters. Use with sort(1) in a pipeline is recommended in this scenario (but again, Sequel support is coming). --- bin/dtas-partstats | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 bin/dtas-partstats (limited to 'bin') diff --git a/bin/dtas-partstats b/bin/dtas-partstats new file mode 100755 index 0000000..e29ec73 --- /dev/null +++ b/bin/dtas-partstats @@ -0,0 +1,39 @@ +#!/usr/bin/env ruby +# Copyright (C) 2013, Eric Wong and all contributors +# License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt) +# TODO +# - option parsing: sox effects, stats effect options +# - support piping out to external processes +# - configurable output formatting +# - Sequel/SQLite support +require 'dtas/partstats' +infile = ARGV[0] or abort "usage: #$0 INFILE" +ps = DTAS::PartStats.new(infile) +opts = { + jobs: `nproc 2>/dev/null || echo 2`.to_i +} +stats = ps.run(opts) + +headers = ps.key_idx.to_a +headers = headers.sort_by! { |(n,i)| i }.map! { |(n,_)| n } +width = ps.key_width +print " time " +puts(headers.map do |h| + cols = width[h] + sprintf("% #{(cols * 6)+cols-1}s", h.tr(' ','_')) +end.join(" | ")) + +stats.each do |row| + trim_part = row.shift + print "#{trim_part.hhmmss} " + puts(row.map do |group| + group.map do |f| + case f + when Float + sprintf("% 6.2f", f) + else + sprintf("% 6s", f) + end + end.join(" ") + end.join(" | ")) +end -- cgit v1.2.3-24-ge0c7