Home | History | Annotate | Line # | Download | only in audio
      1 /*	$NetBSD: audiofil.h,v 1.2 2019/05/08 13:40:17 isaki Exp $	*/
      2 
      3 /*
      4  * Copyright (C) 2017 Tetsuya Isaki. All rights reserved.
      5  * Copyright (C) 2017 Y.Sugahara (moveccr). 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  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     21  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     23  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  * SUCH DAMAGE.
     27  */
     28 
     29 #ifndef _SYS_DEV_AUDIO_AUDIOFIL_H_
     30 #define _SYS_DEV_AUDIO_AUDIOFIL_H_
     31 
     32 /*
     33  * Number of bits for internal format.
     34  * XXX 32bit mode is not completed.
     35  * XXX Is this necessary?
     36  */
     37 #define AUDIO_INTERNAL_BITS		16
     38 /*#define AUDIO_INTERNAL_BITS		32 */
     39 
     40 #if AUDIO_INTERNAL_BITS == 16
     41 
     42 typedef int16_t  aint_t;	/* audio          integer */
     43 typedef uint16_t auint_t;	/* audio unsigned integer */
     44 typedef int32_t  aint2_t;	/* audio          wide integer */
     45 typedef uint32_t auint2_t;	/* audio unsigned wide integer */
     46 #define AINT_T_MAX	((aint_t)0x7fff)
     47 #define AINT_T_MIN	((aint_t)0x8000)
     48 
     49 #elif AUDIO_INTERNAL_BITS == 32
     50 
     51 typedef int32_t  aint_t;
     52 typedef uint32_t auint_t;
     53 typedef int64_t  aint2_t;
     54 typedef uint64_t auint2_t;
     55 #define AINT_T_MAX	((aint_t)0x7fffffff)
     56 #define AINT_T_MIN	((aint_t)0x80000000)
     57 
     58 #else
     59 #error Invalid AUDIO_INTERNAL_BITS
     60 #endif
     61 
     62 /*
     63  * audio format.
     64  *
     65  * precision <= stride always holds.
     66  */
     67 typedef struct {
     68 	u_int	sample_rate;	/* sample rate in Hz */
     69 	u_int	encoding;	/* AUDIO_ENCODING_* */
     70 	u_int	stride;		/* container bits of a sample */
     71 	u_int	precision;	/* valid bits of a sample */
     72 	u_int	channels;	/* 1..AUDIO_MAX_CHANNELS */
     73 } audio_format2_t;
     74 
     75 /* Parameters for conversion filters */
     76 typedef struct {
     77 	/* Pointer to source samples. */
     78 	const void *src;
     79 	/* Input format */
     80 	const audio_format2_t *srcfmt;
     81 
     82 	/* Pointer to destination buffer. */
     83 	void *dst;
     84 	/* Output format */
     85 	const audio_format2_t *dstfmt;
     86 
     87 	/*
     88 	 * Number of frames to be converted.
     89 	 * The conversion filter must output 'count' frames.  src and dst
     90 	 * are guaranteed that at least 'count' frames are contiguous.
     91 	 * The caller does not reference this count after calling, so
     92 	 * that the conversion filter can use passed this variable.
     93 	 * For example, decrementing it directly.
     94 	 */
     95 	u_int count;
     96 
     97 	/* The conversion filters can use this pointer. */
     98 	void *context;
     99 } audio_filter_arg_t;
    100 
    101 typedef void(*audio_filter_t)(audio_filter_arg_t *arg);
    102 
    103 /* Filter registration structure */
    104 typedef struct {
    105 	audio_filter_t codec;	/* conversion function */
    106 	void *context;		/* optional codec's argument */
    107 } audio_filter_reg_t;
    108 
    109 #endif /* !_SYS_DEV_AUDIO_AUDIOFIL_H_ */
    110