mirror of
https://github.com/cookiengineer/audacity
synced 2025-08-01 08:29:27 +02:00
new version from Steve
This commit is contained in:
parent
15f9695d18
commit
cf0869ff85
@ -2,22 +2,24 @@
|
|||||||
;version 3
|
;version 3
|
||||||
;type analyze
|
;type analyze
|
||||||
;name "Sample Data Export..."
|
;name "Sample Data Export..."
|
||||||
;action "Processing..."
|
;action "Analyzing..."
|
||||||
;categories "http://lv2plug.in/ns/lv2core#AnalyserPlugin"
|
;categories "http://lv2plug.in/ns/lv2core#AnalyserPlugin"
|
||||||
;info "by Steve Daulton. Released under GPL v2"
|
;info "by Steve Daulton. Released under GPL v2."
|
||||||
|
|
||||||
;; sample-data-export.ny by Steve Daulton June 2012.
|
;; sample-data-export.ny by Steve Daulton June 2012.
|
||||||
|
;; Updated July 16 2012.
|
||||||
;; Released under terms of the GNU General Public License version 2:
|
;; Released under terms of the GNU General Public License version 2:
|
||||||
;; http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
;; http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||||
|
;;
|
||||||
|
;; For information about writing and modifying Nyquist plug-ins:
|
||||||
|
;; http://wiki.audacityteam.org/wiki/Nyquist_Plug-ins_Reference
|
||||||
|
|
||||||
|
|
||||||
;control help "Show Help File" choice "No,Overview,File Format,Header Text,Output Files,Save Help File" 0
|
|
||||||
;control number "Limit output to first" string "samples" "100"
|
;control number "Limit output to first" string "samples" "100"
|
||||||
;control units "Measurement scale" choice "dB,Linear" 0
|
;control units "Measurement scale" choice "dB,Linear" 0
|
||||||
;control fileformat "File data format" choice "Sample List (txt),Indexed List (txt),Time Indexed (txt),Data (csv),Web Page (html)" 0
|
;control fileformat "File data format" choice "Sample List (txt),Indexed List (txt),Time Indexed (txt),Data (csv),Web Page (html)" 0
|
||||||
;control header "Include header information" choice "None,Minimal,Standard,All" 2
|
;control header "Include header information" choice "None,Minimal,Standard,All" 2
|
||||||
;control optext "Optional header text" string ""
|
;control optext "Optional header text" string ""
|
||||||
;control chan "Channel layout for stereo" choice "Alternate Lines,L Channel First" 1
|
;control chan "Channel layout for stereo" choice "L-R on Same Line,Alternate Lines,L Channel First" 0
|
||||||
;control messages "Show messages" choice "Yes,Errors Only,None" 0
|
;control messages "Show messages" choice "Yes,Errors Only,None" 0
|
||||||
;control filename "File name" string "" "sample-data"
|
;control filename "File name" string "" "sample-data"
|
||||||
;control path "Output folder" string "" "Home directory"
|
;control path "Output folder" string "" "Home directory"
|
||||||
@ -27,7 +29,7 @@
|
|||||||
;; To enable L/R prefix before alternate L/R channels
|
;; To enable L/R prefix before alternate L/R channels
|
||||||
;; (text output with header only)
|
;; (text output with header only)
|
||||||
;; remove the semicolon from the start of the next line:
|
;; remove the semicolon from the start of the next line:
|
||||||
;(setq LR-prefix 1)
|
;(setq LR-prefix '("L: " "R: "))
|
||||||
|
|
||||||
(when (not (boundp 'LR-prefix))(setq LR-prefix nil))
|
(when (not (boundp 'LR-prefix))(setq LR-prefix nil))
|
||||||
|
|
||||||
@ -98,7 +100,6 @@
|
|||||||
(get-env "HOME"))) ; Mac / Linux
|
(get-env "HOME"))) ; Mac / Linux
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;;; Check if Windows
|
;;; Check if Windows
|
||||||
(defun windowsp ()
|
(defun windowsp ()
|
||||||
(char= #\\ *file-separator*))
|
(char= #\\ *file-separator*))
|
||||||
@ -131,18 +132,25 @@
|
|||||||
(snd-fetch snd))) ; linear scale
|
(snd-fetch snd))) ; linear scale
|
||||||
|
|
||||||
|
|
||||||
;; fileformat 0=Text List, 1=Indexed List, 2=Time Indexed, 3=CSV, (4=html but not used here)
|
;; fileformat 0=Text List, 1=Indexed List, 2=Time Indexed, 3=CSV,
|
||||||
(defun formatprint (val snd)
|
;; (4=html but not used here).
|
||||||
|
;; Optional 'same' [line] argument is either 'true' or 'nil'
|
||||||
|
(defun formatprint (val snd &optional same)
|
||||||
(case fileformat
|
(case fileformat
|
||||||
(0 (format fp "~a~%" ; text list
|
(0 (format fp "~a~a" ; text list
|
||||||
(snd-get snd units)))
|
(snd-get snd units)
|
||||||
(1 (format fp "~a\t~a~%" ; indexed list
|
(if same "\t" "\n")))
|
||||||
val (snd-get snd units)))
|
(1 (format fp "~a\t~a~a" ; indexed list
|
||||||
(2 (format fp "~a\t~a~%" ; time index
|
val
|
||||||
|
(snd-get snd units)
|
||||||
|
(if same "\t" "\n")))
|
||||||
|
(2 (format fp "~a\t~a~a" ; time index
|
||||||
(/ (1- val) *sound-srate*)
|
(/ (1- val) *sound-srate*)
|
||||||
(snd-get snd units)))
|
(snd-get snd units)
|
||||||
(3 (format fp "~a," ; csv
|
(if same "\t" "\n")))
|
||||||
(snd-get snd units)))))
|
(3 (format fp "~a~a" ; csv
|
||||||
|
(snd-get snd units)
|
||||||
|
(if (or (= chan 2) same) "," "\n")))))
|
||||||
|
|
||||||
|
|
||||||
;;; Print sample data to file
|
;;; Print sample data to file
|
||||||
@ -154,12 +162,13 @@
|
|||||||
;; option to prefix alternate lines with L/R
|
;; option to prefix alternate lines with L/R
|
||||||
(when LR-prefix
|
(when LR-prefix
|
||||||
(unless (or (= header 0)(= fileformat 3))
|
(unless (or (= header 0)(= fileformat 3))
|
||||||
(format fp "L ")))
|
(format fp "~a" (first LR-prefix))))
|
||||||
(formatprint n (aref s-in 0))
|
(if (= chan 0) ; IF 'Same Line' then "True"
|
||||||
;; option to prefix alternate lines with L/R
|
(formatprint n (aref s-in 0) T)
|
||||||
|
(formatprint n (aref s-in 0)))
|
||||||
(when LR-prefix
|
(when LR-prefix
|
||||||
(unless (or (= header 0)(= fileformat 3))
|
(unless (or (= header 0)(= fileformat 3))
|
||||||
(format fp "R ")))
|
(format fp "~a" (second LR-prefix))))
|
||||||
(formatprint n (aref s-in 1)))
|
(formatprint n (aref s-in 1)))
|
||||||
(formatprint n s-in))))
|
(formatprint n s-in))))
|
||||||
|
|
||||||
@ -172,7 +181,7 @@
|
|||||||
(2 (format t (normhead))(format fp (normhead)))
|
(2 (format t (normhead))(format fp (normhead)))
|
||||||
(3 (format t (normhead))(format fp (fullhead))))
|
(3 (format t (normhead))(format fp (fullhead))))
|
||||||
;; Stereo and left channel first
|
;; Stereo and left channel first
|
||||||
(if (and (arrayp s)(= chan 1))
|
(if (and (arrayp s)(= chan 2))
|
||||||
(progn
|
(progn
|
||||||
(unless (= header 0) ; Don't print 'channel' if no header
|
(unless (= header 0) ; Don't print 'channel' if no header
|
||||||
(format fp "Left Channel.~%~%"))
|
(format fp "Left Channel.~%~%"))
|
||||||
@ -204,43 +213,35 @@
|
|||||||
(3 ".csv")
|
(3 ".csv")
|
||||||
(4 ".html")
|
(4 ".html")
|
||||||
(T ".txt")))
|
(T ".txt")))
|
||||||
|
; file separator as string
|
||||||
;; file separator as string
|
|
||||||
(setq fileseparator (format nil "~a" *file-separator*))
|
(setq fileseparator (format nil "~a" *file-separator*))
|
||||||
|
|
||||||
;; strip file separator and spaces
|
;; strip file separator and spaces
|
||||||
(let ((stuff (format nil " ~a" *file-separator*)))
|
(let ((stuff (format nil " ~a" *file-separator*)))
|
||||||
(setq filename (string-left-trim stuff filename))
|
(setq filename (string-left-trim stuff filename))
|
||||||
(setq path (string-right-trim stuff path)))
|
(setq path (string-right-trim stuff path)))
|
||||||
|
|
||||||
;; strip file extension if present
|
;; strip file extension if present
|
||||||
(if (and (>= (length filename)(length FileExt))
|
(if (and (>= (length filename)(length FileExt))
|
||||||
(string-equal filename FileExt :start1 (- (length filename)(length FileExt))))
|
(string-equal filename FileExt :start1 (- (length filename)(length FileExt))))
|
||||||
(setq filename (subseq filename 0 (- (length filename)(length FileExt)))))
|
(setq filename (subseq filename 0 (- (length filename)(length FileExt)))))
|
||||||
|
|
||||||
;; replace ~/ on Linux/Max
|
;; replace ~/ on Linux/Max
|
||||||
(if (and (>= (length path) 2)(not (windowsp)))
|
(if (and (>= (length path) 2)
|
||||||
|
(not (windowsp)))
|
||||||
(if (string-equal path "~/" :end1 2)
|
(if (string-equal path "~/" :end1 2)
|
||||||
(setq path (strcat (home)(subseq path 1)))))
|
(setq path (strcat (home)(subseq path 1)))))
|
||||||
|
|
||||||
;; If path not set use home directory
|
;; If path not set use home directory
|
||||||
(if (or (string-equal path "Home directory")
|
(if (or (string-equal path "Home directory")
|
||||||
(string-equal path ""))
|
(string-equal path ""))
|
||||||
(setq path (home)))
|
(setq path (home)))
|
||||||
|
|
||||||
;; if file name not set use default
|
;; if file name not set use default
|
||||||
(if (string-equal filename "")
|
(if (string-equal filename "")
|
||||||
(setq filename default-filename))
|
(setq filename default-filename))
|
||||||
|
|
||||||
(setdir (strcat path fileseparator)) ; set target directory
|
(setdir (strcat path fileseparator)) ; set target directory
|
||||||
|
|
||||||
;; set file pointer or error
|
;; set file pointer or error
|
||||||
(let ((realdir (string-right-trim fileseparator (setdir "."))))
|
(let ((realdir (string-right-trim fileseparator (setdir "."))))
|
||||||
(if (or
|
(if (or (string= path realdir)
|
||||||
(and (or (windowsp) ; case insensitive
|
(and (or (windowsp) ; case insensitive
|
||||||
(macp)) ; assume case insensitive
|
(macp)) ; assume case insensitive
|
||||||
(string-equal path realdir))
|
(string-equal path realdir)))
|
||||||
(string= path realdir))
|
|
||||||
;; makefilename or error
|
;; makefilename or error
|
||||||
(setq filename (makefilename filename FileExt))
|
(setq filename (makefilename filename FileExt))
|
||||||
(add-error (format nil "Output folder \"~a~a\" cannot be accessed."
|
(add-error (format nil "Output folder \"~a~a\" cannot be accessed."
|
||||||
@ -255,113 +256,7 @@
|
|||||||
path fileseparator filename)))))
|
path fileseparator filename)))))
|
||||||
|
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;; Header text
|
||||||
;; HELP FILES ;;
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
||||||
|
|
||||||
(defun help-page (page)
|
|
||||||
(case page
|
|
||||||
(1
|
|
||||||
"OVERVIEW.
|
|
||||||
Sample Data Export reads the values of successive
|
|
||||||
samples from the selected audio and prints to a
|
|
||||||
file. Additional information may be added as a
|
|
||||||
'header' at the top of the page.\n
|
|
||||||
HELP SCREENS:
|
|
||||||
Select only one track before viewing to avoid
|
|
||||||
repeated help screens. To run the plug-in set the
|
|
||||||
help option to \"No\".
|
|
||||||
Select \"Save Help File\" to write all help screens
|
|
||||||
to a printable file.\n
|
|
||||||
LIMIT OUTPUT TO FIRST (maximum number of samples):
|
|
||||||
Enter a number to limit the number of samples
|
|
||||||
processed from the selection. The maximum number
|
|
||||||
of samples is 1 million, but files this large may
|
|
||||||
be hard to open. The track sample rate indicates
|
|
||||||
the number of samples per second.\n
|
|
||||||
LINEAR/dB SCALE:
|
|
||||||
Sample values may be displayed on a linear scale
|
|
||||||
+/- 1 (as in the Audacity audio track \"Waveform\"
|
|
||||||
view) or on a dB scale relative to full scale (as
|
|
||||||
in the \"Waveform (dB)\" view).")
|
|
||||||
|
|
||||||
(2
|
|
||||||
"FILE FORMAT.\n
|
|
||||||
Following any header information:\n
|
|
||||||
SAMPLE LIST: produces a list of sample values.\n
|
|
||||||
INDEXED LIST: includes the sample number.\n
|
|
||||||
TIME INDEXED: includes the sample time.
|
|
||||||
Both types of index are relative to the start of
|
|
||||||
the selection.\n
|
|
||||||
DATA (csv): prints the sample values separated
|
|
||||||
by commas.\n
|
|
||||||
WEB PAGE (html): produces an HTML 5 document that
|
|
||||||
contains all of the header information and a table
|
|
||||||
of sample data with sample number, time, linear
|
|
||||||
and dB values. Browsers that are not HTML 5
|
|
||||||
compliant may not display the page correctly.\n
|
|
||||||
CHANNEL LAYOUT: for text/csv output, stereo tracks
|
|
||||||
may be printed alternate left/right samples or all
|
|
||||||
of left channel then all of right channel.")
|
|
||||||
|
|
||||||
(3
|
|
||||||
"OPTIONAL HEADER TEXT:
|
|
||||||
This is provided for adding notes to the output
|
|
||||||
file. In text files, use ~~% to start a new line,
|
|
||||||
in HTML files use <br>.\n
|
|
||||||
NO HEADER: Prints only the optional header text
|
|
||||||
(leave blank for none) followed by the sample data.\n
|
|
||||||
MINIMAL HEADER:
|
|
||||||
The sample rate.
|
|
||||||
Units (linear or dB).
|
|
||||||
Optional header text (leave blank for none).\n
|
|
||||||
STANDARD HEADER: minimal header plus:
|
|
||||||
File name.
|
|
||||||
Number of samples.
|
|
||||||
Duration (seconds).
|
|
||||||
Mono/Stereo.\n
|
|
||||||
FULL HEADER: standard header plus:
|
|
||||||
peak amplitude linear and dB.
|
|
||||||
Unweighted rms level (dB).
|
|
||||||
DC offset.")
|
|
||||||
|
|
||||||
(4 (format nil
|
|
||||||
"OUTPUT FILES.\n
|
|
||||||
The default output folder is the \"home folder\":
|
|
||||||
~a
|
|
||||||
To select a different output folder, enter the
|
|
||||||
full path name. The output folder must exist.\n
|
|
||||||
By default, files will not be overwritten. If you
|
|
||||||
select multiple tracks, they will be saved to
|
|
||||||
separate files with a number appended to the
|
|
||||||
name. If you set \"Allow files to be overwritten\"
|
|
||||||
to \"Yes\", only the last file for multiple tracks
|
|
||||||
will be retained.\n
|
|
||||||
A notification message is displayed on completion
|
|
||||||
indicating the name and location of the file.\n
|
|
||||||
If the plug-in is used in a Chain (Audacity 2.0.1
|
|
||||||
or later) it may be useful to disable messages.\n
|
|
||||||
For text/csv output the file header is shown in
|
|
||||||
the debug window."
|
|
||||||
(home)))))
|
|
||||||
|
|
||||||
|
|
||||||
(defun help (page)
|
|
||||||
(let ((helptext (help-page page)))
|
|
||||||
(format nil helptext)))
|
|
||||||
|
|
||||||
(defun printhelp ()
|
|
||||||
(do ((page 1 (1+ page)))
|
|
||||||
((> page 4))
|
|
||||||
(format fp "~a~%~%~%"(help-page page)))
|
|
||||||
(close fp)
|
|
||||||
(format nil "Help file written to:~%~a~a~a"
|
|
||||||
path fileseparator filename))
|
|
||||||
|
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
||||||
;; Header text ;;
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
||||||
|
|
||||||
(defun nohead ()
|
(defun nohead ()
|
||||||
(if (> (length optext) 0)
|
(if (> (length optext) 0)
|
||||||
@ -379,7 +274,7 @@ the debug window."
|
|||||||
(get 'info 'chan-order) ; Channel Order
|
(get 'info 'chan-order) ; Channel Order
|
||||||
(if (> (length optext) 0)
|
(if (> (length optext) 0)
|
||||||
(format nil "~a~%~%~%" optext) ; optional text
|
(format nil "~a~%~%~%" optext) ; optional text
|
||||||
(format nil "~%~%")))) ; no optional text
|
(format nil "~%")))) ; no optional text
|
||||||
|
|
||||||
|
|
||||||
(defun normhead ()
|
(defun normhead ()
|
||||||
@ -627,46 +522,46 @@ Daulton (<a href=
|
|||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
|
||||||
|
;;; basic info for headers
|
||||||
|
(defun put-head-info ()
|
||||||
|
(putprop 'info (truncate *sound-srate*) 'srate)
|
||||||
|
(putprop 'info (if (= units 0) "dB" "linear") 'units)
|
||||||
|
(putprop 'info (/ number *sound-srate*) 'duration)
|
||||||
|
(putprop 'info
|
||||||
|
(if (arrayp s)
|
||||||
|
"2 channels (stereo)""1 channel (mono)")
|
||||||
|
'channels)
|
||||||
|
;; stereo sample order
|
||||||
|
(putprop 'info
|
||||||
|
(cond
|
||||||
|
((and (= fileformat 3)(= chan 0)) ; csv, channel in column
|
||||||
|
"One column per channel.\n")
|
||||||
|
((and (= fileformat 3)(= chan 2)) ; csv, channel in row
|
||||||
|
"One row per channel.\n")
|
||||||
|
((or (soundp s)(= fileformat 4)) ; mono soundor HTML
|
||||||
|
"")
|
||||||
|
((= chan 0) "Left channel then Right channel on same line.\n")
|
||||||
|
((= chan 1) "Left and right channels on alternate lines.\n")
|
||||||
|
((= chan 2) "Left channel first then right channel.\n")
|
||||||
|
(T "Unspecified channel order"))
|
||||||
|
'chan-order))
|
||||||
|
|
||||||
|
|
||||||
;;; get number from string
|
;;; get number from string
|
||||||
(setq number (read (make-string-input-stream number)))
|
(setq number (read (make-string-input-stream number)))
|
||||||
(if (numberp number)
|
(if (numberp number)
|
||||||
(checknumber)
|
(checknumber)
|
||||||
(add-error (format nil "~a is not a number." number)))
|
(add-error (format nil "~a is not a number." number)))
|
||||||
|
|
||||||
(case help
|
|
||||||
(0 (filewriter)
|
|
||||||
(if (> (length err) 0)
|
|
||||||
;; output error message if enabled
|
|
||||||
(unless (= messages 2)
|
|
||||||
(format nil "Error.~%~a" err))
|
|
||||||
;; else print to file
|
|
||||||
(progn
|
|
||||||
;; basic info for headers
|
|
||||||
(putprop 'info (truncate *sound-srate*) 'srate)
|
|
||||||
(putprop 'info (if (= units 0) "dB" "linear") 'units)
|
|
||||||
(putprop 'info (/ number *sound-srate*) 'duration)
|
|
||||||
(putprop 'info
|
|
||||||
(if (arrayp s) "2 channels (stereo)""1 channel (mono)")
|
|
||||||
'channels)
|
|
||||||
(putprop 'info
|
|
||||||
(if (arrayp s)
|
|
||||||
(if (= chan 0)
|
|
||||||
(if (= fileformat 3)
|
|
||||||
"Alternate Left/Right samples.\n"
|
|
||||||
"Left and right channels on alternate lines.\n")
|
|
||||||
"Left channel first then right channel.\n")
|
|
||||||
"")
|
|
||||||
'chan-order)
|
|
||||||
(if (= fileformat 4)
|
|
||||||
(printhtml) ; html output
|
|
||||||
(printdata))))) ; text output
|
|
||||||
(1 (help 1))
|
|
||||||
(2 (help 2))
|
|
||||||
(3 (help 3))
|
|
||||||
(4 (help 4))
|
|
||||||
(5 (setq fileformat ".txt")
|
|
||||||
(setq filename "SampleDataExport_Help")
|
|
||||||
(filewriter)
|
(filewriter)
|
||||||
(if (> (length err) 0)
|
(if (> (length err) 0)
|
||||||
(format nil "Error.~%~a" err)
|
;; output error message if enabled
|
||||||
(printhelp))))
|
(if (= messages 2)
|
||||||
|
(s-rest 0) ; return nul sound
|
||||||
|
(format nil "Error.~%~a" err)) ; return errors
|
||||||
|
;; else print to file
|
||||||
|
(progn
|
||||||
|
(put-head-info) ; put basic info for headers
|
||||||
|
(if (= fileformat 4)
|
||||||
|
(printhtml) ; html output
|
||||||
|
(printdata)))) ; text output
|
||||||
|
Loading…
x
Reference in New Issue
Block a user