/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 1993-2001 by Sun Microsystems, Inc.
* All rights reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <unistd.h>
#include <convert.h>
#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
#endif
char *Stdin;
char *Stdout;
extern char *optarg;
extern int optind;
int Statistics = 0;
int Debug = 0;
void init_header(AudioHdr&);
void usage();
main(
int argc,
char *argv[])
{
int c; // for getopt
int i;
(void) textdomain(TEXT_DOMAIN);
// basename of program
progname++;
} else {
}
// init the input & output headers
// some conversions depend on invocation name. we'll create
// can be overridden by -o or -i options.
israw++;
pflag++;
} else if (argc <= 1) {
// audioconvert with no arguments
usage();
}
// now parse the rest of the arg's
switch (c) {
#ifdef DEBUG
case 'D':
// enable debug messages
Debug++;
break;
#endif
case 'p':
// convert files in place
exit(1);
}
pflag++;
break;
case 'F':
// force treatment of audio files as raw files
// (ignore filehdr).
fflag++;
break;
case 'f':
// save format string to parse later, but verify now
exit(1);
if (o_offset != 0) {
exit(1);
}
break;
case 'o':
if (pflag) {
exit(1);
}
break;
case 'i':
// if bogus input header, exit ...
exit(1);
}
israw++;
break;
default:
case '?':
usage();
}
}
// XXX - should check argument consistency here....
// If no args left, we're taking input from stdin.
// In this case, make argv point to a fake argv with "-" as a file
// name, and set optind and argc apropriately so we'll go through
// the loop below once.
argc = 1;
optind = 0;
/*
* XXX - we turn off pflag if stdin is the only input file.
* this is kind of a hack. if invoked as raw2audio, pflag
* it turned on. if no files are given, we want to turn
* it off, otherwise we'll complain about using -p with
* stdin, which won't make sense if invoked as raw2audio.
* instead, just silently ignore. the message is still given
* and stdin is ignored if it's specified as one of several
* input files.
*/
pflag = 0;
}
// From this point on we're looking at file names or -i args
// for input format specs.
// new input format spec.
i_offset = 0;
// if bogus input header, exit ...
== -1) {
exit(1);
}
israw++;
// ignore stdin argument if in place
if (pflag) {
Stdin);
continue;
}
if (stdin_seen) {
continue;
} else {
stdin_seen++;
}
} else {
}
// if no audio object returned, just continue to the next
// file. if a fatal error occurs, open_input_file()
// will exit the program.
ifp =
if (!ifp) {
continue;
}
exit(1);
}
// create the output file if not created yet, or if
// converting in place. ofp will be NULL only the first
// time through. use the header of the first input file
// to base the output format on - then create the output
// just use input hdr if no output hdr spec
if (out_fmt) {
== -1) {
exit(1);
}
}
// need to check before output is opened ...
// XXX - bomb out or skip?
exit(3);
}
// Create the file and set the info string.
char *infoString;
int infoStringLen;
} else if (pflag) {
// create new output header based on each input file
// just use input hdr if no output hdr spec
if (out_fmt) {
== -1) {
exit(1);
}
}
// get the *real* path of the infile (follow sym-links),
// and the stat info.
// if the file is read-only, give up
// XXX - do we really want to exit?
exit(1);
}
// this is now the output file.
exit(1);
}
// outfile will get re-assigned to a tmp file
// XXX - bomb out or skip?
exit(3);
}
// If no conversion, just skip the file
if (Debug)
"%s: no-op conversion...skipping\n"),
infile);
continue;
}
// Get the input info string.
char *infoString;
int infoStringLen;
}
// verify that it's a valid conversion by looking at the
// file headers. (this will be called twice for the first
// file if *not* converting in place. that's ok....
== -1)) {
// XXX - bomb out or skip file if invalid conversion?
exit(3);
}
// do the conversion, if error, bomb out
exit(4);
}
ifp->Dereference();
// if in place, finish up by renaming the outfile to
// back to the infile.
if (pflag) {
delete(ofp); // will close and deref, etc.
exit(1);
}
/* Set the permissions to match the original */
}
}
}
if (!pflag) {
delete(ofp); // close output file
}
exit(0); // outta here!
}
// initialize audio hdr to default val's
void
{
hdr.sample_rate = 0;
hdr.samples_per_unit = 0;
hdr.bytes_per_unit = 0;
}
extern "C" { void _doprnt(char *, ...); }
// report a fatal error and exit
void
{
}
void
usage()
{
"Convert between audio file formats and data encodings -- usage:\n"
"\t%s [-pF] [-f outfmt] [-o outfile] [[-i infmt] [file ...]] ...\n"
"where:\n"
"\t-p\tConvert files in place\n"
"\t-F\tForce interpretation of -i (ignore existing file hdr)\n"
"\t-f\tOutput format description\n"
"\t-o\tOutput file (default: stdout)\n"
"\t-i\tInput format description\n"
"\tfile\tList of files to convert (default: stdin)\n\n"
"Format Description:\n"
"\tkeyword=value[,keyword=value...]\n"
"where:\n"
"\tKeywords:\tValues:\n"
"\tchannels\tNumber of interleaved channels\n"
"\tencoding\tAudio encoding. One of:\n"
"\t\t\t ulaw, alaw, g721, g723,\n"
"\t\t\t linear8, linear16, linear32\n"
"\t\t\t pcm (same as linear16)\n"
"\t\t\t voice (ulaw,mono,rate=8k)\n"
"\t\t\t cd (linear16,stereo,rate=44.1k)\n"
"\t\t\t dat (linear16,stereo,rate=48k)\n"
"\tformat\t\tFile format. One of:\n"
"\t\t\t sun, raw (no format)\n"
"\toffset\t\tByte offset (raw input only)\n"),
progname);
exit(1);
}