Path: blob/master/libs/fluidsynth/src/rvoice/fluid_phase.h
4396 views
/* FluidSynth - A Software Synthesizer1*2* Copyright (C) 2003 Peter Hanappe and others.3*4* This library is free software; you can redistribute it and/or5* modify it under the terms of the GNU Lesser General Public License6* as published by the Free Software Foundation; either version 2.1 of7* the License, or (at your option) any later version.8*9* This library is distributed in the hope that it will be useful, but10* WITHOUT ANY WARRANTY; without even the implied warranty of11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU12* Lesser General Public License for more details.13*14* You should have received a copy of the GNU Lesser General Public15* License along with this library; if not, write to the Free16* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA17* 02110-1301, USA18*/192021#ifndef _FLUID_PHASE_H22#define _FLUID_PHASE_H2324/*25* phase26*/2728#define FLUID_INTERP_BITS 829#define FLUID_INTERP_BITS_MASK 0xff00000030#define FLUID_INTERP_BITS_SHIFT 24313233#define FLUID_FRACT_MAX ((double)4294967296.0)3435/* fluid_phase_t36* Purpose:37* Playing pointer for voice playback38*39* When a sample is played back at a different pitch, the playing pointer in the40* source sample will not advance exactly one sample per output sample.41* This playing pointer is implemented using fluid_phase_t.42* It is a 64 bit number. The higher 32 bits contain the 'index' (number of43* the current sample), the lower 32 bits the fractional part.44*/45typedef uint64_t fluid_phase_t;4647/* Purpose:48* Set a to b.49* a: fluid_phase_t50* b: fluid_phase_t51*/52#define fluid_phase_set(a,b) a=b;5354#define fluid_phase_set_int(a, b) ((a) = ((uint64_t)(b)) << 32)5556/* Purpose:57* Sets the phase a to a phase increment given in b.58* For example, assume b is 0.9. After setting a to it, adding a to59* the playing pointer will advance it by 0.9 samples. */60#define fluid_phase_set_float(a, b) \61(a) = (((uint64_t)(b)) << 32) \62| (uint32_t) (((double)(b) - (int)(b)) * (double)FLUID_FRACT_MAX)6364/* create a fluid_phase_t from an index and a fraction value */65#define fluid_phase_from_index_fract(index, fract) \66((((uint64_t)(index)) << 32) + (fract))6768/* Purpose:69* Return the index and the fractional part, respectively. */70#define fluid_phase_index(_x) \71((unsigned int)((_x) >> 32))72#define fluid_phase_fract(_x) \73((uint32_t)((_x) & 0xFFFFFFFF))7475/* Get the phase index with fractional rounding */76#define fluid_phase_index_round(_x) \77((unsigned int)(((_x) + 0x80000000) >> 32))787980/* Purpose:81* Takes the fractional part of the argument phase and82* calculates the corresponding position in the interpolation table.83* The fractional position of the playing pointer is calculated with a quite high84* resolution (32 bits). It would be unpractical to keep a set of interpolation85* coefficients for each possible fractional part...86*/87#define fluid_phase_fract_to_tablerow(_x) \88((unsigned int)(fluid_phase_fract(_x) & FLUID_INTERP_BITS_MASK) >> FLUID_INTERP_BITS_SHIFT)8990#define fluid_phase_double(_x) \91((double)(fluid_phase_index(_x)) + ((double)fluid_phase_fract(_x) / FLUID_FRACT_MAX))9293/* Purpose:94* Advance a by a step of b (both are fluid_phase_t).95*/96#define fluid_phase_incr(a, b) a += b9798/* Purpose:99* Subtract b from a (both are fluid_phase_t).100*/101#define fluid_phase_decr(a, b) a -= b102103/* Purpose:104* Subtract b samples from a.105*/106#define fluid_phase_sub_int(a, b) ((a) -= (uint64_t)(b) << 32)107108/* Purpose:109* Creates the expression a.index++. */110#define fluid_phase_index_plusplus(a) (((a) += 0x100000000LL)111112#endif /* _FLUID_PHASE_H */113114115