/*
* 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 1989-2002 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Miscellaneous audio-related operations.
*/
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <libaudio_impl.h>
#include <audio_errno.h>
#include <audio_hdr.h>
/*
* Convert a byte count into a floating-point time value, in seconds,
* using the encoding specified in the given audio header structure.
* Note that the byte count is not the same as the offset in an audio file,
* since the size of the audio file header is not taken into account.
*/
double
{
return ((double)cnt /
(double)hp->samples_per_unit));
}
/*
* Convert a floating-point time value, in seconds, to a byte count for
* the audio encoding in the given audio header. Note that the byte count
* is not the same as the offset in an audio file, since the size of the
* audio file header is not taken into account.
*/
unsigned
{
unsigned offset;
(double)hp->samples_per_unit)));
/* Round down to the start of the nearest sample frame */
return (offset);
}
/*
* Convert an ASCII time value (hh:mm:ss.dd) into floating-point seconds.
* Returns value if successfully converted. Otherwise, returns HUGE_VAL.
*
* XXX - currently allows the ridiculous construct: 5.3E3:-47.3E-1:17.3
*/
double
{
double val;
char *str2;
return (HUGE_VAL);
val *= 60.;
return (HUGE_VAL);
}
val *= 60.;
return (HUGE_VAL);
}
if (*str2 != '\0')
return (HUGE_VAL);
return (val);
}
/*
* Convert floating-point seconds into an ASCII time value (hh:mm:ss.dd).
*
* HUGE_VAL is converted to 0:00. 'Precision' specifies the maximum
* number of digits after the decimal point (-1 allows the max).
*
* Store the resulting string in the specified buffer (must be at least
* AUDIO_MAX_TIMEVAL bytes long). The string address is returned.
*/
char *
{
char *p;
unsigned ovflow;
int hours;
double x;
return (str);
}
/* Limit precision arg to reasonable value */
precision = 10;
/* If negative, write a minus sign and get on with it. */
p = str;
if (sec < 0.) {
/* Round off within precision to avoid -.01 printing as -0:00 */
if (sec > 0.)
*p++ = '-';
}
/* Round off within precision to avoid 1:59.999 printing as 1:60.00 */
sec -= x;
sec += x;
if (sec >= 60.) {
/* Extract minutes */
if (hours) {
/* convert hours */
p = &p[strlen(p)];
ovflow %= 60;
}
/* convert minutes (use two digits if hours printed) */
p = &p[strlen(p)];
} else {
*p++ = '0';
*p++ = ':';
}
if (sec < 10.)
*p++ = '0';
return (str);
}
/*
* Compare the encoding fields of two audio headers.
* Return 0 if they are the same, 1 if they are the same except for
* sample rate, else -1.
*/
int
{
return (-1);
return (1);
return (0);
}
/*
* Interpret the encoding information in the specified header
* and return an appropriate string in the supplied buffer.
* The buffer should contain at least AUDIO_MAX_ENCODE_INFO bytes.
* The returned string is something like:
* "stereo 16-bit linear PCM @ 44.1kHz"
*
* Returns AUDIO_ERR_BADHDR if the header cannot be interpreted.
*/
int
{
char *chan;
char *prec;
char *enc;
int err;
err = AUDIO_SUCCESS;
case 0:
chan = "(zero channels?)";
break;
case 1:
chan = "mono"; break;
case 2:
chan = "stereo"; break;
case 4:
chan = "quad"; break;
default:
}
case AUDIO_ENCODING_ULAW:
enc = "u-law";
goto pcm;
case AUDIO_ENCODING_ALAW:
enc = "A-law";
goto pcm;
case AUDIO_ENCODING_LINEAR:
enc = "linear PCM";
goto pcm;
case AUDIO_ENCODING_FLOAT:
enc = "floating-point";
pcm:
goto unknown;
break;
default:
enc = "(unknown encoding?)";
if (hdrp->samples_per_unit != 0) {
(double)hdrp->samples_per_unit);
} else {
prec = "(unknown precision?)";
}
}
return (err);
}