#!/usr/bin/perl # # spectrum.pl # # Copyright (C) 2007 Alberto Longhi # # This script expects, as input, a text file in 3 columns: frequency, # FFT level left channel, FFT level right channel. One such file can # be created for example with CoolEdit Pro after a "Frequency # analysis" by doing "Copy to clipboard" and pasting into a text file. # It is expected that there are 2^n data lines at equidistant # frequencies starting with zero and ending with the Nyquist # frequency, that is half of the sampling frequency. All lines not # beginning with a digit are ignored. It is also assumed, as is # conventional in programs such as CoolEdit, that the FFT level is # expressed in dB in such a way that the spectrum of a full-scale sine # wave peaks at 0 dB. # # The script does the following: # # 1. Calculates the total RMS power of the track expressed in dB # relative to the total RMS of a full-scale sine wave. # # 2. Calculates the A-weighted level dBA (also relative to the total # RMS of a full-scale sine wave). # # 3. Rearranges the spectrum so to have data points uniform in log f: # this is convenient when plotting the spectrum in logscale, so the # graphic is not burdened with overdense points in the high end of # the spectrum; when the new binning is sparser the data is # averaged and the plot is smoother, where the new binning is # denser, a stepping shows up. # # Launch without arguments to see a help message. # ------------------------------------------------------------------- # Subroutines # ------------------------------------------------------------------- # Help messages sub usage(){ print STDERR << "EOF"; Usage: spectrum.pl -f filename options spectrum.pl options < filename -f take FFT spectrum from instead of standard input -r calculate RMS -a calculate A-weighting -h show column heading (optional, with -r or -a) -l