  <sect1 id='ch-wave-manual'>
	<title><command>ch_wave</command> <emphasis>Audio file manipulation</emphasis></title>

    <toc depth='1'></toc>
    <para>
    </para>
    <sect2>
      <title>Synopsis</title>
      <para>
      </para>
        <!-- /amd/projects/festival/versions/v_mpiro/speech_tools_linux/bin/ch_wave -sgml_synopsis -->
        <para>
<cmdsynopsis><command>ch_wave</command>[input file0] [input file1] ... -o [output file]<arg>-h </arg>
<arg>-itype <replaceable>string</replaceable></arg>
<arg>-n <replaceable>int</replaceable></arg>
<arg>-f <replaceable>int</replaceable></arg>
<arg>-ibo <replaceable>string</replaceable></arg>
<arg>-iswap </arg>
<arg>-istype <replaceable>string</replaceable></arg>
<arg>-c <replaceable>string</replaceable></arg>
<arg>-start <replaceable>float</replaceable></arg>
<arg>-end <replaceable>float</replaceable></arg>
<arg>-from <replaceable>int</replaceable></arg>
<arg>-to <replaceable>int</replaceable></arg>
<arg>-o <replaceable>ofile</replaceable></arg>
<arg>-otype <replaceable>string</replaceable></arg>
<arg>-F <replaceable>int</replaceable></arg>
<arg>-obo <replaceable>string</replaceable></arg>
<arg>-oswap </arg>
<arg>-ostype <replaceable>string</replaceable></arg>
<arg>-scale <replaceable>float</replaceable></arg>
<arg>-scaleN <replaceable>float</replaceable></arg>
<arg>-lpfilter <replaceable>int</replaceable></arg>
<arg>-hpfilter <replaceable>int</replaceable></arg>
<arg>-forder <replaceable>int</replaceable></arg>
<arg>-fafter </arg>
<arg>-info </arg>
<arg>-add </arg>
<arg>-pc <replaceable>string</replaceable></arg>
<arg>-key <replaceable>ifile</replaceable></arg>
<arg>-divide. </arg>
<arg>-divide </arg>
<arg>-ext <replaceable>string</replaceable></arg>
<arg>-extract <replaceable>string</replaceable></arg>
</cmdsynopsis>
        </para>
        <!-- DONE /amd/projects/festival/versions/v_mpiro/speech_tools_linux/bin/ch_wave -sgml_synopsis -->
      <para>

ch_wave is used to manipulate the format of a waveform
file. Operations include:
<itemizedlist>
<listitem><para>file format conversion</para></listitem>
<listitem><para>resampling (changing the sampling frequency)</para></listitem>
<listitem><para>byte-swapping</para></listitem>
<listitem><para>making multiple input files into a single multi-channel output file</para></listitem>
<listitem><para>making multiple input files into a single single-channel output file</para></listitem>
<listitem><para>extracting a single channel from a multi-channel waveform</para></listitem>
<listitem><para>scaling the amplitude of the waveform</para></listitem>
<listitem><para>low pass and high pass filtering</para></listitem>
<listitem><para>extracting a time-delimited portion of the waveform</para></listitem>
</itemizedlist>
ch_wave is a executable program that serves as a wrap-around for the
EST_Wave class and the basic wave manipulation functions. More
advanced waveform processing is performed by the signal processing library.
      </para>
    </sect2>
    <sect2>
      <title>OPTIONS</title>
      <para>
      </para>
        <!-- /amd/projects/festival/versions/v_mpiro/speech_tools_linux/bin/ch_wave -sgml_options -->
        <para>
<variablelist>
<varlistentry><term>-h</term>
<LISTITEM><PARA>

Options help 
</PARA></LISTITEM>
</varlistentry>

<varlistentry><term>-itype</term>
<LISTITEM><PARA>
<replaceable>string</replaceable>

Input file type (optional). If set to raw, this 
indicates that the input file does not have a header. While 
this can be used to specify file types other than raw, this is 
rarely used for other purposes 
as the file type of all the existing supported 
types can be determined automatically from the 
file's header. If the input file is unheadered, 
files are assumed to be shorts (16bit). 
Supported types are 
nist, est, esps, snd, riff, aiff, audlab, raw, ascii 
</PARA></LISTITEM>
</varlistentry>

<varlistentry><term>-n</term>
<LISTITEM><PARA>
<replaceable>int</replaceable>

Number of channels in an unheadered input file 
</PARA></LISTITEM>
</varlistentry>

<varlistentry><term>-f</term>
<LISTITEM><PARA>
<replaceable>int</replaceable>

Sample rate in Hertz for an unheadered input file 
</PARA></LISTITEM>
</varlistentry>

<varlistentry><term>-ibo</term>
<LISTITEM><PARA>
<replaceable>string</replaceable>

Input byte order in an unheadered input file: 
possibliities are: MSB , LSB, native or nonnative. 
Suns, HP, SGI Mips, M68000 are MSB (big endian) 
Intel, Alpha, DEC Mips, Vax are LSB (little 
endian) 
</PARA></LISTITEM>
</varlistentry>

<varlistentry><term>-iswap</term>
<LISTITEM><PARA>

Swap bytes. (For use on an unheadered input file) 
</PARA></LISTITEM>
</varlistentry>

<varlistentry><term>-istype</term>
<LISTITEM><PARA>
<replaceable>string</replaceable>

Sample type in an unheadered input file: 
short, mulaw, byte, ascii 
</PARA></LISTITEM>
</varlistentry>

<varlistentry><term>-c</term>
<LISTITEM><PARA>
<replaceable>string</replaceable>

Select a single channel (starts from 0). 
Waveforms can have multiple channels. This option 
extracts a single channel for progcessing and 
discards the rest. 
</PARA></LISTITEM>
</varlistentry>

<varlistentry><term>-start</term>
<LISTITEM><PARA>
<replaceable>float</replaceable>

Extract sub-wave starting at this time, specified in 
seconds 
</PARA></LISTITEM>
</varlistentry>

<varlistentry><term>-end</term>
<LISTITEM><PARA>
<replaceable>float</replaceable>

Extract sub-wave ending at this time, specified in 
seconds 
</PARA></LISTITEM>
</varlistentry>

<varlistentry><term>-from</term>
<LISTITEM><PARA>
<replaceable>int</replaceable>

Extract sub-wave starting at this sample point 
</PARA></LISTITEM>
</varlistentry>

<varlistentry><term>-to</term>
<LISTITEM><PARA>
<replaceable>int</replaceable>

Extract sub-wave ending at this sample point 
</PARA></LISTITEM>
</varlistentry>

<varlistentry><term>-o</term>
<LISTITEM><PARA>
<replaceable>ofile</replaceable>

Output filename. If not specified output is 
to stdout. 
</PARA></LISTITEM>
</varlistentry>

<varlistentry><term>-otype</term>
<LISTITEM><PARA>
<replaceable>string</replaceable>

Output file type, (optional). If no type is 
Specified the type of the input file is assumed. 
Supported types are: 
nist, est, esps, snd, riff, aiff, audlab, raw, ascii 
</PARA></LISTITEM>
</varlistentry>

<varlistentry><term>-F</term>
<LISTITEM><PARA>
<replaceable>int</replaceable>

Output sample rate in Hz. If this is different 
from the input sample rate, resampling will occur 
</PARA></LISTITEM>
</varlistentry>

<varlistentry><term>-obo</term>
<LISTITEM><PARA>
<replaceable>string</replaceable>

Output byte order: MSB, LSB, native, or nonnative. 
Suns, HP, SGI Mips, M68000 are MSB (big endian) 
Intel, Alpha, DEC Mips, Vax are LSB 
(little endian) 
</PARA></LISTITEM>
</varlistentry>

<varlistentry><term>-oswap</term>
<LISTITEM><PARA>

Swap bytes when saving to output 
</PARA></LISTITEM>
</varlistentry>

<varlistentry><term>-ostype</term>
<LISTITEM><PARA>
<replaceable>string</replaceable>

Output sample type: short, mulaw, byte or ascii 
</PARA></LISTITEM>
</varlistentry>

<varlistentry><term>-scale</term>
<LISTITEM><PARA>
<replaceable>float</replaceable>

Scaling factor. Increase or descrease the amplitude 
of the whole waveform by the factor given 
</PARA></LISTITEM>
</varlistentry>

<varlistentry><term>-scaleN</term>
<LISTITEM><PARA>
<replaceable>float</replaceable>

Scaling factor with normalization. 
The waveform is scaled to its maximum level, after which 
it is scaled by the factor given 
</PARA></LISTITEM>
</varlistentry>

<varlistentry><term>-lpfilter</term>
<LISTITEM><PARA>
<replaceable>int</replaceable>

Low pass filter, with cutoff frequency in Hz 
Filtering is performed by a FIR filter which is built at run 
time. The order of the filter can be given by -forder. The 
default value is 199 
</PARA></LISTITEM>
</varlistentry>

<varlistentry><term>-hpfilter</term>
<LISTITEM><PARA>
<replaceable>int</replaceable>

High pass filter, with cutoff frequency in Hz 
Filtering is performed by a FIR filter which is 
built at run time. The order of the filter can 
be given by -forder. The default value is 199. 
</PARA></LISTITEM>
</varlistentry>

<varlistentry><term>-forder</term>
<LISTITEM><PARA>
<replaceable>int</replaceable>

Order of FIR filter used for lpfilter and 
hpfilter. This must be ODD. Sensible values range 
from 19 (quick but with a shallow rolloff) to 199 
(slow but with a steep rolloff). The default is 199. 
</PARA></LISTITEM>
</varlistentry>

<varlistentry><term>-fafter</term>
<LISTITEM><PARA>

Do filtering after other operations such as 
resampling (default : filter before other operations) 
</PARA></LISTITEM>
</varlistentry>

<varlistentry><term>-info</term>
<LISTITEM><PARA>

Print information about file and header. 
This option gives useful information such as file 
length, sampling rate, number of channels etc 
No output is produced 
</PARA></LISTITEM>
</varlistentry>

<varlistentry><term>-add</term>
<LISTITEM><PARA>

A new single channel waveform is created by adding 
the corresponding sample points of each input waveform 
</PARA></LISTITEM>
</varlistentry>

<varlistentry><term>-pc</term>
<LISTITEM><PARA>
<replaceable>string</replaceable>

Combine input waveforms to form a single 
multichannel waveform. The argument to this option controls 
how long the new waveform should be. If the option 
is LONGEST, the output wave if the length of the 
longest input wave and shorter waves are padded with 
zeros at the end. If the option is FIRST, the length 
of the new waveform is the length of the first file 
on the command line, and subsequent waves are padded 
or cut to this length 
</PARA></LISTITEM>
</varlistentry>

<varlistentry><term>-key</term>
<LISTITEM><PARA>
<replaceable>ifile</replaceable>

Label file designating subsections, for use with 
</PARA></LISTITEM>
</varlistentry>

<varlistentry><term>-divide.</term>
<LISTITEM><PARA>

The KEYLAB file is a label file which specifies 
where chunks (such as individual sentences) in 
a waveform begin and end. See section of wave extraction. 
</PARA></LISTITEM>
</varlistentry>

<varlistentry><term>-divide</term>
<LISTITEM><PARA>

Divide a single input waveform into multiple output 
waveforms. Each output waveform is extracted from the 
input waveform by using the KEYLAB file, which 
specifies the start and stop times for each chunk. 
The output files are named according to the filename 
in the KEYLAB file, with extension given by -ext. See 
section on wave extraction 
</PARA></LISTITEM>
</varlistentry>

<varlistentry><term>-ext</term>
<LISTITEM><PARA>
<replaceable>string</replaceable>

File extension for divided waveforms 
</PARA></LISTITEM>
</varlistentry>

<varlistentry><term>-extract</term>
<LISTITEM><PARA>
<replaceable>string</replaceable>

Used in conjunction with -key to extract a 
single section of waveform from the input 
waveform. The argument is the name of a file given 
in the file column of the KEYLAB file. </PARA></LISTITEM>
</varlistentry>
</variablelist>
        </para>
        <!-- DONE /amd/projects/festival/versions/v_mpiro/speech_tools_linux/bin/ch_wave -sgml_options -->
    </sect2>
    <sect2>
      <title>Making multiple waves into a single wave</title>
      <para>
If multiple input files are specified, by default they are concatenated into 
the output file.
</para>
<para>
<screen>
$ ch_wave kdt_010.wav kdt_011.wav kdt_012.wav kdt_013.wav -o out.wav
</screen>
</para>
<para>
In the above example, 4 single channel input files are converted to
one single channel output file. Multi-channel waveforms can also be
concatenated provided they all have the same number of input channels.
</para><para>
Multiple input files can be made into a multi-channel output file by 
using the -pc option:
</para><para>
<screen>
$ ch_wave kdt_010.wav kdt_011.wav kdt_012.wav kdt_013.wav -o -pc LONGEST out.wav
</screen>
</para>
<para>
The argument to -pc can either be LONGEST, in which the output
waveform is the length of the longest input file, or FIRST in which it
is the length of the first intput file.
      </para>
    </sect2>
    <sect2>
      <title>Extracting channels from multi-channel waves</title>
      <para>
The -c option is used to specify channels which should be extracted
from the input.  If the input is a 4 channel wave,
</para><para>
<screen>
$ ch_wave kdt_m.wav -o a.wav -c "0 2"
</screen>
</para>
<para>
will extract the 0th and 2nd channel (counting starts from 0). The
argument to -c can be either a single number of a list of numbers
(wrapped in quotes)
      </para>
    </sect2>
    <sect2>
      <title>Extracting of a single region from a waveform</title>
      <para>
There are several ways of extracting a region of a waveform. The
simplest way is by using the start, end, to and from commands to
delimit a sub portion of the input wave. For example
</para><para>
<screen>
$ ch_wave kdt_010.wav -o small.wav -start 1.45 -end 1.768
</screen>
</para>
<para>
extracts a subwave starting at 1.45 seconds and extending to 1.768 seconds.
alternatively,
</para><para>
<screen>
$ ch_wave kd_010.wav -o small.wav -from 5000 -to 10000
</screen>
</para>
<para>
extracts a subwave starting at 5000 samples and extending to 10000
samples. Times and samples can be mixed in sub-wave extraction. The
output waveform will have the same number of channels as the input
waveform.
      </para>
    </sect2>
    <sect2>
      <title>Extracting of a multiple regions from a waveform</title>
      <para>
Mulitple regions can be extracted from a waveform, but as it would be
too complicated to specify the start and end points on the command
line, a label file with start and end points, and file names is used.
The file is called a key label file and in xwaves label format looks
like:
</para>
<para>
<screen>
separator ;
#
0.308272  121 sil ;  	file kdt_010.01 ;
0.440021  121 are ;     file kdt_010.02 ;
0.512930  121 your ;    file kdt_010.03 ;
0.784097  121 grades ;  file kdt_010.04 ;
1.140969  121 higher ;  file kdt_010.05 ;
1.258647  121 or ;      file kdt_010.06 ;
1.577145  121 lower ;   file kdt_010.07 ;
1.725516  121 than ;    file kdt_010.08 ;
2.315186  121 nancy's ; file kdt_010.09 ;
</screen>
</para>
<para>
Each line represents one region. The first column is the end time of
that region and the start time of the next. The next two columns are
colour and an arbitrary name, and the filename in which the output
waveform is to be stored is kept as a field called file in the last column.
In this example, each region corresponds to a single word in the file.
If the above file is called "kdt_010.words.keylab", the command:
</para>
<para>
<screen>
$ ch_wave kdt_010.wav -key kdt_010.words -ext .wav -divide
</screen>
</para>
<para>
will divide the input waveform into 9 output waveforms called
kdt_010.01.wav, kdt_010.02.wav ... kdt_010.09.wav. The -ext option
specifies the extension of the new waveforms, and the -divide command
specifies that division of the entire waveform is to take place.
If only a single file is required the -extract option can be used, in
which case its argument is the filename required.
</para>
<para>
<screen>
$ ch_wave kdt_010.wav -key kdt_010.words -ext .wav -extract kdt_010.03 \
-o kdt_010.03.wav
</screen>
</para>
<para>
Note that an output filename should be specified with this option.
      </para>
    </sect2>
    <sect2>
      <title>Adding headers and format conversion</title>
      <para>
It is usually a good idea for all waveform files to have headers as
this way different byte orders, sampling rates etc can be handled
safely. ch_wave provides a means of adding headers to raw files.
The following adds a header to a file of 16 bit shorts
</para>
<para>
<screen>
$ ch_wave kdt_010.raw1 -o kdt_010.h1.wav -otype nist -f 16000 -itype raw
</screen>
</para>
<para>
The following downsamples the input to 8 KHz
</para>
<para>
<screen>
$ ch_wave kdt_010.raw1 -o kdt_010.h2.wav -otype nist -f 16000  \
-F 8000 -itype raw
</screen>
</para>
<para>
The following takes a 8K ulaw input file and produces a 16bit, 20Khz output file:
</para>
<para>
<screen>
$ ch_wave kdt_010.raw2 -o kdt_010.h3.wav -otype nist -istype ulaw \
-f 8000 -F 20000 -itype raw
</screen>
      </para>
    </sect2>
  </sect1>
