#!/usr/bin/sh
# 
# Convert various types of sound files to Akai S3000 samples.
# Copyright (c) 1997, Hiroyuki Ohsaki.
# All rights reserved.
# 
# $Id: any2akai,v 1.1 1997/03/21 19:19:23 oosaki Exp ohsaki $
# 

# 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., 675 Mass Ave, Cambridge, MA 02139, USA.

umask 077

# parse options
while getopts 'vd:' i
do
  case $i in 
    v) verb='-v' ;;
    d) dir="-d $OPTARG" ;;
    *) echo "usage: $0 [-v] [-d dir] file..." 2>&1; exit 2 ;;
  esac
done
shift `expr $OPTIND - 1`

for i in $*
do
  case "$i" in 
    # for EPS instrument file, use eps2akai
    *.ins|*.INS)
      eps2akai $verb $dir $i
      ;;
    *)
      case "`which sox`" in 
        /*)
          # if sox is found on the system, force to convert the file
	  # to WAVE/PCM/16 bit, then run wav2akai   
          tmp=/tmp/any2akai$$
          trap 'rm -f $tmp; exit 2' 1 2 15
	  # specify parameters for raw sample data
	  case "$i" in
	    *.raw)
	      sox -t raw -r 22050 -w -s -c 2 $i -t wav -s -w $tmp
	      ;;
	    *)
              sox $i -t wav -s -w $tmp
	      ;;
	  esac
          name=`echo $i | sed -e 's/^.*\///' -e 's/\.[^.]*//'`
          wav2akai $verb $dir -n $name $tmp
          rm -f $tmp
          ;;
        *)
          wav2akai $verb $dir $i
          ;;
      esac
      ;;
  esac
done
exit 0

cat <<EOF >/dev/null

=head1 NAME

any2akai - convert various sound files to Akai sample files

=head1 SYNOPSIS

  any2akai [-v] [-d dir] file...

=head1 DESCRIPTION

This manual page documents B<any2akai>.  This program is a shell
script to convert various sound files to Akai format by using other
programs such as B<eps2akai>, B<wav2akai> and B<sox>.

Since B<any2akai> internally calls B<sox>, B<any2akai> can accept all
formats supported by B<sox> in addition to I<Ensoniq EPS instrument>
and I<Microsoft RIFF WAVE> formats.  See L<sox(1)> for supported sound
formats of B<sox>.  

=head1 OPTIONS

=over 4

=item C<-v>

Verbose mode.  Print much information for debugging.

=item C<-d> directory

Specify the directory in which converted samples will be saved.  If
the directory does not exist, B<any2ps> will create it.

=back

=head1 EXAMPLES

This section shows several example usage of B<any2akai>.

=over 4

=item - Convert all RIFF WAVE and AIFF files in the current directory
to Akai format

  akaiconv *.wav *.aiff

=back

=head1 SEE ALSO

akaitools(1), akaiformat(1), akailist(1), akaimkdir(1), akairead(1),
akaiwrite(1), epslist(1), epsread(1), eps2akai(1), wav2akai(1),
any2akai(1), akaiconv(1) 

=head1 AUTHOR

Hiroyuki Ohsaki <ohsaki@lsnl.jp>

=cut

EOF
