2 SuperCollider real time audio synthesis system
3 Copyright (c) 2002 James McCartney. All rights reserved.
4 http://www.audiosynth.com
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 #include <sys/types.h>
27 #include "nova-tt/rw_spinlock.hpp"
30 typedef struct SNDFILE_tag SNDFILE
;
35 double sampledur
; // = 1/ samplerate
40 int mask
; // for delay lines
41 int mask1
; // for interpolating oscillators.
42 int coord
; // used by fft ugens
43 SNDFILE
*sndfile
; // used by disk i/o
44 // SF_INFO fileinfo; // used by disk i/o
47 mutable nova::rw_spinlock lock
;
50 typedef struct SndBuf SndBuf
;
57 typedef struct SndBufUpdates SndBufUpdates
;
59 enum { coord_None
, coord_Complex
, coord_Polar
};
61 inline float PhaseFrac(uint32 inPhase
)
63 union { uint32 itemp
; float ftemp
; } u
;
64 u
.itemp
= 0x3F800000 | (0x007FFF80 & ((inPhase
)<<7));
68 inline float PhaseFrac1(uint32 inPhase
)
70 union { uint32 itemp
; float ftemp
; } u
;
71 u
.itemp
= 0x3F800000 | (0x007FFF80 & ((inPhase
)<<7));
75 inline float lookup(const float *table
, int32 phase
, int32 mask
)
77 return table
[(phase
>> 16) & mask
];
84 inline float lookupi(const float *table
, uint32 phase
, uint32 mask
)
86 float frac
= PhaseFrac(phase
);
87 const float *tbl
= table
+ ((phase
>> 16) & mask
);
90 return a
+ frac
* (b
- a
);
93 inline float lookupi2(const float *table
, uint32 phase
, uint32 mask
)
95 float frac
= PhaseFrac1(phase
);
96 const float *tbl
= table
+ ((phase
>> 16) & mask
);
102 inline float lookupi1(const float* table0
, const float* table1
, uint32 pphase
, int32 lomask
)
104 float pfrac
= PhaseFrac1(pphase
);
105 uint32 index
= ((pphase
>> xlobits1
) & lomask
);
106 float val1
= *(const float*)((const char*)table0
+ index
);
107 float val2
= *(const float*)((const char*)table1
+ index
);
108 return val1
+ val2
* pfrac
;
112 inline float lininterp(float x
, float a
, float b
)
114 return a
+ x
* (b
- a
);
117 inline float cubicinterp(float x
, float y0
, float y1
, float y2
, float y3
)
119 // 4-point, 3rd-order Hermite (x-form)
121 float c1
= 0.5f
* (y2
- y0
);
122 float c2
= y0
- 2.5f
* y1
+ 2.f
* y2
- 0.5f
* y3
;
123 float c3
= 0.5f
* (y3
- y0
) + 1.5f
* (y1
- y2
);
125 return ((c3
* x
+ c2
) * x
+ c1
) * x
+ c0
;