/*
* 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 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <AudioHdr.h>
#define irint(d) ((int)(d))
// Convert a string to lowercase and return an allocated copy of it.
// XXX - There really should be a string-insensitive 8-bit compare routine.
static char *
char *str)
{
unsigned char *oldstr;
unsigned char *newstr;
int i;
for (i = 0; ; i++) {
else
if (oldstr[i] == '\0')
break;
}
return ((char *)newstr);
}
// class AudioHdr parsing methods
// Return a string containing the sample rate
char *AudioHdr::
RateString() const
{
char *str;
int ratek;
int rateh;
int prec;
str = new char[32];
if (rateh == 0) {
} else {
// scale down to print minimum digits after the decimal point
prec = 3;
if ((rateh % 10) == 0) {
prec--;
rateh /= 10;
}
if ((rateh % 10) == 0) {
prec--;
rateh /= 10;
}
}
return (str);
}
// Return a string containing the number of channels
char *AudioHdr::
ChannelString() const
{
char *str;
str = new char[32];
switch (channels) {
case 1:
break;
case 2:
break;
case 4:
break;
default:
break;
}
return (str);
}
// Return a string containing the encoding
char *AudioHdr::
EncodingString() const
{
char *str;
int iprec;
str = new char[64];
if ((samples_per_unit == 0) || (bytes_per_unit == 0) ||
} else {
// First encode precision
} else {
}
// Then encode format
switch (encoding) {
case ULAW:
// XXX - See bug 1121000
// XXX - (void) strcat(str, "�-law");
break;
case ALAW:
break;
case LINEAR:
break;
case FLOAT:
break;
case G721:
break;
case G722:
break;
case G723:
break;
case DVI:
break;
default:
break;
}
}
return (str);
}
// Return a string containing the entire audio encoding
char *AudioHdr::
FormatString() const
{
char *str;
char *rate;
char *chan;
char *enc;
enc = EncodingString();
rate = RateString();
chan = ChannelString();
delete rate;
delete chan;
delete enc;
return (str);
}
// Parse a string containing the sample rate
char *str)
{
double r;
int rate;
char *khz;
return (AUDIO_ERR_BADARG);
// Init i18n string translations
}
// Scan for a number followed by an optional khz designator
case 2:
// Process 'khz', if present, and fall through
r *= 1000.;
delete khz;
return (AUDIO_ERR_BADARG);
}
delete khz;
case 1:
break;
default:
return (AUDIO_ERR_BADARG);
}
// Check for reasonable bounds
return (AUDIO_ERR_BADARG);
}
sample_rate = (unsigned int) rate;
return (AUDIO_SUCCESS);
}
// Parse a string containing the number of channels
char *str)
{
char *cstr;
int chan;
// Init i18n string translations
}
// Parse a number, followed by optional "-channel"
case 2:
delete cstr;
return (AUDIO_ERR_BADARG);
}
delete cstr;
case 1:
break;
default:
// If no number, look for reasonable keywords
return (AUDIO_ERR_BADARG);
}
chan = 1;
chan = 2;
chan = 4;
} else {
delete cstr;
return (AUDIO_ERR_BADARG);
}
delete cstr;
}
return (AUDIO_ERR_BADARG);
}
return (AUDIO_SUCCESS);
}
// Parse a string containing the audio encoding
char *str)
{
int i;
char *p;
char *estr;
char *xtra;
char *xp;
char *cp;
double prec;
// Init i18n string translations
}
// first copy and remove leading spaces
continue;
// Delimit the precision. If there is one, parse it.
prec = 0.;
if (p != NULL) {
*p++ = '\0';
if (i == 0) {
return (AUDIO_ERR_BADARG);
}
if (i == 2) {
// convert to lowercase and skip leading "-", if any
delete xtra;
return (AUDIO_ERR_BADARG);
}
delete xtra;
}
return (AUDIO_ERR_BADARG);
}
// Don't be fooled by "8 bit"
if (i == 1) {
// convert to lowercase and skip leading "-", if any
p = xp;
else
}
delete xtra;
}
} else {
p = cp;
}
// If "adpcm" appended with a space, concatenate it
if (i == 2) {
i = 1;
}
delete xtra;
}
if (i == 1) {
return (AUDIO_ERR_BADARG);
samples_per_unit = 1;
bytes_per_unit = 1;
return (AUDIO_ERR_BADARG);
samples_per_unit = 1;
bytes_per_unit = 1;
return (AUDIO_ERR_BADARG);
if (prec == 0.)
prec = 16.;
samples_per_unit = 1;
return (AUDIO_ERR_BADARG);
prec = 8.;
samples_per_unit = 1;
return (AUDIO_ERR_BADARG);
prec = 16.;
samples_per_unit = 1;
return (AUDIO_ERR_BADARG);
prec = 24.;
samples_per_unit = 1;
return (AUDIO_ERR_BADARG);
prec = 32.;
samples_per_unit = 1;
return (AUDIO_ERR_BADARG);
if (prec == 0.)
prec = 64.;
samples_per_unit = 1;
return (AUDIO_ERR_BADARG);
prec = 32.;
samples_per_unit = 1;
return (AUDIO_ERR_BADARG);
prec = 64.;
samples_per_unit = 1;
return (AUDIO_ERR_BADARG);
samples_per_unit = 2;
bytes_per_unit = 1;
return (AUDIO_ERR_BADARG);
samples_per_unit = 1;
bytes_per_unit = 1;
return (AUDIO_ERR_BADARG);
if (prec == 0.)
prec = 3.;
samples_per_unit = 8;
return (AUDIO_ERR_BADARG);
prec = 3.;
samples_per_unit = 8;
return (AUDIO_ERR_BADARG);
prec = 5.;
samples_per_unit = 8;
return (AUDIO_ERR_BADARG);
samples_per_unit = 2;
bytes_per_unit = 1;
} else {
delete estr;
return (AUDIO_ERR_BADARG);
}
delete estr;
} else {
return (AUDIO_ERR_BADARG);
}
return (AUDIO_SUCCESS);
}
// Parse a string containing the comma-separated audio encoding
// Format is: "enc, chan, rate"
// XXX - some countries use comma instead of decimal point
// so there may be a problem with "44,1 khz"
char *str)
{
char *pstr;
char *ptr;
char *p;
// Delimit and parse the precision string
if (p == NULL)
if (p == NULL) {
goto errret;
}
*p++ = '\0';
// Delimit and parse the sample rate string
if (!err) {
ptr = p;
if (p == NULL)
if (p == NULL) {
goto errret;
}
*p++ = '\0';
}
// Finally, parse the channels string
if (!err) {
}
// Validate the resulting header
if (!err)
if (!err)
*this = newhdr;
delete pstr;
return (err);
}