aboutsummaryrefslogtreecommitdiff
path: root/sc4pd/headers/common
diff options
context:
space:
mode:
Diffstat (limited to 'sc4pd/headers/common')
-rw-r--r--sc4pd/headers/common/SC_AllocPool.h278
-rw-r--r--sc4pd/headers/common/SC_Altivec.h118
-rw-r--r--sc4pd/headers/common/SC_Endian.h64
-rw-r--r--sc4pd/headers/common/SC_Sem.h43
-rw-r--r--sc4pd/headers/common/SC_StringBuffer.h67
-rw-r--r--sc4pd/headers/common/SC_StringParser.h40
-rw-r--r--sc4pd/headers/common/dfftlib.h62
-rw-r--r--sc4pd/headers/common/fftlib.h62
-rw-r--r--sc4pd/headers/common/scsynthsend.h191
9 files changed, 925 insertions, 0 deletions
diff --git a/sc4pd/headers/common/SC_AllocPool.h b/sc4pd/headers/common/SC_AllocPool.h
new file mode 100644
index 0000000..fc9d72a
--- /dev/null
+++ b/sc4pd/headers/common/SC_AllocPool.h
@@ -0,0 +1,278 @@
+
+/*
+ SuperCollider real time audio synthesis system
+ Copyright (c) 2002 James McCartney. All rights reserved.
+ http://www.audiosynth.com
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+/*
+This is based on Doug Lea's allocator but rewritten so I can read and understand it...
+also features of free all-at-once pools are added.
+Now uses 16 byte alignment, which does increase the minimum allocation size to 32 bytes
+including the overhead.
+Improved bit block scanning by using a count leading zeroes instruction.
+
+*/
+
+#ifndef _AllocPool_
+#define _AllocPool_
+
+#include "SC_List.h"
+#include "clz.h"
+#include <stdlib.h>
+
+const int kNumAllocBins = 128;
+const int kNumSmallBins = 64;
+const int kMaxSmallBin = kNumSmallBins - 1;
+const int kBinWidth = 8;
+const int kMaxSmallBinSize = kNumSmallBins * kBinWidth;
+const int kBinBlockWidth = 4;
+const int kBinBlockMask = kBinBlockWidth - 1;
+
+const size_t kAlign = 16;
+const size_t kAlignMask = kAlign - 1;
+const size_t kChunkFree = 0;
+const size_t kChunkInUse = 1;
+const size_t kSizeBits = ~kChunkInUse;
+
+class AllocChunk;
+class AllocPool;
+typedef AllocChunk *AllocChunkPtr;
+typedef Link<AllocChunk> AllocBin;
+typedef AllocBin* AllocBinPtr;
+
+class AllocChunk : public Link<AllocChunk>
+{
+ friend class AllocPool;
+
+ size_t Size()
+ { return mSize & kSizeBits; }
+
+ size_t PrevSize()
+ { return mPrevSize & kSizeBits; }
+
+ AllocChunkPtr ChunkAtOffset(size_t inSize)
+ { return AllocChunkPtr((char*)this + inSize); }
+
+ AllocChunkPtr NextChunk()
+ { return ChunkAtOffset(Size()); }
+
+ AllocChunkPtr PrevChunk()
+ { return ChunkAtOffset(-PrevSize()); }
+
+ bool InUse()
+ { return (bool)(mSize & kChunkInUse); }
+
+ bool PrevInUse()
+ { return (bool)(mPrevSize & kChunkInUse); }
+
+ void SetSizeFree(size_t inSize)
+ { mSize = ChunkAtOffset(inSize)->mPrevSize = inSize; }
+
+ void SetSizeInUse(size_t inSize)
+ { mSize = ChunkAtOffset(inSize)->mPrevSize = inSize | kChunkInUse; }
+
+ void SetNeighborsInUse(size_t inOffset)
+ { mPrevSize = ChunkAtOffset(inOffset)->mSize = kChunkInUse; }
+
+ bool IsArea()
+ { return mPrevSize == kChunkInUse && NextChunk()->mSize == kChunkInUse; }
+
+ void* ToPtr()
+ { return (void*)((char*)this + sizeof(AllocChunk)); }
+
+ size_t mPrevSize;
+ size_t mSize;
+};
+
+class AllocArea;
+typedef AllocArea* AllocAreaPtr;
+
+class AllocAreaHdr /* for size calculations */
+{
+protected:
+ friend class AllocPool;
+
+ AllocAreaPtr mPrev, mNext;
+ size_t mSize;
+ void *mUnalignedPointerToThis;
+};
+
+class AllocArea : public AllocAreaHdr
+{
+public:
+ void SanityCheck();
+
+private:
+ friend class AllocPool;
+
+ AllocChunk mChunk;
+};
+
+const size_t kMinAllocSize = 2 * kAlign;
+// FIXME: add kAlign to overhead? <sk>
+const size_t kAreaOverhead = sizeof(AllocAreaHdr) + 2 * sizeof(AllocChunk);
+
+typedef void* (*NewAreaFunc)(size_t size);
+typedef void (*FreeAreaFunc)(void *);
+
+class AllocPool
+{
+public:
+ AllocPool(NewAreaFunc allocArea, FreeAreaFunc freeArea,
+ size_t areaInitSize, size_t areaMoreSize);
+ ~AllocPool();
+
+ void Reinit();
+
+ void *Alloc(size_t inBytes);
+ void *Realloc(void* inPtr, size_t inBytes);
+ void Free(void* inPtr);
+ void FreeAll();
+ void FreeAllInternal();
+
+ // debugging
+ size_t TotalFree();
+ size_t LargestFreeChunk();
+
+ void DoCheckPool();
+ void DoCheckInUseChunk(AllocChunkPtr p);
+
+ static AllocChunkPtr MemToChunk(void *inPtr)
+ { return (AllocChunkPtr)((char*)(inPtr) - sizeof(AllocChunk)); }
+
+private:
+ void InitAlloc();
+ void InitBins();
+ AllocAreaPtr NewArea(size_t inAreaSize);
+ void FreeArea(AllocChunkPtr chunk);
+
+ // debugging
+ void DoCheckArea(AllocAreaPtr area);
+ void DoCheckBin(AllocChunkPtr bin, long idx);
+ void DoCheckChunk(AllocChunkPtr p);
+ void DoCheckFreeChunk(AllocChunkPtr p);
+ void DoCheckAllocedChunk(AllocChunkPtr p, size_t s);
+ void DoGarbageFill(AllocChunkPtr p);
+ void DoGarbageFill(AllocChunkPtr p, long size);
+
+ // inlines
+
+ static size_t RequestToSize(size_t inReqSize)
+ {
+ size_t sizePlusOverhead = inReqSize + sizeof(AllocChunk);
+ if (sizePlusOverhead <= kMinAllocSize) return kMinAllocSize;
+ else return (sizePlusOverhead + kAlignMask) & ~kAlignMask;
+ }
+
+ static int SmallBinIndex(size_t inSize)
+ { return inSize >> 4; }
+
+ static int BinIndex2(size_t inSize)
+ {
+ return
+ ((inSize < 1024) ? (inSize>>4):
+ (inSize < 2048) ? 56 + (inSize>>7):
+ (inSize < 4096) ? 64 + (inSize>>8):
+ (inSize < 8192) ? 72 + (inSize>>9):
+ (inSize < 16384) ? 80 + (inSize>>10):
+ (inSize < 32768) ? 88 + (inSize>>11):
+ (inSize < 65536) ? 96 + (inSize>>12):
+ (inSize < 131072) ? 104 + (inSize>>13):
+ (inSize < 262144) ? 112 + (inSize>>14):127);
+ }
+
+ static int BinIndex(size_t inSize)
+ {
+ if (inSize < 1024) return inSize >> 4;
+ if (inSize >= 262144) return 127;
+ int bits = 28 - CLZ(inSize);
+ return (bits << 3) + (inSize >> bits) ;
+ }
+
+ void MarkBinBlock(int inIndex)
+ {
+ unsigned long word = inIndex >> 5;
+ unsigned long bitPosition = inIndex & 31;
+ unsigned long bitValue = 1L << bitPosition;
+ mBinBlocks[word] |= bitValue;
+ }
+
+ void ClearBinBlock(int inIndex)
+ {
+ unsigned long word = inIndex >> 5;
+ unsigned long bitPosition = inIndex & 31;
+ unsigned long bitValue = 1L << bitPosition;
+ mBinBlocks[word] &= ~bitValue;
+ }
+
+ int NextFullBin(int inStartingBinIndex)
+ {
+ if (inStartingBinIndex >= 128) return -1;
+ int word = inStartingBinIndex >> 5;
+ int bitPosition = inStartingBinIndex & 31;
+ unsigned long bitValue = 1L << bitPosition;
+ unsigned long binBits = mBinBlocks[word];
+
+ if (binBits >= bitValue) {
+ binBits = (~(bitValue - 1) & binBits);
+ } else {
+ for (++word; word<4 && !mBinBlocks[word]; ++word) {}
+ if (word==4) return -1;
+ binBits = mBinBlocks[word];
+ }
+ bitPosition = CTZ((int32)binBits);
+
+ return (word << 5) + bitPosition;
+ }
+
+ void LinkFree(AllocChunkPtr inChunk);
+ /*
+ {
+ size_t size = inChunk->Size();
+ int index = BinIndex(size);
+
+ AllocChunkPtr bin = mBins + index;
+
+ if (index < kNumSmallBins || bin->IsEmpty()) {
+ inChunk->InsertAfter(bin);
+ MarkBinBlock(index);
+ } else {
+ AllocChunkPtr link = bin->Next();
+ while (link != bin && size < link->Size()) link = link->Next();
+ inChunk->InsertBefore(link);
+ }
+ }
+ */
+
+ void UnlinkFree(AllocChunkPtr inChunk)
+ {
+ inChunk->RemoveLeaveDangling();
+ size_t size = inChunk->Size();
+ int index = BinIndex(size);
+ AllocChunkPtr bin = mBins + index;
+ if (bin->IsEmpty()) ClearBinBlock(index);
+ }
+
+ AllocChunk mBins[kNumAllocBins];
+ AllocAreaPtr mAreas;
+ NewAreaFunc mAllocArea;
+ FreeAreaFunc mFreeArea;
+ size_t mAreaInitSize, mAreaMoreSize;
+ unsigned long mBinBlocks[4];
+};
+
+#endif
diff --git a/sc4pd/headers/common/SC_Altivec.h b/sc4pd/headers/common/SC_Altivec.h
new file mode 100644
index 0000000..8ae3f66
--- /dev/null
+++ b/sc4pd/headers/common/SC_Altivec.h
@@ -0,0 +1,118 @@
+/*
+ SuperCollider real time audio synthesis system
+ Copyright (c) 2003 James McCartney. All rights reserved.
+ http://www.audiosynth.com
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#ifndef _SC_Altivec_
+#define _SC_Altivec_
+
+#if defined(SC_LINUX) && defined(__ALTIVEC__)
+# include <altivec.h>
+#endif
+
+#if __VEC__
+
+typedef vector signed int vint32;
+typedef vector unsigned int vuint32;
+typedef vector float vfloat32;
+
+// Since gcc 3.3 vector initializers are surrounded by brackets. <sk>
+#if defined(__GNUC__) && (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 3)
+# define vinit(x) { x, x, x, x }
+#else
+# define vinit(x) ( x )
+#endif
+
+//#define vload(x) (*vtempptr = (x), vec_splat(vtemp,0))
+#define define_vtemp vfloat32 vtemp; float *vtempptr = (float*)&vtemp;
+#define define_vones vfloat32 vones = vec_ctf(vec_splat_s32(1),0);
+#define define_vzero vfloat32 vzero = (vfloat32)vec_splat_s32(0);
+#define vi0123 (vec_unpackh(vec_unpackh((vector signed char)vec_lvsl(0,(int*)0))))
+#define v0123 (vec_ctf(vec_unpackh(vec_unpackh((vector signed char)vec_lvsl(0,(int*)0))), 0))
+#define v0123_4ths (vec_ctf(vec_unpackh(vec_unpackh((vector signed char)vec_lvsl(0,(int*)0))), 2))
+#define vstart(x, vslope) (vec_madd(vslope, v0123_4ths, vload(x)))
+
+#define vec_not(a) (vtemp = (a); vec_nor(vtemp, vtemp))
+#define vec_cmplt(a, b) (vec_cmpgt(b, a))
+#define vec_cmple(a, b) (vec_cmpge(b, a))
+#define vec_mul(a, b) (vec_madd(a, b, vzero))
+#define vec_2sComp(x) (vec_sub(vec_sub (x, x), x))
+
+#define USEVEC (ft->mAltivecAvailable && !(BUFLENGTH & 3))
+
+typedef union vec_union {
+ int32 i[4];
+ float32 f[4];
+ vint32 vi;
+ vfloat32 vf;
+} vec_union;
+
+inline vfloat32 vload( float f )
+{
+ vec_union temp;
+ temp.f[0] = f;
+ return vec_splat( vec_lde( 0, temp.f ), 0 );
+}
+
+inline vint32 vload( int32 i )
+{
+ vec_union temp;
+ temp.i[0] = i;
+ return vec_splat( vec_lde( 0, temp.i ), 0 );
+}
+
+inline vint32 vload( int32 a, int32 b, int32 c, int32 d )
+{
+ vec_union temp;
+ temp.i[0] = a;
+ temp.i[1] = b;
+ temp.i[2] = c;
+ temp.i[3] = d;
+ return temp.vi;
+}
+
+inline vector float vec_float_1( void )
+{
+ return vec_ctf( vec_splat_u32(1), 0);
+}
+
+inline vector float vec_reciprocal( vector float v )
+{
+ vector float reciprocal = vec_re( v );
+ return vec_madd( reciprocal, vec_nmsub( reciprocal, v, vec_float_1()), reciprocal ); //Newton Rapheson refinement
+}
+
+#define vec_div(a, b) vec_mul(a, vec_reciprocal(b))
+
+// seed = ((seed & mask) << shift1) ^ (((seed << shift2) ^ seed) >> shift3);
+
+#define define_trshifts \
+ vuint32 trmask = ((vuint32)(0xFFFFFFFE,0xFFFFFFF8,0xFFFFFFF0,0)); \
+ vuint32 trshift1 = ((vuint32)(12, 14, 7, 0)); \
+ vuint32 trshift2 = ((vuint32)(13, 2, 3, 0)); \
+ vuint32 trshift3 = ((vuint32)(19, 25, 11, 0));
+
+inline vuint32 trands(vuint32 seed, vuint32 trmask, vuint32 shift1, vuint32 shift2, vuint32 shift3)
+{
+ return vec_xor(vec_sl(vec_and(seed, trmask),shift1), vec_sr(vec_xor(vec_sl(seed,shift2),seed),shift3));
+}
+
+#endif
+#endif
+
+
diff --git a/sc4pd/headers/common/SC_Endian.h b/sc4pd/headers/common/SC_Endian.h
new file mode 100644
index 0000000..ba127f5
--- /dev/null
+++ b/sc4pd/headers/common/SC_Endian.h
@@ -0,0 +1,64 @@
+/*
+ SuperCollider real time audio synthesis system
+ Copyright (c) 2002 James McCartney. All rights reserved.
+ http://www.audiosynth.com
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+/* NOTE: This file should declare/define the following functions/macros:
+
+ htonl
+ htons
+ ntohl
+ ntohs
+
+ either explicitly or implicitly by including system headers.
+*/
+
+#ifndef SC_ENDIAN_H_INCLUDED
+#define SC_ENDIAN_H_INCLUDED
+
+#ifdef SC_DARWIN
+
+# include <machine/endian.h>
+
+#elif defined(SC_WIN32)
+
+# define LITTLE_ENDIAN 1234
+# define BIG_ENDIAN 4321
+# define BYTE_ORDER LITTLE_ENDIAN
+# include <winsock2.h>
+
+#else
+
+# include <endian.h>
+# include <netinet/in.h>
+
+#endif
+
+#ifndef BYTE_ORDER
+# error BYTE_ORDER undefined, check __FILE__
+#endif // BYTE_ORDER
+
+#ifndef BIG_ENDIAN
+# error BIG_ENDIAN undefined, check __FILE__
+#endif // BIG_ENDIAN
+
+#ifndef LITTLE_ENDIAN
+# error LITTLE_ENDIAN undefined, check __FILE__
+#endif // LITTLE_ENDIAN
+
+#endif // SC_ENDIAN_H_INCLUDED
diff --git a/sc4pd/headers/common/SC_Sem.h b/sc4pd/headers/common/SC_Sem.h
new file mode 100644
index 0000000..22a2ffa
--- /dev/null
+++ b/sc4pd/headers/common/SC_Sem.h
@@ -0,0 +1,43 @@
+/*
+ SuperCollider real time audio synthesis system
+ Copyright (c) 2002 James McCartney. All rights reserved.
+ http://www.audiosynth.com
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+
+#ifndef _SC_Semaphore_
+#define _SC_Semaphore_
+
+#include <pthread.h>
+
+class SC_Semaphore
+{
+public:
+ SC_Semaphore(int initialCount);
+ ~SC_Semaphore();
+
+ void Acquire();
+ void Release();
+
+private:
+ pthread_cond_t available;
+ pthread_mutex_t mutex;
+ int count;
+};
+
+#endif
+
diff --git a/sc4pd/headers/common/SC_StringBuffer.h b/sc4pd/headers/common/SC_StringBuffer.h
new file mode 100644
index 0000000..24bcd4d
--- /dev/null
+++ b/sc4pd/headers/common/SC_StringBuffer.h
@@ -0,0 +1,67 @@
+// emacs: -*- c++ -*-
+// file: SC_StringBuffer.h
+// copyright: 2003 stefan kersten <steve@k-hornz.de>
+// cvs: $Id: SC_StringBuffer.h,v 1.1.1.1 2004-07-14 16:21:36 timblech Exp $
+
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 2 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+// USA
+
+#ifndef SC_STRINGBUFFER_H_INCLUDED
+#define SC_STRINGBUFFER_H_INCLUDED
+
+#include <stdarg.h>
+#include <stdlib.h>
+
+// =====================================================================
+// SC_StringBuffer - Autogrowing string buffer.
+// =====================================================================
+
+class SC_StringBuffer
+{
+public:
+ SC_StringBuffer(size_t initialSize=0);
+ SC_StringBuffer(const SC_StringBuffer& other);
+ ~SC_StringBuffer();
+
+ size_t getCapacity() const { return mCapacity; }
+ size_t getSize() const { return mPtr - mData; }
+ size_t getRemaining() const { return mCapacity - getSize(); }
+ char* getData() const { return mData; }
+
+ bool isEmpty() const { return getSize() == 0; }
+
+ void finish() { append('\0'); }
+ void reset() { mPtr = mData; }
+ void append(const char* src, size_t len);
+ void append(char c);
+ void append(const char* str);
+ void vappendf(const char* fmt, va_list vargs);
+ void appendf(const char* fmt, ...);
+
+protected:
+ enum {
+ kGrowAlign = 256,
+ kGrowMask = kGrowAlign - 1
+ };
+
+ void growBy(size_t request);
+
+private:
+ size_t mCapacity;
+ char* mPtr;
+ char* mData;
+};
+
+#endif // SC_STRINGBUFFER_H_INCLUDED
diff --git a/sc4pd/headers/common/SC_StringParser.h b/sc4pd/headers/common/SC_StringParser.h
new file mode 100644
index 0000000..f2d414e
--- /dev/null
+++ b/sc4pd/headers/common/SC_StringParser.h
@@ -0,0 +1,40 @@
+// emacs: -*- c++ -*-
+// file: SC_StringParser.h
+// copyright: 2003 stefan kersten <steve@k-hornz.de>
+// cvs: $Id: SC_StringParser.h,v 1.1.1.1 2004-07-14 16:21:37 timblech Exp $
+
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 2 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+// USA
+
+#ifndef _SC_StringParser_
+#define _SC_StringParser_
+
+#define SC_MAX_TOKEN_LENGTH 256
+
+class SC_StringParser
+{
+ char *mSpec, *mStart, *mEnd;
+ char mSep, mBuf[SC_MAX_TOKEN_LENGTH];
+
+public:
+ SC_StringParser();
+ SC_StringParser(char *spec, char sep);
+
+ bool AtEnd() const;
+ const char *NextToken();
+};
+
+#endif
+
diff --git a/sc4pd/headers/common/dfftlib.h b/sc4pd/headers/common/dfftlib.h
new file mode 100644
index 0000000..409267e
--- /dev/null
+++ b/sc4pd/headers/common/dfftlib.h
@@ -0,0 +1,62 @@
+long dFFTInit(long *fftMptr, long fftN, double *Utbl);
+/* Compute cosine table and check size for complex ffts */
+/* INPUTS */
+/* fftN = size of fft */
+/* OUTPUTS */
+/* *fftMptr = log2 of fft size */
+/* *Utbl = cosine table with fftN/4 + 1 entries (angles = 0 to pi/2 inclusive) */
+/* RETURNS */
+/* 1 if fftN is invalid, 0 otherwise */
+
+long drFFTInit(long *fftMptr, long fftN, double *Utbl);
+/* Compute cosine table and check size for a real input fft */
+/* INPUTS */
+/* fftN = size of fft */
+/* OUTPUTS */
+/* *fftMptr = log2 of fft size */
+/* *Utbl = cosine table with fftN/4 + 1 entries (angles = 0 to pi/2 inclusive) */
+/* RETURNS */
+/* 1 if fftN is invalid, 0 otherwise */
+
+void dffts(double *ioptr, long M, long Rows, double *Utbl);
+/* Compute in-place complex fft on the rows of the input array */
+/* INPUTS */
+/* M = log2 of fft size */
+/* *ioptr = input data array */
+/* *Utbl = cosine table */
+/* Rows = number of rows in ioptr array (use Rows of 1 if ioptr is a 1 dimensional array) */
+/* OUTPUTS */
+/* *ioptr = output data array */
+
+void diffts(double *ioptr, long M, long Rows, double *Utbl);
+/* Compute in-place inverse complex fft on the rows of the input array */
+/* INPUTS */
+/* M = log2 of fft size */
+/* *ioptr = input data array */
+/* *Utbl = cosine table */
+/* Rows = number of rows in ioptr array (use Rows of 1 if ioptr is a 1 dimensional array) */
+/* OUTPUTS */
+/* *ioptr = output data array */
+
+void drffts(double *ioptr, long M, long Rows, double *Utbl);
+/* Compute in-place real fft on the rows of the input array */
+/* INPUTS */
+/* M = log2 of fft size */
+/* *ioptr = real input data array */
+/* *Utbl = cosine table */
+/* Rows = number of rows in ioptr array (use Rows of 1 if ioptr is a 1 dimensional array) */
+/* OUTPUTS */
+/* *ioptr = output data array in the following order */
+/* Re(x[0]), Re(x[N/2]), Re(x[1]), Im(x[1]), Re(x[2]), Im(x[2]), ... Re(x[N/2-1]), Im(x[N/2-1]). */
+
+
+void driffts(double *ioptr, long M, long Rows, double *Utbl);
+/* Compute in-place real ifft on the rows of the input array */
+/* INPUTS */
+/* M = log2 of fft size */
+/* *ioptr = input data array in the following order */
+/* Re(x[0]), Re(x[N/2]), Re(x[1]), Im(x[1]), Re(x[2]), Im(x[2]), ... Re(x[N/2-1]), Im(x[N/2-1]). */
+/* *Utbl = cosine table */
+/* Rows = number of rows in ioptr array (use Rows of 1 if ioptr is a 1 dimensional array) */
+/* OUTPUTS */
+/* *ioptr = real output data array */
diff --git a/sc4pd/headers/common/fftlib.h b/sc4pd/headers/common/fftlib.h
new file mode 100644
index 0000000..b03317d
--- /dev/null
+++ b/sc4pd/headers/common/fftlib.h
@@ -0,0 +1,62 @@
+long FFTInit(long *fftMptr, long fftN, float *Utbl);
+/* Compute cosine table and check size for complex ffts */
+/* INPUTS */
+/* fftN = size of fft */
+/* OUTPUTS */
+/* *fftMptr = log2 of fft size */
+/* *Utbl = cosine table with fftN/4 + 1 entries (angles = 0 to pi/2 inclusive) */
+/* RETURNS */
+/* 1 if fftN is invalid, 0 otherwise */
+
+long rFFTInit(long *fftMptr, long fftN, float *Utbl);
+/* Compute cosine table and check size for a real input fft */
+/* INPUTS */
+/* fftN = size of fft */
+/* OUTPUTS */
+/* *fftMptr = log2 of fft size */
+/* *Utbl = cosine table with fftN/4 + 1 entries (angles = 0 to pi/2 inclusive) */
+/* RETURNS */
+/* 1 if fftN is invalid, 0 otherwise */
+
+void ffts(float *ioptr, long M, long Rows, float *Utbl);
+/* Compute in-place complex fft on the rows of the input array */
+/* INPUTS */
+/* M = log2 of fft size */
+/* *ioptr = input data array */
+/* *Utbl = cosine table */
+/* Rows = number of rows in ioptr array (use Rows of 1 if ioptr is a 1 dimensional array) */
+/* OUTPUTS */
+/* *ioptr = output data array */
+
+void iffts(float *ioptr, long M, long Rows, float *Utbl);
+/* Compute in-place inverse complex fft on the rows of the input array */
+/* INPUTS */
+/* M = log2 of fft size */
+/* *ioptr = input data array */
+/* *Utbl = cosine table */
+/* Rows = number of rows in ioptr array (use Rows of 1 if ioptr is a 1 dimensional array) */
+/* OUTPUTS */
+/* *ioptr = output data array */
+
+void rffts(float *ioptr, long M, long Rows, float *Utbl);
+/* Compute in-place real fft on the rows of the input array */
+/* INPUTS */
+/* M = log2 of fft size */
+/* *ioptr = real input data array */
+/* *Utbl = cosine table */
+/* Rows = number of rows in ioptr array (use Rows of 1 if ioptr is a 1 dimensional array) */
+/* OUTPUTS */
+/* *ioptr = output data array in the following order */
+/* Re(x[0]), Re(x[N/2]), Re(x[1]), Im(x[1]), Re(x[2]), Im(x[2]), ... Re(x[N/2-1]), Im(x[N/2-1]). */
+
+
+void riffts(float *ioptr, long M, long Rows, float *Utbl);
+/* Compute in-place real ifft on the rows of the input array */
+/* INPUTS */
+/* M = log2 of fft size */
+/* *ioptr = input data array in the following order */
+/* Re(x[0]), Re(x[N/2]), Re(x[1]), Im(x[1]), Re(x[2]), Im(x[2]), ... Re(x[N/2-1]), Im(x[N/2-1]). */
+/* *Utbl = cosine table */
+/* Rows = number of rows in ioptr array (use Rows of 1 if ioptr is a 1 dimensional array) */
+/* OUTPUTS */
+/* *ioptr = real output data array */
diff --git a/sc4pd/headers/common/scsynthsend.h b/sc4pd/headers/common/scsynthsend.h
new file mode 100644
index 0000000..97f345b
--- /dev/null
+++ b/sc4pd/headers/common/scsynthsend.h
@@ -0,0 +1,191 @@
+/*
+ SuperCollider real time audio synthesis system
+ Copyright (c) 2002 James McCartney. All rights reserved.
+ http://www.audiosynth.com
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#ifndef _scpacket_
+#define _scpacket_
+
+#include "SC_Endian.h"
+#include "SC_Types.h"
+#include <stdexcept>
+
+struct netaddr {
+ int socket;
+ int addr;
+ int port;
+};
+typedef struct netaddr netaddr;
+
+#define kSCMaxPacketSize 8192
+
+struct scpacket {
+ int32 *wrpos, *endpos, *msgsizepos;
+ char *tagwrpos;
+ int inbundle;
+ int32 buf[kSCMaxPacketSize];
+
+ scpacket();
+ void reset();
+ void addi(int i);
+ void addii(int64 ii);
+ void addf(float f);
+ void addd(double f);
+ void adds(char *cstr);
+ void adds(char *src, size_t len);
+ void addb(uint8 *src, size_t len);
+ void addtag(char c);
+ void skip(int n);
+ void maketags(int n);
+ int size() { return (char*)wrpos - (char*)buf; }
+ char* data() { return (char*)buf; }
+
+ void sendudp(int socket, int addr, int port);
+
+ void OpenBundle(int64 time);
+ void CloseBundle();
+
+ void BeginMsg();
+ void EndMsg();
+};
+
+inline scpacket::scpacket() { reset(); }
+
+// ways to fail
+#define BUFFEROVERFLOW return
+//#define BUFFEROVERFLOW throw std::runtime_error("buffer overflow")
+
+inline void scpacket::reset()
+{
+ wrpos = buf;
+ endpos = buf + kSCMaxPacketSize;
+ inbundle = 0;
+}
+
+inline void scpacket::skip(int n)
+{
+ if (wrpos + n > endpos) BUFFEROVERFLOW;
+ wrpos += n;
+}
+
+inline void scpacket::addtag(char c)
+{
+ *tagwrpos++ = c;
+}
+
+inline void scpacket::maketags(int n)
+{
+ int size4 = (n + 4) >> 2;
+ tagwrpos = (char*)wrpos;
+ skip(size4);
+ wrpos[-1] = 0;
+}
+
+
+inline void scpacket::addi(int i)
+{
+ if (wrpos >= endpos) BUFFEROVERFLOW;
+ *wrpos++ = htonl(i);
+}
+
+inline void scpacket::addii(int64 ii)
+{
+ int i;
+ i = (int)(ii >> 32);
+ addi(i);
+ i = (int)ii;
+ addi(i);
+}
+
+inline void scpacket::addf(float f)
+{
+ if (wrpos >= endpos) BUFFEROVERFLOW;
+ elem32 slot;
+ slot.f = f;
+ *wrpos++ = htonl(slot.i);
+}
+
+inline void scpacket::addd(double f)
+{
+ if (wrpos >= endpos) BUFFEROVERFLOW;
+ elem64 slot;
+ slot.f = f;
+ *wrpos++ = htonl(slot.i >> 32);
+ *wrpos++ = htonl(slot.i & 0x00000000FFFFFFFF);
+}
+
+inline void scpacket::adds(char *src)
+{
+ size_t len = strlen(src);
+ size_t len4 = (len + 4) >> 2;
+ if (wrpos + len4 > endpos) BUFFEROVERFLOW;
+ wrpos[len4 - 1] = 0;
+ memcpy(wrpos, src, (size_t)len);
+ wrpos += len4;
+}
+
+inline void scpacket::adds(char *src, size_t len)
+{
+ size_t len4 = (len + 4) >> 2;
+ if (wrpos + len4 > endpos) BUFFEROVERFLOW;
+ wrpos[len4 - 1] = 0;
+ memcpy(wrpos, src, (size_t)len);
+ wrpos += len4;
+}
+
+// support binary objects
+inline void scpacket::addb(uint8 *src, size_t len)
+{
+ size_t len4 = (len + 3) >> 2;
+ if (wrpos + (len4 + 1) > endpos) BUFFEROVERFLOW;
+ wrpos[len4 - 1] = 0;
+ int32 swaplen = len;
+ *wrpos++ = htonl(swaplen);
+ memcpy(wrpos, src, (size_t)len);
+ wrpos += len4;
+}
+
+inline void scpacket::OpenBundle(int64 time)
+{
+ inbundle++;
+ adds("#bundle");
+ addii(time);
+}
+
+inline void scpacket::CloseBundle()
+{
+ if (inbundle) inbundle--;
+}
+
+inline void scpacket::BeginMsg()
+{
+ if (inbundle) {
+ msgsizepos = wrpos;
+ addi(0);
+ }
+}
+
+inline void scpacket::EndMsg()
+{
+ if (inbundle) {
+ *msgsizepos = htonl(((wrpos - msgsizepos) - 1) * sizeof(int32));
+ }
+}
+
+#endif
+