changeset 1:dbcf9bc275e3 draft

planemo upload commit 063e049d569aeb45e1008cbf044f2dad850eca3d-dirty
author stevecassidy
date Wed, 07 Dec 2016 19:10:51 -0500
parents 6d6dc275b107
children 6f4db0e89117
files g_cepstrum.R g_cepstrum.xml g_f0.R g_f0.xml g_forest.R g_forest.xml get_fm_at_midpoint.xml outputAssp.R r_wrapper.sh util.R
diffstat 10 files changed, 352 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/g_cepstrum.R	Wed Dec 07 19:10:51 2016 -0500
@@ -0,0 +1,26 @@
+
+library(wrassp)
+
+args = commandArgs(TRUE)
+# args will be like
+#        ${wavfile} ${output}
+#        ${beginTime} ${endTime}
+#        ${windowShift} ${window} ${resolution}
+#        ${fftLength}
+
+
+if (length(args) != 8) {
+    print("Wrong number of arguments!")
+    q("no", status=1)
+}
+
+res = cepstrum(args[1], toFile=FALSE,
+               beginTime=as.numeric(args[3]),
+               endTime=as.numeric(args[4]),
+               windowShift=as.numeric(args[5]),
+               window=args[6],
+               resolution=as.numeric(args[7]),
+               fftLength=as.numeric(args[8])
+             )
+
+assp_to_tsv(res, args[2])
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/g_cepstrum.xml	Wed Dec 07 19:10:51 2016 -0500
@@ -0,0 +1,67 @@
+<tool id="g_cepstrum" name="Compute Cepstrum" version="0.01">
+    <description>using wrassp</description>
+
+    <requirements>
+        <requirement type="package" version="3.2.1">R</requirement>
+        <requirement type="package" version="0.1.4">r-wrassp</requirement>
+    </requirements>
+
+    <command interpreter="bash">
+        r_wrapper.sh $__tool_directory__/g_cepstrum.R --args ${wavfile} ${output}
+        ${beginTime} ${endTime} ${windowShift} ${window} ${resolution}
+        ${fftLength}
+     </command>
+
+    <inputs>
+        <param name="wavfile" type="data" format="wav" label="Audio File" help="Audio file in WAV format"/>
+        <param name="beginTime" type="integer" value="0" label="Start time for analysis (s)"/>
+        <param name="endTime" type="integer" value="0" label="End Time for analysis (s) 0 means end of signal"/>
+        <param name="windowShift" type="integer" value="5" label="Window Shift (ms)" help="set analysis window shift to dur ms"/>
+        <param name="resolution" type="integer" value="40" label="set FFT length to the smallest value which results in a frequency resolution of freq Hz or better"/>
+
+        <param name="fftLength" type="integer" value="0" label="set FFT length to num points (overrules 'resolution' option)"/>
+        <param name="window" type="select">
+            <option value="BLACKMAN" selected="true">Blackman</option>
+            <option value="RECTANGLE">rectangle</option>
+            <option value="PARABOLA">parabola/Riesz/Welch</option>
+            <option value="COS"      >cosine</option>
+            <option value="HANN"     >Hann/hanning/cosine^2</option>
+            <option value="COS_4"    >cosine^4</option>
+            <option value="HAMMING"  >Hamming</option>
+            <option value="BLACK_X"  >exact Blackman</option>
+            <option value="BLACK_M3" >min. 3-term Blackman-Nuttal</option>
+            <option value="BLACK_M4" >min. 4-term Blackman-Nuttal</option>
+            <option value="NUTTAL_3" >3-term Nuttal (-18 dB/oct)</option>
+            <option value="NUTTAL_4" >4-term Nuttal (-18 dB/oct)</option>
+            <option value="KAISER2_0">Kaiser-Bessel (alpha = 2.0)</option>
+            <option value="KAISER3_0">Kaiser-Bessel (alpha = 3.0)</option>
+            <option value="KAISER4_0">Kaiser-Bessel (alpha = 4.0)</option>
+        </param>
+    </inputs>
+
+    <outputs>
+        <data name="output" format="tabular" label="#echo $wavfile.element_identifier.replace('wav', 'cep') #" />
+    </outputs>
+
+
+    <tests>
+        <test>
+            <param name="wavfile" value="1_1119_2_22_001-ch6-speaker16.wav"/>
+            <output name="output" file="1_1119_2_22_001-cepstrum.dat"/>
+        </test>
+    </tests>
+
+    <help>Short-term cepstral analysis of the signal using the Fast Fourier Transform. The number of coefficients per output record will also equal the FFT length / 2 + 1 (i.e. be non-mirrored).</help>
+
+    <citations>
+        <citation type='bibtex'>
+            @Manual{,
+              title = {wrassp: an R wrapper to the ASSP Library},
+              author = {Lasse Bombien and Raphael Winkelmann and Michel
+                Scheffers},
+              year = {2016},
+              note = {R package version 0.1.4},
+            }
+        </citation>
+    </citations>
+</tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/g_f0.R	Wed Dec 07 19:10:51 2016 -0500
@@ -0,0 +1,25 @@
+
+library(wrassp)
+
+args = commandArgs(TRUE)
+# args will be like
+#        ${wavfile} ${output}
+#        ${beginTime} ${endTime} ${windowShift} ${gender} ${maxF} ${minF} ${minAmp} ${maxZCR}
+
+
+
+if (length(args) != 10) {
+    print("Wrong number of arguments!")
+    q("no", status=1)
+}
+
+res = ksvF0(args[1], toFile=FALSE, beginTime=as.numeric(args[3]), endTime=as.numeric(args[4]),
+             windowShift=as.numeric(args[5]),
+             gender=args[6],
+             maxF=as.numeric(args[7]),
+             minF=as.numeric(args[8]),
+             minAmp=as.numeric(args[9]),
+             maxZCR=as.numeric(args[10])
+             )
+
+assp_to_tsv(res, args[2])
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/g_f0.xml	Wed Dec 07 19:10:51 2016 -0500
@@ -0,0 +1,57 @@
+<tool id="g_f0" name="Get Pitch" version="0.01">
+    <description>using wrassp ksvF0 pitch tracker</description>
+
+    <requirements>
+        <requirement type="package" version="3.2.1">R</requirement>
+        <requirement type="package" version="0.1.4">r-wrassp</requirement>
+    </requirements>
+
+    <command interpreter="bash">
+        r_wrapper.sh $__tool_directory__/g_f0.R --args ${wavfile} ${output}
+        ${beginTime} ${endTime} ${windowShift} ${gender} ${maxF} ${minF} ${minAmp} ${maxZCR}
+     </command>
+
+
+    <inputs>
+        <param name="wavfile" type="data" format="wav" label="Audio File" help="Audio file in WAV format"/>
+        <param name="beginTime" type="integer" value="0" label="Start time for analysis (s)"/>
+        <param name="endTime" type="integer" value="0" label="End Time for analysis (s) 0 means end of signal"/>
+        <param name="windowShift" type="integer" value="5" label="Window Shift (ms)" help="set analysis window shift to dur ms"/>
+        <param name="gender" type="select" label="Speaker Gender">
+            <option value="m" selected="true">Male</option>
+            <option value="f">Female</option>
+            <option value="u">Unknown</option>
+        </param>
+        <param name="maxF" type="integer" value="500" label="Maximum F0 Frequency (Hz)"/>
+        <param name="minF" type="integer" value="50" label="Minimum F0 Frequency (Hz)"/>
+        <param name="minAmp" type="integer" value="100" label="Amplitude threshold for voiced samples"/>
+        <param name="maxZCR" type="integer" value="3000" label="Maximum zero crossing rate in Hz (for voicing detection)"/>
+    </inputs>
+
+    <outputs>
+        <data name="output" format="tabular" label="#echo $wavfile.element_identifier.replace('wav', 'f0') #" />
+    </outputs>
+
+
+    <tests>
+        <test>
+            <param name="wavfile" value="1_1119_2_22_001-ch6-speaker16.wav"/>
+            <output name="output" file="1_1119_2_22_001-F0.dat"/>
+        </test>
+    </tests>
+
+    <help>F0 analysis of the signal using the K. Schaefer-Vincent periodicity detection algortithm.
+    </help>
+
+    <citations>
+        <citation type='bibtex'>
+            @Manual{,
+              title = {wrassp: an R wrapper to the ASSP Library},
+              author = {Lasse Bombien and Raphael Winkelmann and Michel
+                Scheffers},
+              year = {2016},
+              note = {R package version 0.1.4},
+            }
+        </citation>
+    </citations>
+</tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/g_forest.R	Wed Dec 07 19:10:51 2016 -0500
@@ -0,0 +1,29 @@
+
+library(wrassp)
+
+args = commandArgs(TRUE)
+# args will be like
+#        ${wavfile} ${output}
+#        ${beginTime} ${endTime} ${windowShift} ${windowSize} ${effectiveLength}
+#        ${nominalF1} ${gender} ${estimate} ${order} ${incrOrder} ${numFormants}
+#        ${window} ${preEmphasis}
+
+
+if (length(args) != 15) {
+    print("Wrong number of arguments!")
+    q("no", status=1)
+}
+
+res = forest(args[1], toFile=FALSE, beginTime=as.numeric(args[3]), endTime=as.numeric(args[4]),
+             windowShift=as.numeric(args[5]),
+             windowSize=as.numeric(args[6]),
+             effectiveLength=as.integer(args[7]),
+             nominalF1=as.numeric(args[8]),
+             gender=args[9],
+             estimate=as.integer(args[10]),
+             order=as.numeric(args[11]), incrOrder=as.numeric(args[12]),
+             numFormants=as.numeric(args[13]), window=args[14],
+             preemphasis=as.numeric(args[15])
+             )
+
+assp_to_tsv(res, args[2])
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/g_forest.xml	Wed Dec 07 19:10:51 2016 -0500
@@ -0,0 +1,87 @@
+<tool id="g_forest" name="Get Formants" version="0.01">
+    <description>using wrassp formant tracker</description>
+
+    <requirements>
+        <requirement type="package" version="3.2.1">R</requirement>
+        <requirement type="package" version="0.1.4">r-wrassp</requirement>
+    </requirements>
+
+    <command interpreter="bash">
+        r_wrapper.sh $__tool_directory__/g_forest.R --args ${wavfile} ${output}
+        ${beginTime} ${endTime} ${windowShift} ${windowSize} ${effectiveLength}
+        ${nominalF1} ${gender} ${estimate} ${order} ${incrOrder} ${numFormants}
+        ${window} ${preemphasis}
+     </command>
+
+
+    <inputs>
+        <param name="wavfile" type="data" format="wav" label="Audio File" help="Audio file in WAV format"/>
+        <param name="beginTime" type="integer" value="0" label="Start time for analysis (s)"/>
+        <param name="endTime" type="integer" value="0" label="End Time for analysis (s) 0 means end of signal"/>
+        <param name="windowShift" type="integer" value="5" label="Window Shift (ms)" help="set analysis window shift to dur ms"/>
+        <param name="windowSize" type="integer" value="20" label="Window Size (ms)" help="set analysis window size to dur ms"/>
+        <param name="effectiveLength" type="select" label="make window size effective rather than exact">
+            <option value="1" selected="true">Yes</option>
+            <option value="0">No</option>
+        </param>
+        <param name="nominalF1" type="integer" value="500" label="Nominal F1 Frequency (Hz)"/>
+        <param name="gender" type="select" label="Speaker Gender">
+            <option value="m" selected="true">Male</option>
+            <option value="f">Female</option>
+            <option value="u">Unknown</option>
+        </param>
+        <param name="estimate" type="select" label="Insert rough frequency estimates of missing formants (default: frequency set to zero)">
+            <option value="1">Yes</option>
+            <option value="0" selected="true">No</option>
+        </param>
+        <param name="order" type="integer" value="0" label="analysis order (default 0 means automatic)"/>
+        <param name="incrOrder" type="integer" value="0" label="increment/decrement analysis order"/>
+        <param name="numFormants" type="integer" value="4" label="Number of formants"/>
+        <param name="window" type="select">
+            <option value="BLACKMAN" selected="true">Blackman</option>
+            <option value="RECTANGLE">rectangle</option>
+            <option value="PARABOLA">parabola/Riesz/Welch</option>
+            <option value="COS"      >cosine</option>
+            <option value="HANN"     >Hann/hanning/cosine^2</option>
+            <option value="COS_4"    >cosine^4</option>
+            <option value="HAMMING"  >Hamming</option>
+            <option value="BLACK_X"  >exact Blackman</option>
+            <option value="BLACK_M3" >min. 3-term Blackman-Nuttal</option>
+            <option value="BLACK_M4" >min. 4-term Blackman-Nuttal</option>
+            <option value="NUTTAL_3" >3-term Nuttal (-18 dB/oct)</option>
+            <option value="NUTTAL_4" >4-term Nuttal (-18 dB/oct)</option>
+            <option value="KAISER2_0">Kaiser-Bessel (alpha = 2.0)</option>
+            <option value="KAISER3_0">Kaiser-Bessel (alpha = 3.0)</option>
+            <option value="KAISER4_0">Kaiser-Bessel (alpha = 4.0)</option>
+        </param>
+        <param name="preemphasis" type="float" value="-0.8" min="-1" max="0" label="Pre-emphasis"/>
+    </inputs>
+
+    <outputs>
+        <data name="output" format="tabular" label="#echo $wavfile.element_identifier.replace('wav', 'fm') #" />
+    </outputs>
+
+
+    <tests>
+        <test>
+            <param name="wavfile" value="1_1119_2_22_001-ch6-speaker16.wav"/>
+            <output name="output" file="1_1119_2_22_001-formants.dat"/>
+        </test>
+    </tests>
+
+    <help>Calculate the formant tracks for segments of an audio file.
+ Raw resonance frequency and bandwidth values are obtained by root-solving of the Linear Prediction polynomial from the autocorrelation method and the Split-Levinson-Algorithm (SLA). Resonances are then classified as formants using the so-called Pisarenko frequencies (by-product of the SLA) and a formant frequeny range table derived from the nominal F1 frequency. The latter may have to be increased by about 12% for female voices (see NominalF1 and Gender options).
+    </help>
+
+    <citations>
+        <citation type='bibtex'>
+            @Manual{,
+              title = {wrassp: an R wrapper to the ASSP Library},
+              author = {Lasse Bombien and Raphael Winkelmann and Michel
+                Scheffers},
+              year = {2016},
+              note = {R package version 0.1.4},
+            }
+        </citation>
+    </citations>
+</tool>
--- a/get_fm_at_midpoint.xml	Mon Aug 15 23:48:20 2016 -0400
+++ b/get_fm_at_midpoint.xml	Wed Dec 07 19:10:51 2016 -0500
@@ -1,4 +1,4 @@
-<tool id="get_fm_at_midpoint" name="Get Formants at segment midpoint" version="0.01" force_history_refresh="True">
+<tool id="get_fm_at_midpoint" name="Get Formants at segment midpoint" version="0.01">
     <description>using wrassp formant tracker</description>
 
     <requirements>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/outputAssp.R	Wed Dec 07 19:10:51 2016 -0500
@@ -0,0 +1,37 @@
+assp_to_est <- function(assp, outfile) {
+    
+    # convert to a dataframe
+    result <- data.frame(assp[1])
+    for(idx in seq(2,length(attr(assp,'names')))) {
+        result <- cbind(result, assp[idx])
+    }
+    # add a column of timestamps
+    start <- attr(assp, 'startTime')
+    rate <- attr(assp, 'sampleRate')
+    sampletime <- seq(start, by=1/rate, length.out=nrow(result))
+    # and a column of 1s for some reason
+    #one <- rep(1, nrow(result))
+    result <- cbind(sampletime, result)
+    
+    # write header
+    #write("EST_File Track", file=outfile)
+    #write("DataType ascii", file=outfile, append=T)
+    #write("BreaksPresent true", file=outfile, append=T)    
+    #write(paste("NumFrames", nrow(result)), file=outfile, append=T)    
+    
+    #count <- 0 # count overall number of columns
+    #vcount <- 1 # count variables in assp obj
+    #for(name in attr(assp,'names')) {
+    #    for (coln in seq(ncol(data.frame(assp[vcount])))) {
+    #        colname = paste(name, coln, sep="_")
+    #        write(c(paste("Channel_", count, " ", colname, sep="")), file=outfile, append=T)
+    #        count <- count+1
+    #    }
+    #    vcount <- vcount+1
+    #}
+    #write(paste("NumChannels", count), file=outfile, append=T)
+    #write("EST_Header_End", file=outfile, append=T)
+
+    
+    write.table(result, file=outfile, sep="\t", quote=F, row.names=F, col.names=T, append=F)
+}
\ No newline at end of file
--- a/r_wrapper.sh	Mon Aug 15 23:48:20 2016 -0400
+++ b/r_wrapper.sh	Wed Dec 07 19:10:51 2016 -0500
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-### Run R providing the R script in $1 as standard input and passing 
+### Run R providing the R script in $1 as standard input and passing
 ### the remaining arguments on the command line
 
 # Function that writes a message to stderr and exits
@@ -11,7 +11,9 @@
 }
 
 # Ensure R executable is found
-which R > /dev/null || fail "'R' is required by this tool but was not found on path" 
+which R > /dev/null || fail "'R' is required by this tool but was not found on path"
+
+DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
 
 # Extract first argument
 infile=$1; shift
@@ -20,4 +22,5 @@
 test -f $infile || fail "R input file '$infile' does not exist"
 
 # Invoke R passing file named by first argument to stdin
-R --vanilla --slave $* < $infile
+# add in the util.R file too containing common functions
+cat $DIR/util.R $infile | R --vanilla --slave $*
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/util.R	Wed Dec 07 19:10:51 2016 -0500
@@ -0,0 +1,17 @@
+assp_to_tsv <- function(assp, outfile) {
+
+    # convert to a dataframe, need to add one column at a time
+    result <- data.frame(assp[1])
+    if (length(attr(assp,'names'))>1) {
+        for(idx in seq(2,length(attr(assp,'names')))) {
+            result <- cbind(result, assp[idx])
+        }
+    }
+    # add a column of timestamps
+    start <- attr(assp, 'startTime')
+    rate <- attr(assp, 'sampleRate')
+    time <- seq(start, by=1/rate, length.out=nrow(result))
+    result <- cbind(time, result)
+
+    write.table(result, file=outfile, sep="\t", quote=F, row.names=F, col.names=T, append=F)
+}