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"
36 #include <sndfile-win.h>
44 typedef bool (*AsyncStageFn
)(World
*inWorld
, void* cmdData
);
45 typedef void (*AsyncFreeFn
)(World
*inWorld
, void* cmdData
);
54 float *channel_data( uint32 channel
) {
55 return data
+ (channel
* maxFrames
);
60 return internalData
!= 0;
66 unsigned int mSineSize
;
67 float32
*mSineWavetable
;
71 // call printf for debugging. should not use in finished code.
72 int (*fPrint
)(const char *fmt
, ...);
74 // get a seed for a random number generator
78 bool (*fDefineUnit
)(const char *inUnitClassName
, size_t inAllocSize
,
79 UnitCtorFunc inCtor
, UnitDtorFunc inDtor
, uint32 inFlags
);
81 // define a command /cmd
82 bool (*fDefinePlugInCmd
)(const char *inCmdName
, PlugInCmdFunc inFunc
, void* inUserData
);
84 // define a command for a unit generator /u_cmd
85 bool (*fDefineUnitCmd
)(const char *inUnitClassName
, const char *inCmdName
, UnitCmdFunc inFunc
);
88 bool (*fDefineBufGen
)(const char *inName
, BufGenFunc inFunc
);
90 // clear all of the unit's outputs.
91 void (*fClearUnitOutputs
)(Unit
*inUnit
, int inNumSamples
);
93 // non real time memory allocation
94 void* (*fNRTAlloc
)(size_t inSize
);
95 void* (*fNRTRealloc
)(void *inPtr
, size_t inSize
);
96 void (*fNRTFree
)(void *inPtr
);
98 // real time memory allocation
99 void* (*fRTAlloc
)(World
*inWorld
, size_t inSize
);
100 void* (*fRTRealloc
)(World
*inWorld
, void *inPtr
, size_t inSize
);
101 void (*fRTFree
)(World
*inWorld
, void *inPtr
);
103 // call to set a Node to run or not.
104 void (*fNodeRun
)(struct Node
* node
, int run
);
106 // call to stop a Graph after the next buffer.
107 void (*fNodeEnd
)(struct Node
* graph
);
109 // send a trigger from a Node to clients
110 void (*fSendTrigger
)(struct Node
* inNode
, int triggerID
, float value
);
112 // send a reply message from a Node to clients
113 void (*fSendNodeReply
)(struct Node
* inNode
, int replyID
, const char* cmdName
, int numArgs
, const float* values
);
115 // sending messages between real time and non real time levels.
116 bool (*fSendMsgFromRT
)(World
*inWorld
, struct FifoMsg
& inMsg
);
117 bool (*fSendMsgToRT
)(World
*inWorld
, struct FifoMsg
& inMsg
);
119 // libsndfile support
121 int (*fSndFileFormatInfoFromStrings
)(void *info
,
122 const char *headerFormatString
, const char *sampleFormatString
);
124 int (*fSndFileFormatInfoFromStrings
)(SF_INFO
*info
,
125 const char *headerFormatString
, const char *sampleFormatString
);
129 struct Node
* (*fGetNode
)(World
*inWorld
, int inID
);
130 struct Graph
* (*fGetGraph
)(World
*inWorld
, int inID
);
132 void (*fNRTLock
)(World
*inWorld
);
133 void (*fNRTUnlock
)(World
*inWorld
);
135 bool mAltivecAvailable
;
137 void (*fGroup_DeleteAll
)(struct Group
* group
);
138 void (*fDoneAction
)(int doneAction
, struct Unit
*unit
);
140 int (*fDoAsynchronousCommand
)
146 AsyncStageFn stage2
, // stage2 is non real time
147 AsyncStageFn stage3
, // stage3 is real time - completion msg performed if stage3 returns true
148 AsyncStageFn stage4
, // stage4 is non real time - sends done if stage4 returns true
150 int completionMsgSize
,
151 void* completionMsgData
155 // fBufAlloc should only be called within a BufGenFunc
156 int (*fBufAlloc
)(SndBuf
*inBuf
, int inChannels
, int inFrames
, double inSampleRate
);
158 // To initialise a specific FFT, ensure your input and output buffers exist. Internal data structures
159 // will be allocated using the alloc object,
160 // Both "fullsize" and "winsize" should be powers of two (this is not checked internally).
161 struct scfft
* (*fSCfftCreate
)(size_t fullsize
, size_t winsize
, SCFFT_WindowFunction wintype
,
162 float *indata
, float *outdata
, SCFFT_Direction forward
, SCFFT_Allocator
& alloc
);
164 void (*fSCfftDoFFT
)(scfft
*f
);
165 void (*fSCfftDoIFFT
)(scfft
*f
);
167 // destroy any resources held internally.
168 void (*fSCfftDestroy
)(scfft
*f
, SCFFT_Allocator
& alloc
);
170 // Get scope buffer. Returns the maximum number of possile frames.
171 bool (*fGetScopeBuffer
)(World
*inWorld
, int index
, int channels
, int maxFrames
, ScopeBufferHnd
&);
172 void (*fPushScopeBuffer
)(World
*inWorld
, ScopeBufferHnd
&, int frames
);
173 void (*fReleaseScopeBuffer
)(World
*inWorld
, ScopeBufferHnd
&);
176 typedef struct InterfaceTable InterfaceTable
;
178 #define Print (*ft->fPrint)
179 #define RanSeed (*ft->fRanSeed)
180 #define NodeEnd (*ft->fNodeEnd)
181 #define NodeRun (*ft->fNodeRun)
182 #define DefineUnit (*ft->fDefineUnit)
183 #define DefinePlugInCmd (*ft->fDefinePlugInCmd)
184 #define DefineUnitCmd (*ft->fDefineUnitCmd)
185 #define DefineBufGen (*ft->fDefineBufGen)
186 #define ClearUnitOutputs (*ft->fClearUnitOutputs)
187 #define SendTrigger (*ft->fSendTrigger)
188 #define SendNodeReply (*ft->fSendNodeReply)
189 #define SendMsgFromRT (*ft->fSendMsgFromRT)
190 #define SendMsgToRT (*ft->fSendMsgToRT)
191 #define DoneAction (*ft->fDoneAction)
193 #define NRTAlloc (*ft->fNRTAlloc)
194 #define NRTRealloc (*ft->fNRTRealloc)
195 #define NRTFree (*ft->fNRTFree)
197 #define RTAlloc (*ft->fRTAlloc)
198 #define RTRealloc (*ft->fRTRealloc)
199 #define RTFree (*ft->fRTFree)
201 #define SC_GetNode (*ft->fGetNode)
202 #define SC_GetGraph (*ft->fGetGraph)
204 #define NRTLock (*ft->fNRTLock)
205 #define NRTUnlock (*ft->fNRTUnlock)
207 #define BufAlloc (*ft->fBufAlloc)
209 #define GroupDeleteAll (*ft->fGroup_DeleteAll)
211 #define SndFileFormatInfoFromStrings (*ft->fSndFileFormatInfoFromStrings)
213 #define DoAsynchronousCommand (*ft->fDoAsynchronousCommand)
215 #define DefineSimpleUnit(name) \
216 (*ft->fDefineUnit)(#name, sizeof(name), (UnitCtorFunc)&name##_Ctor, 0, 0);
218 #define DefineDtorUnit(name) \
219 (*ft->fDefineUnit)(#name, sizeof(name), (UnitCtorFunc)&name##_Ctor, \
220 (UnitDtorFunc)&name##_Dtor, 0);
222 #define DefineSimpleCantAliasUnit(name) \
223 (*ft->fDefineUnit)(#name, sizeof(name), (UnitCtorFunc)&name##_Ctor, 0, kUnitDef_CantAliasInputsToOutputs);
225 #define DefineDtorCantAliasUnit(name) \
226 (*ft->fDefineUnit)(#name, sizeof(name), (UnitCtorFunc)&name##_Ctor, \
227 (UnitDtorFunc)&name##_Dtor, kUnitDef_CantAliasInputsToOutputs);
229 #ifdef STATIC_PLUGINS
230 #define PluginLoad(name) void name##_Load(InterfaceTable *inTable)
232 #define PluginLoad(name) \
233 C_LINKAGE SC_API_EXPORT int api_version(void) { return sc_api_version; } \
234 C_LINKAGE SC_API_EXPORT void load(InterfaceTable *inTable)
237 #define scfft_create (*ft->fSCfftCreate)
238 #define scfft_dofft (*ft->fSCfftDoFFT)
239 #define scfft_doifft (*ft->fSCfftDoIFFT)
240 #define scfft_destroy (*ft->fSCfftDestroy)
243 class SCWorld_Allocator
:
244 public SCFFT_Allocator
250 SCWorld_Allocator(InterfaceTable
* ft
, World
* world
):
254 virtual void* alloc(size_t size
)
256 return RTAlloc(world
, size
);
259 virtual void free(void* ptr
)