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 "SC_PlugIn.h"
25 #include "SCComplex.h"
41 static inline SCPolarBuf
* ToPolarApx(SndBuf
*buf
)
43 if (buf
->coord
== coord_Complex
) {
44 SCComplexBuf
* p
= (SCComplexBuf
*)buf
->data
;
45 int numbins
= buf
->samples
- 2 >> 1;
46 for (int i
=0; i
<numbins
; ++i
) {
47 p
->bin
[i
].ToPolarApxInPlace();
49 buf
->coord
= coord_Polar
;
52 return (SCPolarBuf
*)buf
->data
;
55 static inline SCComplexBuf
* ToComplexApx(SndBuf
*buf
)
57 if (buf
->coord
== coord_Polar
) {
58 SCPolarBuf
* p
= (SCPolarBuf
*)buf
->data
;
59 int numbins
= buf
->samples
- 2 >> 1;
60 for (int i
=0; i
<numbins
; ++i
) {
61 p
->bin
[i
].ToComplexApxInPlace();
63 buf
->coord
= coord_Complex
;
65 return (SCComplexBuf
*)buf
->data
;
73 #define sc_clipbuf(x, hi) ((x) >= (hi) ? 0 : ((x) < 0 ? 0 : (x)))
75 // for operation on one buffer
77 float fbufnum = ZIN0(0); \
78 if (fbufnum < 0.f) { ZOUT0(0) = -1.f; return; } \
80 uint32 ibufnum = (uint32)fbufnum; \
81 World *world = unit->mWorld; \
83 if (ibufnum >= world->mNumSndBufs) { \
84 int localBufNum = ibufnum - world->mNumSndBufs; \
85 Graph *parent = unit->mParent; \
86 if(localBufNum <= parent->localBufNum) { \
87 buf = parent->mLocalSndBufs + localBufNum; \
89 buf = world->mSndBufs; \
92 buf = world->mSndBufs + ibufnum; \
95 int numbins = buf->samples - 2 >> 1; \
98 // for operation on two input buffers, result goes in first one.
100 float fbufnum1 = ZIN0(0); \
101 float fbufnum2 = ZIN0(1); \
102 if (fbufnum1 < 0.f || fbufnum2 < 0.f) { ZOUT0(0) = -1.f; return; } \
103 ZOUT0(0) = fbufnum1; \
104 uint32 ibufnum1 = (int)fbufnum1; \
105 uint32 ibufnum2 = (int)fbufnum2; \
106 World *world = unit->mWorld; \
109 if (ibufnum1 >= world->mNumSndBufs) { \
110 int localBufNum = ibufnum1 - world->mNumSndBufs; \
111 Graph *parent = unit->mParent; \
112 if(localBufNum <= parent->localBufNum) { \
113 buf1 = parent->mLocalSndBufs + localBufNum; \
115 buf1 = world->mSndBufs; \
118 buf1 = world->mSndBufs + ibufnum1; \
120 if (ibufnum2 >= world->mNumSndBufs) { \
121 int localBufNum = ibufnum2 - world->mNumSndBufs; \
122 Graph *parent = unit->mParent; \
123 if(localBufNum <= parent->localBufNum) { \
124 buf2 = parent->mLocalSndBufs + localBufNum; \
126 buf2 = world->mSndBufs; \
129 buf2 = world->mSndBufs + ibufnum2; \
131 LOCK_SNDBUF2(buf1, buf2); \
132 if (buf1->samples != buf2->samples) return; \
133 int numbins = buf1->samples - 2 >> 1;
135 #define MAKE_TEMP_BUF \
136 if (!unit->m_tempbuf) { \
137 unit->m_tempbuf = (float*)RTAlloc(unit->mWorld, buf->samples * sizeof(float)); \
138 unit->m_numbins = numbins; \
139 } else if (numbins != unit->m_numbins) return;
141 extern InterfaceTable
*ft
;