Home | History | Annotate | Line # | Download | only in common
sun.c revision 1.3
      1 /*	$NetBSD: sun.c,v 1.3 2003/06/23 12:15:01 agc 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 #include <sys/cdefs.h>
     35 
     36 #ifndef lint
     37 __RCSID("$NetBSD: sun.c,v 1.3 2003/06/23 12:15:01 agc Exp $");
     38 #endif
     39 
     40 
     41 #include <sys/types.h>
     42 #include <sys/audioio.h>
     43 #include <sys/ioctl.h>
     44 #include <sys/time.h>
     45 
     46 #include <ctype.h>
     47 #include <err.h>
     48 #include <stdio.h>
     49 #include <stdlib.h>
     50 #include <string.h>
     51 
     52 #include "libaudio.h"
     53 
     54 /*
     55  * SunOS/NeXT .au format helpers
     56  */
     57 struct {
     58 	int	file_encoding;
     59 	int	encoding;
     60 	int	precision;
     61 } file2sw_encodings[] = {
     62 	{ AUDIO_FILE_ENCODING_MULAW_8,		AUDIO_ENCODING_ULAW,	8 },
     63 	{ AUDIO_FILE_ENCODING_LINEAR_8,		AUDIO_ENCODING_SLINEAR_BE, 8 },
     64 	{ AUDIO_FILE_ENCODING_LINEAR_16,	AUDIO_ENCODING_SLINEAR_BE, 16 },
     65 	{ AUDIO_FILE_ENCODING_LINEAR_24,	AUDIO_ENCODING_SLINEAR_BE, 24 },
     66 	{ AUDIO_FILE_ENCODING_LINEAR_32,	AUDIO_ENCODING_SLINEAR_BE, 32 },
     67 #if 0
     68 	/*
     69 	 * we should make some of these available.  the, eg ultrasparc, port
     70 	 * can use the VIS instructions (if available) do do some of these
     71 	 * mpeg ones.
     72 	 */
     73 	{ AUDIO_FILE_ENCODING_FLOAT,		AUDIO_ENCODING_ULAW,	32 },
     74 	{ AUDIO_FILE_ENCODING_DOUBLE,		AUDIO_ENCODING_ULAW,	64 },
     75 	{ AUDIO_FILE_ENCODING_ADPCM_G721,	AUDIO_ENCODING_ULAW,	4 },
     76 	{ AUDIO_FILE_ENCODING_ADPCM_G722,	AUDIO_ENCODING_ULAW,	0 },
     77 	{ AUDIO_FILE_ENCODING_ADPCM_G723_3,	AUDIO_ENCODING_ULAW,	3 },
     78 	{ AUDIO_FILE_ENCODING_ADPCM_G723_5,	AUDIO_ENCODING_ULAW,	5 },
     79 #endif
     80 	{ AUDIO_FILE_ENCODING_ALAW_8,		AUDIO_ENCODING_ALAW,	8 },
     81 	{ -1, -1 }
     82 };
     83 
     84 int
     85 audio_sun_to_encoding(sun_encoding, encp, precp)
     86 	int	sun_encoding;
     87 	int	*encp;
     88 	int	*precp;
     89 {
     90 	int i;
     91 
     92 	for (i = 0; file2sw_encodings[i].file_encoding != -1; i++)
     93 		if (file2sw_encodings[i].file_encoding == sun_encoding) {
     94 			*precp = file2sw_encodings[i].precision;
     95 			*encp = file2sw_encodings[i].encoding;
     96 			return (0);
     97 		}
     98 	return (1);
     99 }
    100 
    101 int
    102 audio_encoding_to_sun(encoding, precision, sunep)
    103 	int	encoding;
    104 	int	precision;
    105 	int	*sunep;
    106 {
    107 	int i;
    108 
    109 	for (i = 0; file2sw_encodings[i].file_encoding != -1; i++)
    110 		if (file2sw_encodings[i].encoding == encoding &&
    111 		    file2sw_encodings[i].precision == precision) {
    112 			*sunep = file2sw_encodings[i].file_encoding;
    113 			return (0);
    114 		}
    115 	return (1);
    116 }
    117