andrew@0: /* andrew@0: ** Copyright (C) 2002-2008 Erik de Castro Lopo andrew@0: ** andrew@0: ** This program is free software; you can redistribute it and/or modify andrew@0: ** it under the terms of the GNU General Public License as published by andrew@0: ** the Free Software Foundation; either version 2 of the License, or andrew@0: ** (at your option) any later version. andrew@0: ** andrew@0: ** This program is distributed in the hope that it will be useful, andrew@0: ** but WITHOUT ANY WARRANTY; without even the implied warranty of andrew@0: ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the andrew@0: ** GNU General Public License for more details. andrew@0: ** andrew@0: ** You should have received a copy of the GNU General Public License andrew@0: ** along with this program; if not, write to the Free Software andrew@0: ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. andrew@0: */ andrew@0: andrew@0: /* andrew@0: ** This code is part of Secret Rabibt Code aka libsamplerate. A commercial andrew@0: ** use license for this code is available, please see: andrew@0: ** http://www.mega-nerd.com/SRC/procedure.html andrew@0: */ andrew@0: andrew@0: #ifndef COMMON_H_INCLUDED andrew@0: #define COMMON_H_INCLUDED andrew@0: andrew@0: #ifdef HAVE_STDINT_H andrew@0: #include andrew@0: #elif (SIZEOF_INT == 4) andrew@0: typedef int int32_t ; andrew@0: #elif (SIZEOF_LONG == 4) andrew@0: typedef long int32_t ; andrew@0: #endif andrew@0: andrew@0: #define SRC_MAX_RATIO 256 andrew@0: #define SRC_MIN_RATIO_DIFF (1e-20) andrew@0: andrew@0: #define MAX(a,b) (((a) > (b)) ? (a) : (b)) andrew@0: #define MIN(a,b) (((a) < (b)) ? (a) : (b)) andrew@0: andrew@0: #define ARRAY_LEN(x) ((int) (sizeof (x) / sizeof ((x) [0]))) andrew@0: #define OFFSETOF(type,member) ((int) (&((type*) 0)->member)) andrew@0: andrew@0: #define MAKE_MAGIC(a,b,c,d,e,f) ((a) + ((b) << 4) + ((c) << 8) + ((d) << 12) + ((e) << 16) + ((f) << 20)) andrew@0: andrew@0: andrew@0: #include "samplerate.h" andrew@0: andrew@0: enum andrew@0: { SRC_FALSE = 0, andrew@0: SRC_TRUE = 1, andrew@0: andrew@0: SRC_MODE_PROCESS = 555, andrew@0: SRC_MODE_CALLBACK = 556 andrew@0: } ; andrew@0: andrew@0: enum andrew@0: { SRC_ERR_NO_ERROR = 0, andrew@0: andrew@0: SRC_ERR_MALLOC_FAILED, andrew@0: SRC_ERR_BAD_STATE, andrew@0: SRC_ERR_BAD_DATA, andrew@0: SRC_ERR_BAD_DATA_PTR, andrew@0: SRC_ERR_NO_PRIVATE, andrew@0: SRC_ERR_BAD_SRC_RATIO, andrew@0: SRC_ERR_BAD_PROC_PTR, andrew@0: SRC_ERR_SHIFT_BITS, andrew@0: SRC_ERR_FILTER_LEN, andrew@0: SRC_ERR_BAD_CONVERTER, andrew@0: SRC_ERR_BAD_CHANNEL_COUNT, andrew@0: SRC_ERR_SINC_BAD_BUFFER_LEN, andrew@0: SRC_ERR_SIZE_INCOMPATIBILITY, andrew@0: SRC_ERR_BAD_PRIV_PTR, andrew@0: SRC_ERR_BAD_SINC_STATE, andrew@0: SRC_ERR_DATA_OVERLAP, andrew@0: SRC_ERR_BAD_CALLBACK, andrew@0: SRC_ERR_BAD_MODE, andrew@0: SRC_ERR_NULL_CALLBACK, andrew@0: SRC_ERR_NO_VARIABLE_RATIO, andrew@0: andrew@0: /* This must be the last error number. */ andrew@0: SRC_ERR_MAX_ERROR andrew@0: } ; andrew@0: andrew@0: typedef struct SRC_PRIVATE_tag andrew@0: { double last_ratio, last_position ; andrew@0: andrew@0: int error ; andrew@0: int channels ; andrew@0: andrew@0: /* SRC_MODE_PROCESS or SRC_MODE_CALLBACK */ andrew@0: int mode ; andrew@0: andrew@0: /* Pointer to data to converter specific data. */ andrew@0: void *private_data ; andrew@0: andrew@0: /* Varispeed process function. */ andrew@0: int (*vari_process) (struct SRC_PRIVATE_tag *psrc, SRC_DATA *data) ; andrew@0: andrew@0: /* Constant speed process function. */ andrew@0: int (*const_process) (struct SRC_PRIVATE_tag *psrc, SRC_DATA *data) ; andrew@0: andrew@0: /* State reset. */ andrew@0: void (*reset) (struct SRC_PRIVATE_tag *psrc) ; andrew@0: andrew@0: /* Data specific to SRC_MODE_CALLBACK. */ andrew@0: src_callback_t callback_func ; andrew@0: void *user_callback_data ; andrew@0: long saved_frames ; andrew@0: float *saved_data ; andrew@0: } SRC_PRIVATE ; andrew@0: andrew@0: /* In src_sinc.c */ andrew@0: const char* sinc_get_name (int src_enum) ; andrew@0: const char* sinc_get_description (int src_enum) ; andrew@0: andrew@0: int sinc_set_converter (SRC_PRIVATE *psrc, int src_enum) ; andrew@0: andrew@0: /* In src_linear.c */ andrew@0: const char* linear_get_name (int src_enum) ; andrew@0: const char* linear_get_description (int src_enum) ; andrew@0: andrew@0: int linear_set_converter (SRC_PRIVATE *psrc, int src_enum) ; andrew@0: andrew@0: /* In src_zoh.c */ andrew@0: const char* zoh_get_name (int src_enum) ; andrew@0: const char* zoh_get_description (int src_enum) ; andrew@0: andrew@0: int zoh_set_converter (SRC_PRIVATE *psrc, int src_enum) ; andrew@0: andrew@0: /*---------------------------------------------------------- andrew@0: ** Common static inline functions. andrew@0: */ andrew@0: andrew@0: static inline double andrew@0: fmod_one (double x) andrew@0: { double res ; andrew@0: andrew@0: res = x - lrint (x) ; andrew@0: if (res < 0.0) andrew@0: return res + 1.0 ; andrew@0: andrew@0: return res ; andrew@0: } /* fmod_one */ andrew@0: andrew@0: #endif /* COMMON_H_INCLUDED */ andrew@0: