annotate libs/aubioFullOSXUni/include/libsamplerate/common.h @ 2:fa2af670b5c5 tip

SoundFileLoader might have moved
author Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk>
date Fri, 06 Jan 2012 00:23:26 +0000
parents bcb0d40158f4
children
rev   line source
andrew@0 1 /*
andrew@0 2 ** Copyright (C) 2002-2008 Erik de Castro Lopo <erikd@mega-nerd.com>
andrew@0 3 **
andrew@0 4 ** This program is free software; you can redistribute it and/or modify
andrew@0 5 ** it under the terms of the GNU General Public License as published by
andrew@0 6 ** the Free Software Foundation; either version 2 of the License, or
andrew@0 7 ** (at your option) any later version.
andrew@0 8 **
andrew@0 9 ** This program is distributed in the hope that it will be useful,
andrew@0 10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
andrew@0 11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
andrew@0 12 ** GNU General Public License for more details.
andrew@0 13 **
andrew@0 14 ** You should have received a copy of the GNU General Public License
andrew@0 15 ** along with this program; if not, write to the Free Software
andrew@0 16 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
andrew@0 17 */
andrew@0 18
andrew@0 19 /*
andrew@0 20 ** This code is part of Secret Rabibt Code aka libsamplerate. A commercial
andrew@0 21 ** use license for this code is available, please see:
andrew@0 22 ** http://www.mega-nerd.com/SRC/procedure.html
andrew@0 23 */
andrew@0 24
andrew@0 25 #ifndef COMMON_H_INCLUDED
andrew@0 26 #define COMMON_H_INCLUDED
andrew@0 27
andrew@0 28 #ifdef HAVE_STDINT_H
andrew@0 29 #include <stdint.h>
andrew@0 30 #elif (SIZEOF_INT == 4)
andrew@0 31 typedef int int32_t ;
andrew@0 32 #elif (SIZEOF_LONG == 4)
andrew@0 33 typedef long int32_t ;
andrew@0 34 #endif
andrew@0 35
andrew@0 36 #define SRC_MAX_RATIO 256
andrew@0 37 #define SRC_MIN_RATIO_DIFF (1e-20)
andrew@0 38
andrew@0 39 #define MAX(a,b) (((a) > (b)) ? (a) : (b))
andrew@0 40 #define MIN(a,b) (((a) < (b)) ? (a) : (b))
andrew@0 41
andrew@0 42 #define ARRAY_LEN(x) ((int) (sizeof (x) / sizeof ((x) [0])))
andrew@0 43 #define OFFSETOF(type,member) ((int) (&((type*) 0)->member))
andrew@0 44
andrew@0 45 #define MAKE_MAGIC(a,b,c,d,e,f) ((a) + ((b) << 4) + ((c) << 8) + ((d) << 12) + ((e) << 16) + ((f) << 20))
andrew@0 46
andrew@0 47
andrew@0 48 #include "samplerate.h"
andrew@0 49
andrew@0 50 enum
andrew@0 51 { SRC_FALSE = 0,
andrew@0 52 SRC_TRUE = 1,
andrew@0 53
andrew@0 54 SRC_MODE_PROCESS = 555,
andrew@0 55 SRC_MODE_CALLBACK = 556
andrew@0 56 } ;
andrew@0 57
andrew@0 58 enum
andrew@0 59 { SRC_ERR_NO_ERROR = 0,
andrew@0 60
andrew@0 61 SRC_ERR_MALLOC_FAILED,
andrew@0 62 SRC_ERR_BAD_STATE,
andrew@0 63 SRC_ERR_BAD_DATA,
andrew@0 64 SRC_ERR_BAD_DATA_PTR,
andrew@0 65 SRC_ERR_NO_PRIVATE,
andrew@0 66 SRC_ERR_BAD_SRC_RATIO,
andrew@0 67 SRC_ERR_BAD_PROC_PTR,
andrew@0 68 SRC_ERR_SHIFT_BITS,
andrew@0 69 SRC_ERR_FILTER_LEN,
andrew@0 70 SRC_ERR_BAD_CONVERTER,
andrew@0 71 SRC_ERR_BAD_CHANNEL_COUNT,
andrew@0 72 SRC_ERR_SINC_BAD_BUFFER_LEN,
andrew@0 73 SRC_ERR_SIZE_INCOMPATIBILITY,
andrew@0 74 SRC_ERR_BAD_PRIV_PTR,
andrew@0 75 SRC_ERR_BAD_SINC_STATE,
andrew@0 76 SRC_ERR_DATA_OVERLAP,
andrew@0 77 SRC_ERR_BAD_CALLBACK,
andrew@0 78 SRC_ERR_BAD_MODE,
andrew@0 79 SRC_ERR_NULL_CALLBACK,
andrew@0 80 SRC_ERR_NO_VARIABLE_RATIO,
andrew@0 81
andrew@0 82 /* This must be the last error number. */
andrew@0 83 SRC_ERR_MAX_ERROR
andrew@0 84 } ;
andrew@0 85
andrew@0 86 typedef struct SRC_PRIVATE_tag
andrew@0 87 { double last_ratio, last_position ;
andrew@0 88
andrew@0 89 int error ;
andrew@0 90 int channels ;
andrew@0 91
andrew@0 92 /* SRC_MODE_PROCESS or SRC_MODE_CALLBACK */
andrew@0 93 int mode ;
andrew@0 94
andrew@0 95 /* Pointer to data to converter specific data. */
andrew@0 96 void *private_data ;
andrew@0 97
andrew@0 98 /* Varispeed process function. */
andrew@0 99 int (*vari_process) (struct SRC_PRIVATE_tag *psrc, SRC_DATA *data) ;
andrew@0 100
andrew@0 101 /* Constant speed process function. */
andrew@0 102 int (*const_process) (struct SRC_PRIVATE_tag *psrc, SRC_DATA *data) ;
andrew@0 103
andrew@0 104 /* State reset. */
andrew@0 105 void (*reset) (struct SRC_PRIVATE_tag *psrc) ;
andrew@0 106
andrew@0 107 /* Data specific to SRC_MODE_CALLBACK. */
andrew@0 108 src_callback_t callback_func ;
andrew@0 109 void *user_callback_data ;
andrew@0 110 long saved_frames ;
andrew@0 111 float *saved_data ;
andrew@0 112 } SRC_PRIVATE ;
andrew@0 113
andrew@0 114 /* In src_sinc.c */
andrew@0 115 const char* sinc_get_name (int src_enum) ;
andrew@0 116 const char* sinc_get_description (int src_enum) ;
andrew@0 117
andrew@0 118 int sinc_set_converter (SRC_PRIVATE *psrc, int src_enum) ;
andrew@0 119
andrew@0 120 /* In src_linear.c */
andrew@0 121 const char* linear_get_name (int src_enum) ;
andrew@0 122 const char* linear_get_description (int src_enum) ;
andrew@0 123
andrew@0 124 int linear_set_converter (SRC_PRIVATE *psrc, int src_enum) ;
andrew@0 125
andrew@0 126 /* In src_zoh.c */
andrew@0 127 const char* zoh_get_name (int src_enum) ;
andrew@0 128 const char* zoh_get_description (int src_enum) ;
andrew@0 129
andrew@0 130 int zoh_set_converter (SRC_PRIVATE *psrc, int src_enum) ;
andrew@0 131
andrew@0 132 /*----------------------------------------------------------
andrew@0 133 ** Common static inline functions.
andrew@0 134 */
andrew@0 135
andrew@0 136 static inline double
andrew@0 137 fmod_one (double x)
andrew@0 138 { double res ;
andrew@0 139
andrew@0 140 res = x - lrint (x) ;
andrew@0 141 if (res < 0.0)
andrew@0 142 return res + 1.0 ;
andrew@0 143
andrew@0 144 return res ;
andrew@0 145 } /* fmod_one */
andrew@0 146
andrew@0 147 #endif /* COMMON_H_INCLUDED */
andrew@0 148