├── LICENSE ├── README.md └── pd ├── es4encoder~ └── main.cpp ├── es5encoder~ ├── main.cpp └── makefile └── esx8cvencoder~ └── main.cpp /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Expert Sleepers Ltd 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | externals 2 | ========= 3 | 4 | Externals for Max/MSP, pd etc. supporting Expert Sleepers hardware 5 | -------------------------------------------------------------------------------- /pd/es4encoder~/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014 Expert Sleepers Ltd 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #include "m_pd.h" 24 | 25 | #include 26 | 27 | #if __LP64__ 28 | typedef unsigned int UInt32; 29 | typedef signed int SInt32; 30 | #else 31 | typedef unsigned long UInt32; 32 | typedef signed long SInt32; 33 | #endif 34 | 35 | #define ES_BITSTOFLOAT_SETUP() \ 36 | float btf_n_factor, btf_p_factor; \ 37 | btf_n_factor = -(float)0x800000; btf_p_factor = (float)0x800000; 38 | 39 | #define ES_BITSTOFLOAT( bits ) \ 40 | ( ( bits & 0x800000 ) ? ( (((float)(0xffffff&(-(SInt32)(bits)))) / btf_n_factor ) ) : ( ((float)(bits)) / btf_p_factor ) ) 41 | 42 | #define ES_FLOATTOBITS( f ) \ 43 | ( ( f < 0 ) ? ( 0x800000 | ( 0xffffff & -(SInt32)( (f) * btf_n_factor ) ) ) : ( (UInt32)( (f) * btf_p_factor ) ) ) 44 | 45 | // struct to represent the object's state 46 | typedef struct _es4encoder { 47 | t_object ob; 48 | t_sample m_dummy; 49 | 50 | t_inlet* m_in[4]; // inlets 2-5. inlet 1 is created by CLASS_MAINSIGNALIN 51 | t_outlet* m_out[2]; 52 | } t_es4encoder; 53 | 54 | // method prototypes 55 | extern "C" { 56 | void es4encoder_tilde_setup(void); 57 | void *es4encoder_new(t_symbol *s, int argc, t_atom *argv); 58 | void es4encoder_free(t_es4encoder *x); 59 | void es4encoder_dsp(t_es4encoder *x, t_signal **sp); 60 | t_int *es4encoder_perform(t_int *w); 61 | } 62 | 63 | // global class pointer variable 64 | static t_class *es4encoder_class = NULL; 65 | 66 | //*********************************************************************************************** 67 | 68 | void es4encoder_tilde_setup(void) 69 | { 70 | t_class *c = class_new(gensym("es4encoder~"), (t_newmethod)es4encoder_new, (t_method)es4encoder_free, sizeof(t_es4encoder), CLASS_DEFAULT, A_GIMME, 0); 71 | 72 | class_addmethod(c, (t_method)es4encoder_dsp, gensym("dsp"), A_CANT, 0); // Old 32-bit MSP dsp chain compilation for Max 5 and earlier 73 | 74 | CLASS_MAINSIGNALIN(c, t_es4encoder, m_dummy); 75 | 76 | es4encoder_class = c; 77 | } 78 | 79 | void *es4encoder_new(t_symbol *s, int argc, t_atom *argv) 80 | { 81 | t_es4encoder *x = (t_es4encoder *)pd_new(es4encoder_class); 82 | 83 | if (x) { 84 | for ( int i=0; i<4; ++i ) 85 | x->m_in[i] = inlet_new( &x->ob, &x->ob.ob_pd, &s_signal, &s_signal ); 86 | for ( int i=0; i<2; ++i ) 87 | x->m_out[i] = outlet_new( &x->ob, &s_signal ); 88 | } 89 | return (x); 90 | } 91 | 92 | void es4encoder_free(t_es4encoder *x) 93 | { 94 | for ( int i=0; i<4; ++i ) 95 | inlet_free( x->m_in[i] ); 96 | for ( int i=0; i<2; ++i ) 97 | outlet_free( x->m_out[i] ); 98 | } 99 | 100 | //*********************************************************************************************** 101 | 102 | void es4encoder_dsp(t_es4encoder *x, t_signal **sp) 103 | { 104 | dsp_add(es4encoder_perform, 9, x, sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[3]->s_vec, sp[4]->s_vec, 105 | sp[5]->s_vec, sp[6]->s_vec, 106 | sp[0]->s_n); 107 | } 108 | 109 | //*********************************************************************************************** 110 | 111 | t_int *es4encoder_perform(t_int *w) 112 | { 113 | // t_es4encoder *x = (t_es4encoder *)(w[1]); 114 | t_float *in1 = (t_float *)(w[2]); 115 | t_float *in2 = (t_float *)(w[3]); 116 | t_float *in3 = (t_float *)(w[4]); 117 | t_float *in4 = (t_float *)(w[5]); 118 | t_float *in5 = (t_float *)(w[6]); 119 | t_float *dstpL = (t_float *)(w[7]); 120 | t_float *dstpR = (t_float *)(w[8]); 121 | long n = (long)(w[9]); 122 | 123 | struct { 124 | int m_interfaceCategory; 125 | } m_preCompNoInterp; 126 | m_preCompNoInterp.m_interfaceCategory = 0; 127 | 128 | ES_BITSTOFLOAT_SETUP() 129 | 130 | while (n--) 131 | { 132 | UInt32 out1 = (UInt32)( std::max( 0.0f, std::min( 255.0f, *in1++ ) ) ); 133 | UInt32 out2 = (UInt32)( std::max( 0.0f, std::min( 255.0f, *in2++ ) ) ); 134 | UInt32 out3 = (UInt32)( std::max( 0.0f, std::min( 255.0f, *in3++ ) ) ); 135 | UInt32 out4 = (UInt32)( std::max( 0.0f, std::min( 255.0f, *in4++ ) ) ); 136 | UInt32 out5 = (UInt32)( std::max( 0.0f, std::min( 255.0f, *in5++ ) ) ); 137 | 138 | SInt32 bitsL = ( out1 << 16 ) | ( out2 << 8 ) | ( ( out5 << 0 ) & 0xf0 ); 139 | SInt32 bitsR = ( out3 << 16 ) | ( out4 << 8 ) | ( ( out5 << 4 ) & 0xf0 ); 140 | 141 | float floatL = ES_BITSTOFLOAT( bitsL ); 142 | float floatR = ES_BITSTOFLOAT( bitsR ); 143 | 144 | *dstpL++ = floatL; 145 | *dstpR++ = floatR; 146 | } 147 | 148 | return w + 10; 149 | } 150 | 151 | //*********************************************************************************************** 152 | -------------------------------------------------------------------------------- /pd/es5encoder~/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014 Expert Sleepers Ltd 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #include "m_pd.h" 24 | 25 | #include 26 | 27 | #if __LP64__ 28 | typedef unsigned int UInt32; 29 | typedef signed int SInt32; 30 | #else 31 | typedef unsigned long UInt32; 32 | typedef signed long SInt32; 33 | #endif 34 | 35 | #define ES_BITSTOFLOAT_SETUP() \ 36 | float btf_n_factor, btf_p_factor; \ 37 | btf_n_factor = -(float)0x800000; btf_p_factor = (float)0x800000; 38 | 39 | #define ES_BITSTOFLOAT( bits ) \ 40 | ( ( bits & 0x800000 ) ? ( (((float)(0xffffff&(-(SInt32)(bits)))) / btf_n_factor ) ) : ( ((float)(bits)) / btf_p_factor ) ) 41 | 42 | #define ES_FLOATTOBITS( f ) \ 43 | ( ( f < 0 ) ? ( 0x800000 | ( 0xffffff & -(SInt32)( (f) * btf_n_factor ) ) ) : ( (UInt32)( (f) * btf_p_factor ) ) ) 44 | 45 | // struct to represent the object's state 46 | typedef struct _es5encoder { 47 | t_object ob; 48 | t_sample m_dummy; 49 | 50 | t_inlet* m_in[5]; // inlets 2-6. inlet 1 is created by CLASS_MAINSIGNALIN 51 | t_outlet* m_out[2]; 52 | } t_es5encoder; 53 | 54 | // method prototypes 55 | extern "C" { 56 | void es5encoder_tilde_setup(void); 57 | void *es5encoder_new(t_symbol *s, int argc, t_atom *argv); 58 | void es5encoder_free(t_es5encoder *x); 59 | void es5encoder_dsp(t_es5encoder *x, t_signal **sp); 60 | t_int *es5encoder_perform(t_int *w); 61 | } 62 | 63 | // global class pointer variable 64 | static t_class *es5encoder_class = NULL; 65 | 66 | //*********************************************************************************************** 67 | 68 | void es5encoder_tilde_setup(void) 69 | { 70 | t_class *c = class_new(gensym("es5encoder~"), (t_newmethod)es5encoder_new, (t_method)es5encoder_free, sizeof(t_es5encoder), CLASS_DEFAULT, A_GIMME, 0); 71 | 72 | class_addmethod(c, (t_method)es5encoder_dsp, gensym("dsp"), A_CANT, 0); // Old 32-bit MSP dsp chain compilation for Max 5 and earlier 73 | 74 | CLASS_MAINSIGNALIN(c, t_es5encoder, m_dummy); 75 | 76 | es5encoder_class = c; 77 | } 78 | 79 | void *es5encoder_new(t_symbol *s, int argc, t_atom *argv) 80 | { 81 | t_es5encoder *x = (t_es5encoder *)pd_new(es5encoder_class); 82 | 83 | if (x) { 84 | for ( int i=0; i<5; ++i ) 85 | x->m_in[i] = inlet_new( &x->ob, &x->ob.ob_pd, &s_signal, &s_signal ); 86 | for ( int i=0; i<2; ++i ) 87 | x->m_out[i] = outlet_new( &x->ob, &s_signal ); 88 | } 89 | return (x); 90 | } 91 | 92 | void es5encoder_free(t_es5encoder *x) 93 | { 94 | for ( int i=0; i<5; ++i ) 95 | inlet_free( x->m_in[i] ); 96 | for ( int i=0; i<2; ++i ) 97 | outlet_free( x->m_out[i] ); 98 | } 99 | 100 | //*********************************************************************************************** 101 | 102 | void es5encoder_dsp(t_es5encoder *x, t_signal **sp) 103 | { 104 | dsp_add(es5encoder_perform, 10, x, sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[3]->s_vec, sp[4]->s_vec, sp[5]->s_vec, 105 | sp[6]->s_vec, sp[7]->s_vec, 106 | sp[0]->s_n); 107 | } 108 | 109 | //*********************************************************************************************** 110 | 111 | t_int *es5encoder_perform(t_int *w) 112 | { 113 | // t_es5encoder *x = (t_es5encoder *)(w[1]); 114 | t_float *in1 = (t_float *)(w[2]); 115 | t_float *in2 = (t_float *)(w[3]); 116 | t_float *in3 = (t_float *)(w[4]); 117 | t_float *in4 = (t_float *)(w[5]); 118 | t_float *in5 = (t_float *)(w[6]); 119 | t_float *in6 = (t_float *)(w[7]); 120 | t_float *dstpL = (t_float *)(w[8]); 121 | t_float *dstpR = (t_float *)(w[9]); 122 | long n = (long)(w[10]); 123 | 124 | struct { 125 | int m_interfaceCategory; 126 | } m_preCompNoInterp; 127 | m_preCompNoInterp.m_interfaceCategory = 0; 128 | 129 | ES_BITSTOFLOAT_SETUP() 130 | 131 | while (n--) 132 | { 133 | UInt32 out1 = (UInt32)( std::max( 0.0f, std::min( 255.0f, *in1++ ) ) ); 134 | UInt32 out2 = (UInt32)( std::max( 0.0f, std::min( 255.0f, *in2++ ) ) ); 135 | UInt32 out3 = (UInt32)( std::max( 0.0f, std::min( 255.0f, *in3++ ) ) ); 136 | UInt32 out4 = (UInt32)( std::max( 0.0f, std::min( 255.0f, *in4++ ) ) ); 137 | UInt32 out5 = (UInt32)( std::max( 0.0f, std::min( 255.0f, *in5++ ) ) ); 138 | UInt32 out6 = (UInt32)( std::max( 0.0f, std::min( 255.0f, *in6++ ) ) ); 139 | 140 | SInt32 bitsL = ( out1 << 16 ) | ( out2 << 8 ) | out3; 141 | SInt32 bitsR = ( out4 << 16 ) | ( out5 << 8 ) | out6; 142 | 143 | float floatL = ES_BITSTOFLOAT( bitsL ); 144 | float floatR = ES_BITSTOFLOAT( bitsR ); 145 | 146 | *dstpL++ = floatL; 147 | *dstpR++ = floatR; 148 | } 149 | 150 | return w + 11; 151 | } 152 | 153 | //*********************************************************************************************** 154 | -------------------------------------------------------------------------------- /pd/es5encoder~/makefile: -------------------------------------------------------------------------------- 1 | current: pd_linux 2 | 3 | clean: ; rm -f *.pd_linux *.o 4 | 5 | # ----------------------- LINUX i386 ----------------------- 6 | 7 | LINUXCFLAGS = -DPD -O2 -funroll-loops -fomit-frame-pointer \ 8 | -Wall -W -Wshadow -Werror -fPIC \ 9 | -Wno-unused -Wno-parentheses -Wno-switch 10 | 11 | LINUXINCLUDE = -I../../pd-0.45-4/src 12 | 13 | pd_linux: 14 | g++ $(LINUXCFLAGS) $(LINUXINCLUDE) -o main.o -c main.cpp 15 | g++ -shared -o es5encoder~.pd_linux main.o -lc -lm 16 | strip --strip-unneeded es5encoder~.pd_linux 17 | 18 | # ----------------------- NT ----------------------- 19 | 20 | pd_nt: es5encoder~.dll 21 | 22 | .SUFFIXES: .obj .dll 23 | 24 | PDNTCFLAGS = /W3 /WX /DNT /DPD /nologo /wd4091 25 | VC="C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC" 26 | 27 | PDNTINCLUDE = /I. /I\tcl\include /I..\..\..\..\3rdparty\pd\src /I$(VC)\include 28 | 29 | PDNTLDIR = $(VC)\lib 30 | PDNTLIB = $(PDNTLDIR)\oldnames.lib \ 31 | ..\..\..\..\3rdparty\pd-0.45-4.msw\bin\pd.lib 32 | 33 | # override explicitly for tilde objects like this: 34 | es5encoder~.dll: main.cpp; 35 | cl $(PDNTCFLAGS) $(PDNTINCLUDE) /c main.cpp 36 | link /dll /export:es5encoder_tilde_setup main.obj $(PDNTLIB) /OUT:es5encoder~.dll 37 | -------------------------------------------------------------------------------- /pd/esx8cvencoder~/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014 Expert Sleepers Ltd 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #include "m_pd.h" 24 | 25 | #include 26 | 27 | #if __LP64__ 28 | typedef unsigned int UInt32; 29 | typedef signed int SInt32; 30 | #else 31 | typedef unsigned long UInt32; 32 | typedef signed long SInt32; 33 | #endif 34 | 35 | // struct to represent the object's state 36 | typedef struct _esx8cvencoder { 37 | t_object ob; 38 | int m_phase; 39 | UInt32 m_value; 40 | t_sample m_dummy; 41 | 42 | t_inlet* m_in[7]; // inlets 2-8. inlet 1 is created by CLASS_MAINSIGNALIN 43 | t_outlet* m_out[1]; 44 | } t_esx8cvencoder; 45 | 46 | // method prototypes 47 | extern "C" { 48 | void esx8cvencoder_tilde_setup(void); 49 | void *esx8cvencoder_new(t_symbol *s, long argc, t_atom *argv); 50 | void esx8cvencoder_free(t_esx8cvencoder *x); 51 | void esx8cvencoder_dsp(t_esx8cvencoder *x, t_signal **sp); 52 | t_int *esx8cvencoder_perform(t_int *w); 53 | } 54 | 55 | // global class pointer variable 56 | static t_class *esx8cvencoder_class = NULL; 57 | 58 | //*********************************************************************************************** 59 | 60 | void esx8cvencoder_tilde_setup(void) 61 | { 62 | t_class *c = class_new(gensym("esx8cvencoder~"), (t_newmethod)esx8cvencoder_new, (t_method)esx8cvencoder_free, (long)sizeof(t_esx8cvencoder), CLASS_DEFAULT, A_GIMME, 0); 63 | 64 | class_addmethod(c, (t_method)esx8cvencoder_dsp, gensym("dsp"), A_CANT, 0); // Old 32-bit MSP dsp chain compilation for Max 5 and earlier 65 | 66 | CLASS_MAINSIGNALIN(c, t_esx8cvencoder, m_dummy); 67 | 68 | esx8cvencoder_class = c; 69 | } 70 | 71 | void *esx8cvencoder_new(t_symbol *s, long argc, t_atom *argv) 72 | { 73 | t_esx8cvencoder *x = (t_esx8cvencoder *)pd_new(esx8cvencoder_class); 74 | 75 | if (x) { 76 | x->m_phase = 0; 77 | x->m_value = 0; 78 | for ( int i=0; i<7; ++i ) 79 | x->m_in[i] = inlet_new( &x->ob, &x->ob.ob_pd, &s_signal, &s_signal ); 80 | for ( int i=0; i<1; ++i ) 81 | x->m_out[i] = outlet_new( &x->ob, &s_signal ); 82 | } 83 | return (x); 84 | } 85 | 86 | void esx8cvencoder_free(t_esx8cvencoder *x) 87 | { 88 | for ( int i=0; i<7; ++i ) 89 | inlet_free( x->m_in[i] ); 90 | for ( int i=0; i<1; ++i ) 91 | outlet_free( x->m_out[i] ); 92 | } 93 | 94 | //*********************************************************************************************** 95 | 96 | void esx8cvencoder_dsp(t_esx8cvencoder *x, t_signal **sp) 97 | { 98 | dsp_add(esx8cvencoder_perform, 11, x, sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[3]->s_vec, sp[4]->s_vec, sp[5]->s_vec, sp[6]->s_vec, sp[7]->s_vec, 99 | sp[8]->s_vec, 100 | sp[0]->s_n); 101 | } 102 | 103 | //*********************************************************************************************** 104 | 105 | t_int *esx8cvencoder_perform(t_int *w) 106 | { 107 | t_esx8cvencoder *x = (t_esx8cvencoder *)(w[1]); 108 | t_float* srcp[8]; 109 | srcp[0] = (t_float *)(w[2]); 110 | srcp[1] = (t_float *)(w[3]); 111 | srcp[2] = (t_float *)(w[4]); 112 | srcp[3] = (t_float *)(w[5]); 113 | srcp[4] = (t_float *)(w[6]); 114 | srcp[5] = (t_float *)(w[7]); 115 | srcp[6] = (t_float *)(w[8]); 116 | srcp[7] = (t_float *)(w[9]); 117 | t_float *dstp = (t_float *)(w[10]); 118 | long n = (long)(w[11]); 119 | 120 | int phase = x->m_phase; 121 | UInt32 value = x->m_value; 122 | bool smuxProof = false; 123 | if ( !smuxProof ) 124 | phase = phase & ~1; 125 | int phaseInc = smuxProof ? 1 : 2; 126 | 127 | double values[8]; 128 | 129 | while (n--) 130 | { 131 | for ( int i=0; i<8; ++i ) 132 | { 133 | values[i] = *srcp[i]++; 134 | } 135 | 136 | int state = ( phase >> 1 ) & 3; 137 | int dac = ( phase >> 3 ) & 7; 138 | 139 | if ( state == 0 ) 140 | { 141 | { 142 | // take the next dac in sequence 143 | double s = values[ dac ]; 144 | value = 2048 + (SInt32)( std::max( -2048.0, std::min( 2047.0, s ) ) ); 145 | } 146 | } 147 | 148 | phase += phaseInc; 149 | if ( ( phase & 7 ) == 6 ) 150 | phase += 2; 151 | phase = phase & 63; 152 | 153 | UInt32 out = ( state == 0 ) ? ( 0x80 | ( value & 0x1f ) ) 154 | : ( ( state == 1 ) ? ( ( value >> 5 ) & 0x1f ) 155 | : ( ( ( dac > 3 ) ? 0x40 : 0x20 ) | ( value >> 10 ) | ( ( dac & 3 ) << 2 ) ) ); 156 | 157 | *dstp++ = (float)out; 158 | } 159 | 160 | x->m_phase = phase; 161 | x->m_value = value; 162 | 163 | return w + 12; 164 | } 165 | 166 | //*********************************************************************************************** 167 | --------------------------------------------------------------------------------