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
21 #ifndef _SC_SynthInterfaceTable_
22 #define _SC_SynthInterfaceTable_
24 static const int sc_api_version
= 2;
27 #include "SC_SndBuf.h"
29 #include "SC_BufGen.h"
30 #include "SC_FifoMsg.h"
31 #include "SC_fftlib.h"
32 #include "SC_Export.h"
40 typedef bool (*AsyncStageFn
)(World
*inWorld
, void* cmdData
);
41 typedef void (*AsyncFreeFn
)(World
*inWorld
, void* cmdData
);
50 float *channel_data( uint32 channel
) {
51 return data
+ (channel
* maxFrames
);
56 return internalData
!= 0;
62 unsigned int mSineSize
;
63 float32
*mSineWavetable
;
67 // call printf for debugging. should not use in finished code.
68 int (*fPrint
)(const char *fmt
, ...);
70 // get a seed for a random number generator
74 bool (*fDefineUnit
)(const char *inUnitClassName
, size_t inAllocSize
,
75 UnitCtorFunc inCtor
, UnitDtorFunc inDtor
, uint32 inFlags
);
77 // define a command /cmd
78 bool (*fDefinePlugInCmd
)(const char *inCmdName
, PlugInCmdFunc inFunc
, void* inUserData
);
80 // define a command for a unit generator /u_cmd
81 bool (*fDefineUnitCmd
)(const char *inUnitClassName
, const char *inCmdName
, UnitCmdFunc inFunc
);
84 bool (*fDefineBufGen
)(const char *inName
, BufGenFunc inFunc
);
86 // clear all of the unit's outputs.
87 void (*fClearUnitOutputs
)(Unit
*inUnit
, int inNumSamples
);
89 // non real time memory allocation
90 void* (*fNRTAlloc
)(size_t inSize
);
91 void* (*fNRTRealloc
)(void *inPtr
, size_t inSize
);
92 void (*fNRTFree
)(void *inPtr
);
94 // real time memory allocation
95 void* (*fRTAlloc
)(World
*inWorld
, size_t inSize
);
96 void* (*fRTRealloc
)(World
*inWorld
, void *inPtr
, size_t inSize
);
97 void (*fRTFree
)(World
*inWorld
, void *inPtr
);
99 // call to set a Node to run or not.
100 void (*fNodeRun
)(struct Node
* node
, int run
);
102 // call to stop a Graph after the next buffer.
103 void (*fNodeEnd
)(struct Node
* graph
);
105 // send a trigger from a Node to clients
106 void (*fSendTrigger
)(struct Node
* inNode
, int triggerID
, float value
);
108 // send a reply message from a Node to clients
109 void (*fSendNodeReply
)(struct Node
* inNode
, int replyID
, const char* cmdName
, int numArgs
, const float* values
);
111 // sending messages between real time and non real time levels.
112 bool (*fSendMsgFromRT
)(World
*inWorld
, struct FifoMsg
& inMsg
);
113 bool (*fSendMsgToRT
)(World
*inWorld
, struct FifoMsg
& inMsg
);
115 // libsndfile support
117 int (*fSndFileFormatInfoFromStrings
)(void *info
,
118 const char *headerFormatString
, const char *sampleFormatString
);
120 int (*fSndFileFormatInfoFromStrings
)(SF_INFO
*info
,
121 const char *headerFormatString
, const char *sampleFormatString
);
125 struct Node
* (*fGetNode
)(World
*inWorld
, int inID
);
126 struct Graph
* (*fGetGraph
)(World
*inWorld
, int inID
);
128 void (*fNRTLock
)(World
*inWorld
);
129 void (*fNRTUnlock
)(World
*inWorld
);
131 bool mAltivecAvailable
;
133 void (*fGroup_DeleteAll
)(struct Group
* group
);
134 void (*fDoneAction
)(int doneAction
, struct Unit
*unit
);
136 int (*fDoAsynchronousCommand
)
142 AsyncStageFn stage2
, // stage2 is non real time
143 AsyncStageFn stage3
, // stage3 is real time - completion msg performed if stage3 returns true
144 AsyncStageFn stage4
, // stage4 is non real time - sends done if stage4 returns true
146 int completionMsgSize
,
147 void* completionMsgData
151 // fBufAlloc should only be called within a BufGenFunc
152 int (*fBufAlloc
)(SndBuf
*inBuf
, int inChannels
, int inFrames
, double inSampleRate
);
154 // To initialise a specific FFT, ensure your input and output buffers exist. Internal data structures
155 // will be allocated using the alloc object,
156 // Both "fullsize" and "winsize" should be powers of two (this is not checked internally).
157 struct scfft
* (*fSCfftCreate
)(size_t fullsize
, size_t winsize
, SCFFT_WindowFunction wintype
,
158 float *indata
, float *outdata
, SCFFT_Direction forward
, SCFFT_Allocator
& alloc
);
160 void (*fSCfftDoFFT
)(scfft
*f
);
161 void (*fSCfftDoIFFT
)(scfft
*f
);
163 // destroy any resources held internally.
164 void (*fSCfftDestroy
)(scfft
*f
, SCFFT_Allocator
& alloc
);
166 // Get scope buffer. Returns the maximum number of possile frames.
167 bool (*fGetScopeBuffer
)(World
*inWorld
, int index
, int channels
, int maxFrames
, ScopeBufferHnd
&);
168 void (*fPushScopeBuffer
)(World
*inWorld
, ScopeBufferHnd
&, int frames
);
169 void (*fReleaseScopeBuffer
)(World
*inWorld
, ScopeBufferHnd
&);
172 typedef struct InterfaceTable InterfaceTable
;
174 #define Print (*ft->fPrint)
175 #define RanSeed (*ft->fRanSeed)
176 #define NodeEnd (*ft->fNodeEnd)
177 #define NodeRun (*ft->fNodeRun)
178 #define DefineUnit (*ft->fDefineUnit)
179 #define DefinePlugInCmd (*ft->fDefinePlugInCmd)
180 #define DefineUnitCmd (*ft->fDefineUnitCmd)
181 #define DefineBufGen (*ft->fDefineBufGen)
182 #define ClearUnitOutputs (*ft->fClearUnitOutputs)
183 #define SendTrigger (*ft->fSendTrigger)
184 #define SendNodeReply (*ft->fSendNodeReply)
185 #define SendMsgFromRT (*ft->fSendMsgFromRT)
186 #define SendMsgToRT (*ft->fSendMsgToRT)
187 #define DoneAction (*ft->fDoneAction)
189 #define NRTAlloc (*ft->fNRTAlloc)
190 #define NRTRealloc (*ft->fNRTRealloc)
191 #define NRTFree (*ft->fNRTFree)
193 #define RTAlloc (*ft->fRTAlloc)
194 #define RTRealloc (*ft->fRTRealloc)
195 #define RTFree (*ft->fRTFree)
197 #define SC_GetNode (*ft->fGetNode)
198 #define SC_GetGraph (*ft->fGetGraph)
200 #define NRTLock (*ft->fNRTLock)
201 #define NRTUnlock (*ft->fNRTUnlock)
203 #define BufAlloc (*ft->fBufAlloc)
205 #define GroupDeleteAll (*ft->fGroup_DeleteAll)
207 #define SndFileFormatInfoFromStrings (*ft->fSndFileFormatInfoFromStrings)
209 #define DoAsynchronousCommand (*ft->fDoAsynchronousCommand)
211 #define DefineSimpleUnit(name) \
212 (*ft->fDefineUnit)(#name, sizeof(name), (UnitCtorFunc)&name##_Ctor, 0, 0);
214 #define DefineDtorUnit(name) \
215 (*ft->fDefineUnit)(#name, sizeof(name), (UnitCtorFunc)&name##_Ctor, \
216 (UnitDtorFunc)&name##_Dtor, 0);
218 #define DefineSimpleCantAliasUnit(name) \
219 (*ft->fDefineUnit)(#name, sizeof(name), (UnitCtorFunc)&name##_Ctor, 0, kUnitDef_CantAliasInputsToOutputs);
221 #define DefineDtorCantAliasUnit(name) \
222 (*ft->fDefineUnit)(#name, sizeof(name), (UnitCtorFunc)&name##_Ctor, \
223 (UnitDtorFunc)&name##_Dtor, kUnitDef_CantAliasInputsToOutputs);
225 #ifdef STATIC_PLUGINS
226 #define PluginLoad(name) void name##_Load(InterfaceTable *inTable)
228 #define PluginLoad(name) \
229 C_LINKAGE SC_API_EXPORT int api_version(void) { return sc_api_version; } \
230 C_LINKAGE SC_API_EXPORT void load(InterfaceTable *inTable)
233 #define scfft_create (*ft->fSCfftCreate)
234 #define scfft_dofft (*ft->fSCfftDoFFT)
235 #define scfft_doifft (*ft->fSCfftDoIFFT)
236 #define scfft_destroy (*ft->fSCfftDestroy)
239 class SCWorld_Allocator
:
240 public SCFFT_Allocator
246 SCWorld_Allocator(InterfaceTable
* ft
, World
* world
):
250 virtual void* alloc(size_t size
)
252 return RTAlloc(world
, size
);
255 virtual void free(void* ptr
)