#!/usr/bin/perl -w #use strict; #use strict 'refs'; my $Debug = 1; # Copyright (C) 2001,2002 Britton Leo Kerin (fsblk@aurora.alaska.edu) # Copyright (C) 2004 Filip Gieszczykiewicz (www.repairfaq.org) # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA # 02111-1307, USA. # http://repairfaq.ece.drexel.edu/filipg/soundgrab/ # (fmg) added the '1', '2', 'adjust', 'verify', 'huh', 'oggment *', # exporting to lame (MP3), sox effects options, 'name *' # and various hacks/tweaks/ports. My goal was to # allow basic "file templates" to be preserved and tweaked. # You may be familar with 'templates' if you use OCR software. # A typical 3 hour show on AM, breaks on-the-hour and most of the # commercials are on a somewhat fixed schedule (+/- few min) so # these additions allow for 'cleaning up' of such things... # I usually copy the previous show's '.sg' file to the new one # and then make some adjustments. I use the text interface # exclusively, at the moment. # GUI/X/Gtk # I found several versions floating # on the web called gsoundgrab which used Gtk[1] GUI. I split the # two interfaces off (don't like bloated, half-assed efforts) and # beat Gtk2 support into gsoungrab2 and ported over most of the # functionality from tsoundgrab2. # # # Changelog: # 0.9.0-f1 2/28/04: added '1' and '2' # 0.9.0-f2 3/1/04: added 'adjust', 'huh' :-) # 0.9.0-f3 3/2/04: added 'set' to 'adjust' and 'list' to 'oggment' # 0.9.0-f4 3/5/04: bug-fixes and cleanup, also '*' to 'name' and # auto chunk name on load ('2'), giving argument to # mark gives usual warning AND mark position and # delta. Added setting time to 'mark'. # 0.9.0-f5 3/6/04: seems 'set locale' figures into key sorts! Fixed # that and some other bugs. Did another 45 hrs of # FM music edits. # 0.9.0-f6 3/10/04: split off text and GUI ports, added support for # export to 'lame' (MP3), added fade to sox, fixed # docs/comments of pipe commands. Also added # '--automatic' argument! # 0.9.0-f7 11/04: added "space" to "list" so that I can tell quickly # how many units are between chunks (so as to predict next) # Also fixed up my prior hacks to work smoother + no warn'igs. # 0.9.0-f8 01/05: added rawplay_signal (KILL vs TERM) because on linux # with ALSA drivers gave 3 seconds latency in stop_core() and # KILL is instant - don't see any problems. # # Locale matters! Copy 4 lines between ---'s and run... same? nope! # This affects the sorting of keys in hashes, too... took me for a spin. # ------------- # use locale; # print +(sort grep /\w/, map { chr } 0..255), "\n"; # no locale; # print +(sort grep /\w/, map { chr } 0..255), "\n"; # ------------- # Would be nice: # * if pgm prompt changed if mark was set =head1 NAME soundgrab - interactively select and save sections of an audio file =cut use diagnostics; use Fcntl qw(:seek); use File::Basename qw(basename fileparse); use FileHandle; use Getopt::Long qw(GetOptions); use Pod::Usage qw(pod2usage); use POSIX qw(:errno_h :signal_h :sys_wait_h floor ceil); use Text::ParseWords qw(parse_line shellwords); # Replace the normal time function with one returning a high-res # float. Don't ask exactly what the resolution is; this is chainsaw # real-time here. use Time::HiRes qw(time); my $progname = basename($0); my $version = "0.9.0-f8"; =head1 SYNOPSIS B [option]... [I] =head1 DESCRIPTION B is a perl script which runs the rawrec and sox and possibly the oggenc, flac, and lame (MP3) executables to let the user play back a raw audio file and interactively select and export portions of the file to other files. By default, the input file should contain 2 interleaved channels of signed 16 bit little- endian raw audio data sampled at 44.1 kHz. A variety of output formats are available (some depend on the presence of certain encoder binaries in the users path). =head1 INHERENT ADVANTAGES The power of B is that it I reads the volume into memory. This means that you can quickly mark up a 10 GB file on a machine with 128MB ram[1]. You can also postpone the CPU-intensive export and encoding of the individual chunks for later. Using B involves two separate steps: =over 2 =item B: Select and describe chunks (and save to .sg file) In this step, you interactively peruse the volume, set or adjust the Start and End positions of chunks, and assign names and other information (like Title, Artist, etc. for ogg or mp3) to these chunks. You may, optionally, load or save these chunk definitions from or to a '.sg' file. This allows you to postpone B or use a generic 'template' .sg file. This step does not need much system memory and is also easy on the CPU. =item B: 'export' the chunks to individual files [and encode] In this step, B uses the powerful B
command to access the volume in a random-access manner and copy the chunks to separate files. If you decide to export to ogg or mp3, this step may be very CPU intensive and the various encoders may use substancial amounts of memory. You may schedule this task with the I command to take place, for example, at 1 A.M. =head1 OPTIONS AND ARGUMENTS =over 4 =item B<-b> I, B<--ogg-kbitrate>=I Files exported in the Ogg Vorbis lossy compression format should use approximately I kilobits per second encoding. =item B<--ogg-bitrate>=I Deprecated. Use B<--ogg-kbitrate> instead. =item B<-c> I, B<--channels>=I The file on which soundgrab is to operate contains I-channel data. One channel is mono, two is stereo. Modern sound cards may support 4 or more channels. The default is 2. =item B<-d>, I, B<--audio-device>=I Use I instead of the default /dev/dsp. =item B<-f>, I, B<--output-file-format>=I The arguments to the export command (see online help) that do not end in a known dot extension should be saved in format I in a file with the appropriate dot extension appended. I may be one of the following strings: =over 4 =item B CD Mastering format. This is two channel unsigned sixteen bit little endian data with some blocking and padding. =item B FLAC lossless compressed format. =item B Ogg vorbis lossy compressed format. =item B Lame lossy compressed format. =item B Raw data samples in the format specified with the B option at the sampling rate specified with the B option and containing the number of channels specified with the B option. If any of these options were not specied the default for that option is used. =back The default for this option is B. The flac and ogg formats are only available if the appropriate encoder is present on the system. =item B<-i> I, B<--input-sample-format>=I The samples for the individual channels in the argument file are in format I, where I is one of the following strings: =over 4 =item B Signed sixteen bit little endian format. =item B Unsigned eight bit. =back =item B<-s> I, B<--sampling-rate>=I The data in the argument file was sampled at I samples per second. =item B<-t> I