History

add buffer to ugens and accessor for external ugens

Jack Atherton committed 9 years ago

Commit 98ba93b1 parent 11748e48 files · +122 −204Browse files

Unified · Split

8 files
  1. src/core/chuck.cpp +15 −0
  2. src/core/chuck.h +1 −0
  3. src/core/chuck.tab.h +0 −203
  4. src/core/chuck_lang.cpp +1 −1
  5. src/core/chuck_ugen.cpp +75 −0
  6. src/core/chuck_ugen.h +4 −0
  7. src/core/chuck_vm.cpp +24 −0
  8. src/core/chuck_vm.h +2 −0
src/core/chuck.cpp+15−0
@@ -1017,6 +1017,21 @@ t_CKBOOL ChucK::stopListeningForExternalEvent( const char * name, · 1016 unmodified lines
10171017
10181018
10191019
1020+//-----------------------------------------------------------------------------
1021+// name: getExternalUGenSamples()
1022+// desc: directly get ugen samples (call only from audio thread!!!)
1023+//-----------------------------------------------------------------------------
1024+t_CKBOOL ChucK::getExternalUGenSamples( const char * name,
1025+ SAMPLE * buffer, int numSamples )
1026+{
1027+ if( !m_carrier->vm->running() ) return FALSE;
1028+ return m_carrier->vm->get_external_ugen_samples(
1029+ std::string( name ), buffer, numSamples );
1030+}
1031+
1032+
1033+
1034+
10201035 //-----------------------------------------------------------------------------
10211036 // name: setChoutCallback()
10221037 // desc: provide a callback where Chout print statements are routed
src/core/chuck.h+1−0
@@ -136,6 +136,7 @@ public: · 135 unmodified lines
136136 t_CKBOOL broadcastExternalEvent( const char * name );
137137 t_CKBOOL listenForExternalEvent( const char * name, void (* callback)(void), t_CKBOOL listen_forever );
138138 t_CKBOOL stopListeningForExternalEvent( const char * name, void (* callback)(void) );
139+ t_CKBOOL getExternalUGenSamples( const char * name, SAMPLE * buffer, int numSamples );
139140
140141 public:
141142 // external callback functions
src/core/chuck.tab.h+0−203
@@ -1,203 +0,0 @@
1−/* A Bison parser, made by GNU Bison 3.0.4. */
2−
3−/* Bison interface for Yacc-like parsers in C
4−
5− Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
6−
7− This program is free software: you can redistribute it and/or modify
8− it under the terms of the GNU General Public License as published by
9− the Free Software Foundation, either version 3 of the License, or
10− (at your option) any later version.
11−
12− This program is distributed in the hope that it will be useful,
13− but WITHOUT ANY WARRANTY; without even the implied warranty of
14− MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15− GNU General Public License for more details.
16−
17− You should have received a copy of the GNU General Public License
18− along with this program. If not, see <http://www.gnu.org/licenses/>. */
19−
20−/* As a special exception, you may create a larger work that contains
21− part or all of the Bison parser skeleton and distribute that work
22− under terms of your choice, so long as that work isn't itself a
23− parser generator using the skeleton or a modified version thereof
24− as a parser skeleton. Alternatively, if you modify or redistribute
25− the parser skeleton itself, you may (at your option) remove this
26− special exception, which will cause the skeleton and the resulting
27− Bison output files to be licensed under the GNU General Public
28− License without this special exception.
29−
30− This special exception was added by the Free Software Foundation in
31− version 2.2 of Bison. */
32−
33−#ifndef YY_YY_CHUCK_TAB_H_INCLUDED
34−# define YY_YY_CHUCK_TAB_H_INCLUDED
35−/* Debug traces. */
36−#ifndef YYDEBUG
37−# define YYDEBUG 0
38−#endif
39−#if YYDEBUG
40−extern int yydebug;
41−#endif
42−
43−/* Token type. */
44−#ifndef YYTOKENTYPE
45−# define YYTOKENTYPE
46− enum yytokentype
47− {
48− ID = 258,
49− STRING_LIT = 259,
50− CHAR_LIT = 260,
51− NUM = 261,
52− FLOAT = 262,
53− POUND = 263,
54− COMMA = 264,
55− COLON = 265,
56− SEMICOLON = 266,
57− LPAREN = 267,
58− RPAREN = 268,
59− LBRACK = 269,
60− RBRACK = 270,
61− LBRACE = 271,
62− RBRACE = 272,
63− DOT = 273,
64− PLUS = 274,
65− MINUS = 275,
66− TIMES = 276,
67− DIVIDE = 277,
68− PERCENT = 278,
69− EQ = 279,
70− NEQ = 280,
71− LT = 281,
72− LE = 282,
73− GT = 283,
74− GE = 284,
75− AND = 285,
76− OR = 286,
77− ASSIGN = 287,
78− IF = 288,
79− THEN = 289,
80− ELSE = 290,
81− WHILE = 291,
82− FOR = 292,
83− DO = 293,
84− LOOP = 294,
85− BREAK = 295,
86− CONTINUE = 296,
87− NULL_TOK = 297,
88− FUNCTION = 298,
89− RETURN = 299,
90− QUESTION = 300,
91− EXCLAMATION = 301,
92− S_OR = 302,
93− S_AND = 303,
94− S_XOR = 304,
95− PLUSPLUS = 305,
96− MINUSMINUS = 306,
97− DOLLAR = 307,
98− POUNDPAREN = 308,
99− PERCENTPAREN = 309,
100− ATPAREN = 310,
101− SIMULT = 311,
102− PATTERN = 312,
103− CODE = 313,
104− TRANSPORT = 314,
105− HOST = 315,
106− TIME = 316,
107− WHENEVER = 317,
108− NEXT = 318,
109− UNTIL = 319,
110− EXTERNAL = 320,
111− EVERY = 321,
112− BEFORE = 322,
113− AFTER = 323,
114− AT = 324,
115− AT_SYM = 325,
116− ATAT_SYM = 326,
117− NEW = 327,
118− SIZEOF = 328,
119− TYPEOF = 329,
120− SAME = 330,
121− PLUS_CHUCK = 331,
122− MINUS_CHUCK = 332,
123− TIMES_CHUCK = 333,
124− DIVIDE_CHUCK = 334,
125− S_AND_CHUCK = 335,
126− S_OR_CHUCK = 336,
127− S_XOR_CHUCK = 337,
128− SHIFT_RIGHT_CHUCK = 338,
129− SHIFT_LEFT_CHUCK = 339,
130− PERCENT_CHUCK = 340,
131− SHIFT_RIGHT = 341,
132− SHIFT_LEFT = 342,
133− TILDA = 343,
134− CHUCK = 344,
135− COLONCOLON = 345,
136− S_CHUCK = 346,
137− AT_CHUCK = 347,
138− LEFT_S_CHUCK = 348,
139− UNCHUCK = 349,
140− UPCHUCK = 350,
141− CLASS = 351,
142− INTERFACE = 352,
143− EXTENDS = 353,
144− IMPLEMENTS = 354,
145− PUBLIC = 355,
146− PROTECTED = 356,
147− PRIVATE = 357,
148− STATIC = 358,
149− ABSTRACT = 359,
150− CONST = 360,
151− SPORK = 361,
152− ARROW_RIGHT = 362,
153− ARROW_LEFT = 363,
154− L_HACK = 364,
155− R_HACK = 365
156− };
157−#endif
158−
159−/* Value type. */
160−#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
161−
162−union YYSTYPE
163−{
164−#line 59 "chuck.y" /* yacc.c:1909 */
165−
166− int pos;
167− int ival;
168− double fval;
169− c_str sval;
170−
171− a_Program program;
172− a_Section program_section;
173− a_Stmt_List stmt_list;
174− a_Class_Def class_def;
175− a_Class_Ext class_ext;
176− a_Class_Body class_body;
177− a_Stmt stmt;
178− a_Exp exp;
179− a_Func_Def func_def;
180− a_Var_Decl_List var_decl_list;
181− a_Var_Decl var_decl;
182− a_Type_Decl type_decl;
183− a_Arg_List arg_list;
184− a_Id_List id_list;
185− a_Array_Sub array_sub;
186− a_Complex complex_exp;
187− a_Polar polar_exp;
188− a_Vec vec_exp; // ge: added 1.3.5.3
189−
190−#line 191 "chuck.tab.h" /* yacc.c:1909 */
191−};
192−
193−typedef union YYSTYPE YYSTYPE;
194−# define YYSTYPE_IS_TRIVIAL 1
195−# define YYSTYPE_IS_DECLARED 1
196−#endif
197−
198−
199−extern YYSTYPE yylval;
200−
201−int yyparse (void);
202−
203−#endif /* !YY_YY_CHUCK_TAB_H_INCLUDED */
src/core/chuck_lang.cpp+1−1
@@ -2427,7 +2427,7 @@ CK_DLL_MFUN( ugen_buffered ) · 2426 unmodified lines
24272427 // get arg
24282428 t_CKINT buffered = GET_CK_INT( ARGS );
24292429 // set op
2430− ugen->m_is_buffered = buffered;
2430+ ugen->set_is_buffered( buffered );
24312431 // set return
24322432 RETURN->v_int = ugen->m_is_buffered;
24332433
src/core/chuck_ugen.cpp+75−0
@@ -223,6 +223,8 @@ void Chuck_UGen::init() · 222 unmodified lines
223223
224224 // yes more hacks (add some time after REFACTOR-2017)
225225 m_is_buffered = FALSE;
226+ // buffer empty for any ugen that is not buffered
227+ m_buffer.resize( 0 );
226228 }
227229
228230
@@ -366,6 +368,62 @@ t_CKUINT Chuck_UGen::get_num_src() · 137 unmodified lines
366368
367369
368370
371+//-----------------------------------------------------------------------------
372+// name: set_is_buffered()
373+// dsec: set whether we should store our old samples
374+//-----------------------------------------------------------------------------
375+t_CKBOOL Chuck_UGen::set_is_buffered( t_CKBOOL buffered )
376+{
377+ // check if value is really changing. if not, return
378+ if( ( buffered && m_is_buffered ) || ( !buffered && !m_is_buffered ) )
379+ {
380+ return TRUE;
381+ }
382+
383+ if( buffered )
384+ {
385+ // alloc
386+ // (TODO: smarter way of maximum size of my buffer)
387+ m_buffer.resize( 8192 );
388+ }
389+ else
390+ {
391+ // dealloc
392+ m_buffer.resize( 0 );
393+ }
394+
395+ // store flag
396+ m_is_buffered = buffered;
397+
398+ return TRUE;
399+
400+}
401+
402+
403+
404+
405+//-----------------------------------------------------------------------------
406+// name: get_buffer()
407+// dsec: get the most recent buffer of samples
408+//-----------------------------------------------------------------------------
409+void Chuck_UGen::get_buffer( SAMPLE * buffer, t_CKINT num_elem )
410+{
411+ if( m_is_buffered )
412+ {
413+ // if we actually store our samples, give them num_elem of them
414+ m_buffer.get( buffer, num_elem );
415+ }
416+ else
417+ {
418+ // otherwise, give them 0
419+ memset( buffer, 0, sizeof( SAMPLE ) * num_elem );
420+ }
421+}
422+
423+
424+
425+
426+
369427 //-----------------------------------------------------------------------------
370428 // name: src_chan()
371429 // desc: added 1.3.3.1
@@ -989,6 +1047,13 @@ t_CKBOOL Chuck_UGen::system_tick( t_CKTIME now ) · 617 unmodified lines
9891047 }
9901048 }
9911049
1050+ // store in buffer
1051+ if( m_is_buffered )
1052+ {
1053+ // m_current is the mono mixdown of all channels (if > 1)
1054+ m_buffer.put( m_current );
1055+ }
1056+
9921057 return m_valid;
9931058 }
9941059
@@ -1221,6 +1286,16 @@ t_CKBOOL Chuck_UGen::system_tick_v( t_CKTIME now, t_CKUINT numFrames ) · 226 unmodified lines
12211286 m_last = m_current_v[numFrames-1];
12221287 }
12231288
1289+ // store in buffer
1290+ if( m_is_buffered )
1291+ {
1292+ // m_current_v is the mono mixdown of all channels (if > 1)
1293+ for( j = 0; j < numFrames; j++ )
1294+ {
1295+ m_buffer.put( m_current_v[j] );
1296+ }
1297+ }
1298+
12241299 return m_valid;
12251300 }
12261301
src/core/chuck_ugen.h+4−0
@@ -39,6 +39,7 @@ · 38 unmodified lines
3939 #include "chuck_def.h"
4040 #include "chuck_oo.h"
4141 #include "chuck_dl.h"
42+#include "util_buffers.h"
4243
4344
4445 // forward reference
@@ -77,6 +78,8 @@ public: // src · 32 unmodified lines
7778 t_CKUINT system_tick( t_CKTIME now );
7879 t_CKUINT system_tick_v( t_CKTIME now, t_CKUINT numFrames );
7980 t_CKBOOL alloc_v( t_CKUINT size );
81+ t_CKBOOL set_is_buffered( t_CKBOOL buffered );
82+ void get_buffer( SAMPLE * buffer, t_CKINT num_elem );
8083
8184 Chuck_UGen *src_chan( t_CKUINT chan );
8285 Chuck_UGen *dst_for_src_chan( t_CKUINT chan );
@@ -157,6 +160,7 @@ public: // data · 74 unmodified lines
157160
158161 // what a hack! (added some time after REFACTOR-2017)
159162 t_CKBOOL m_is_buffered;
163+ AccumBuffer m_buffer;
160164 };
161165
162166
src/core/chuck_vm.cpp+24−0
@@ -1538,6 +1538,30 @@ Chuck_Event * * Chuck_VM::get_ptr_to_external_event( std::string name ) · 1537 unmodified lines
15381538
15391539
15401540
1541+//-----------------------------------------------------------------------------
1542+// name: init_external_ugen()
1543+// desc: tell the vm that an external ugen is now available
1544+//-----------------------------------------------------------------------------
1545+t_CKBOOL Chuck_VM::get_external_ugen_samples( std::string name,
1546+ SAMPLE * buffer, int numFrames )
1547+{
1548+ // if hasn't been init, or it has been init and hasn't been constructed,
1549+ if( m_external_ugens.count( name ) == 0 ||
1550+ should_call_external_ctor( name, te_externalUGen ) )
1551+ {
1552+ // fail without doing anything
1553+ return FALSE;
1554+ }
1555+
1556+ // else, fill (if the ugen isn't buffered, then it will fill with zeroes)
1557+ m_external_ugens[name]->val->get_buffer( buffer, numFrames );
1558+
1559+ return TRUE;
1560+}
1561+
1562+
1563+
1564+
15411565 //-----------------------------------------------------------------------------
15421566 // name: init_external_ugen()
15431567 // desc: tell the vm that an external ugen is now available
src/core/chuck_vm.h+2−0
@@ -667,6 +667,8 @@ public: · 666 unmodified lines
667667 t_CKBOOL listen_for_external_event( std::string name, void (* callback)(void), t_CKBOOL listen_forever );
668668 t_CKBOOL stop_listening_for_external_event( std::string name, void (* callback)(void) );
669669
670+ t_CKBOOL get_external_ugen_samples( std::string name, SAMPLE * buffer, int numFrames );
671+
670672 public:
671673 // REFACTOR-2017: externally accessible variables.
672674 // these internal functions are to be used only by other

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t