Home | History | Annotate | Line # | Download | only in common
sun.c revision 1.1
      1 /*	$NetBSD: sun.c,v 1.1 2002/01/15 08:19:37 mrg Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2002 Matthew R. Green
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. The name of the author may not be used to endorse or promote products
     16  *    derived from this software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     23  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     24  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     25  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     26  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     28  * SUCH DAMAGE.
     29  */
     30 
     31 /*
     32  * XXX this is slightly icky in places...
     33  */
     34 
     35 #include <sys/types.h>
     36 #include <sys/audioio.h>
     37 #include <sys/ioctl.h>
     38 #include <sys/time.h>
     39 
     40 #include <ctype.h>
     41 #include <err.h>
     42 #include <stdio.h>
     43 #include <stdlib.h>
     44 #include <string.h>
     45 
     46 #include "libaudio.h"
     47 
     48 /*
     49  * SunOS/NeXT .au format helpers
     50  */
     51 struct {
     52 	int	file_encoding;
     53 	int	encoding;
     54 	int	precision;
     55 } file2sw_encodings[] = {
     56 	{ AUDIO_FILE_ENCODING_MULAW_8,		AUDIO_ENCODING_ULAW,	8 },
     57 	{ AUDIO_FILE_ENCODING_LINEAR_8,		AUDIO_ENCODING_ULINEAR_BE, 8 },
     58 	{ AUDIO_FILE_ENCODING_LINEAR_16,	AUDIO_ENCODING_ULINEAR_BE, 16 },
     59 	{ AUDIO_FILE_ENCODING_LINEAR_24,	AUDIO_ENCODING_ULINEAR_BE, 24 },
     60 	{ AUDIO_FILE_ENCODING_LINEAR_32,	AUDIO_ENCODING_ULINEAR_BE, 32 },
     61 #if 0
     62 	/*
     63 	 * we should make some of these available.  the, eg ultrasparc, port
     64 	 * can use the VIS instructions (if available) do do some of these
     65 	 * mpeg ones.
     66 	 */
     67 	{ AUDIO_FILE_ENCODING_FLOAT,		AUDIO_ENCODING_ULAW,	32 },
     68 	{ AUDIO_FILE_ENCODING_DOUBLE,		AUDIO_ENCODING_ULAW,	64 },
     69 	{ AUDIO_FILE_ENCODING_ADPCM_G721,	AUDIO_ENCODING_ULAW,	4 },
     70 	{ AUDIO_FILE_ENCODING_ADPCM_G722,	AUDIO_ENCODING_ULAW,	0 },
     71 	{ AUDIO_FILE_ENCODING_ADPCM_G723_3,	AUDIO_ENCODING_ULAW,	3 },
     72 	{ AUDIO_FILE_ENCODING_ADPCM_G723_5,	AUDIO_ENCODING_ULAW,	5 },
     73 #endif
     74 	{ AUDIO_FILE_ENCODING_ALAW_8,		AUDIO_ENCODING_ALAW,	8 },
     75 	{ -1, -1 }
     76 };
     77 
     78 int
     79 audio_sun_to_encoding(sun_encoding, encp, precp)
     80 	int	sun_encoding;
     81 	int	*encp;
     82 	int	*precp;
     83 {
     84 	int i;
     85 
     86 	for (i = 0; file2sw_encodings[i].file_encoding != -1; i++)
     87 		if (file2sw_encodings[i].file_encoding == sun_encoding) {
     88 			*precp = file2sw_encodings[i].precision;
     89 			*encp = file2sw_encodings[i].encoding;
     90 			return (0);
     91 		}
     92 	return (1);
     93 }
     94 
     95 int
     96 audio_encoding_to_sun(encoding, precision, sunep)
     97 	int	encoding;
     98 	int	precision;
     99 	int	*sunep;
    100 {
    101 	int i;
    102 
    103 	for (i = 0; file2sw_encodings[i].file_encoding != -1; i++)
    104 		if (file2sw_encodings[i].encoding == encoding &&
    105 		    file2sw_encodings[i].precision == precision) {
    106 			*sunep = file2sw_encodings[i].file_encoding;
    107 			return (0);
    108 		}
    109 	return (1);
    110 }
    111