value lime_mouse_warp (value x, value y, value window) { Window* windowRef = 0; if (!val_is_null (window)) { windowRef = (Window*)(intptr_t)val_float (window); } Mouse::Warp (val_int (x), val_int (y), windowRef); return alloc_null (); }
int val_equal(const cst_val *v1, const cst_val *v2) { if (v1 == v2) return TRUE; /* its eq so its equal */ else if (v1 == 0) return FALSE; else if (CST_VAL_TYPE(v1) == CST_VAL_TYPE(v2)) { if (cst_val_consp(v1)) return ((val_equal(val_car(v1),val_car(v2))) && (val_equal(val_cdr(v1),val_cdr(v2)))); else if (CST_VAL_TYPE(v1) == CST_VAL_TYPE_INT) return (val_int(v1) == val_int(v2)); else if (CST_VAL_TYPE(v1) == CST_VAL_TYPE_FLOAT) return (val_float(v1) == val_float(v2)); else if (CST_VAL_TYPE(v1) == CST_VAL_TYPE_STRING) return (cst_streq(CST_VAL_STRING(v1),CST_VAL_STRING(v2))); else return CST_VAL_VOID(v1) == CST_VAL_VOID(v2); } else return FALSE; }
/** math_int : number -> int <doc>Return integer rounded down towards 0</doc> **/ static value math_int( value n ) { switch( val_type(n) ) { case VAL_INT: case VAL_INT32: return n; case VAL_FLOAT: { tfloat v = val_float(n); return alloc_best_int( (int)((n < 0) ? ceil(v) : floor(v)) ); } default: neko_error(); } }
value lime_bytes_from_data_pointer (value data, value length) { int size = val_int (length); intptr_t ptr = (intptr_t)val_float (data); Bytes bytes = Bytes (size); if (ptr) { memcpy (bytes.Data (), (const void*)ptr, size); } return bytes.Value (); }
value lime_alc_make_context_current (value context) { if (val_is_null (context)) { alcMakeContextCurrent (NULL); } else { ALCcontext* alcContext = (ALCcontext*)(intptr_t)val_float (context); alcMakeContextCurrent (alcContext); } return alloc_null (); }
cst_utterance *cart_duration(cst_utterance *u) { cst_cart *dur_tree; cst_item *s; float zdur, dur_stretch, local_dur_stretch, dur; float end; dur_stats *ds; const dur_stat *dur_stat; end = 0; if (feat_present(u->features,"no_segment_duration_model")) return u; /* not all methods need segment durations */ dur_tree = val_cart(feat_val(u->features,"dur_cart")); dur_stretch = get_param_float(u->features,"duration_stretch", 1.0); ds = val_dur_stats(feat_val(u->features,"dur_stats")); for (s=relation_head(utt_relation(u,"Segment")); s; s=item_next(s)) { zdur = val_float(cart_interpret(s,dur_tree)); dur_stat = phone_dur_stat(ds,item_name(s)); local_dur_stretch = ffeature_float(s, "R:SylStructure.parent.parent." "R:Token.parent.local_duration_stretch"); if (local_dur_stretch) local_dur_stretch *= dur_stretch; else local_dur_stretch = dur_stretch; dur = local_dur_stretch * ((zdur*dur_stat->stddev)+dur_stat->mean); DPRINTF(0,("phone %s accent %s stress %s pdur %f stretch %f mean %f std %f dur %f\n", item_name(s), ffeature_string(s,"R:SylStructure.parent.accented"), ffeature_string(s,"R:SylStructure.parent.stress"), zdur, local_dur_stretch, dur_stat->mean, dur_stat->stddev, dur)); end += dur; item_set_float(s,"end",end); } return u; }
value lime_alc_get_integerv (value device, value param, value size) { ALCdevice* alcDevice = (ALCdevice*)(intptr_t)val_float (device); int count = val_int (size); ALint* values = new ALint[count]; alcGetIntegerv (alcDevice, val_int (param), count, values); value result = alloc_array (count); for (int i = 0; i < count; ++i) { val_array_set_i (result, i, alloc_int (values[i])); } return result; }
void lime_al_sourcefv (int source, int param, value values) { if (val_is_null (values) == false) { int size = val_array_size (values); ALfloat *data = new ALfloat[size]; for (int i = 0; i < size; ++i) { data[i] = (ALfloat)val_float( val_array_i (values, i) ); } alSourcefv (source, param, data); delete[] data; } }
value lime_al_buffer3f (value buffer, value param, value value1, value value2, value value3) { alBuffer3f (val_int (buffer), val_int (param), val_float (value1), val_float (value2), val_float (value3)); return alloc_null (); }
value lime_al_doppler_velocity (value velocity) { alDopplerVelocity (val_float (velocity)); return alloc_null (); }
value lime_al_doppler_factor (value factor) { alDopplerFactor (val_float (factor)); return alloc_null (); }
int val_less(const cst_val *v1, const cst_val *v2) { return val_float(v1) < val_float(v2); }
value lime_alc_get_error (value device) { ALCdevice* alcDevice = (ALCdevice*)(intptr_t)val_float (device); return alloc_int (alcGetError (alcDevice)); }
value lime_al_sourcef (value source, value param, value value) { alSourcef (val_int (source), val_int (param), val_float (value)); return alloc_null (); }
value lime_al_listenerf (value param, value value1) { alListenerf (val_int (param), val_float (value1)); return alloc_null (); }
value lime_renderer_lock (value renderer) { return ((Renderer*)(intptr_t)val_float (renderer))->Lock (); }
void _ofxOscMessage_addFloatArg(value a,value b) { ofxOscMessage* oscMessage = (ofxOscMessage*) val_data(a); oscMessage->addFloatArg(val_float(b)); }
float feat_float(const cst_features *f, const char *name) { return val_float(feat_val(f,name)); }
void serialize_rec( sbuffer *b, value o ) { b->nrec++; if( b->nrec > 350 ) failure("Serialization stack overflow"); switch( val_type(o) ) { case VAL_NULL: write_char(b,'N'); break; case VAL_BOOL: if( val_bool(o) ) write_char(b,'T'); else write_char(b,'F'); break; case VAL_INT: write_char(b,'i'); write_int(b,val_int(o)); break; case VAL_FLOAT: write_char(b,'f'); write_str(b,sizeof(tfloat),&val_float(o)); break; case VAL_STRING: if( !write_ref(b,o,NULL) ) { write_char(b,'s'); write_int(b,val_strlen(o)); write_str(b,val_strlen(o),val_string(o)); } break; case VAL_OBJECT: { value s; if( !write_ref(b,o,&s) ) { if( s != NULL ) { // reference was not written if( !val_is_function(s) || (val_fun_nargs(s) != 0 && val_fun_nargs(s) != VAR_ARGS) ) failure("Invalid __serialize method"); write_char(b,'x'); serialize_rec(b,((neko_module*)((vfunction*)s)->module)->name); serialize_rec(b,val_ocall0(o,id_serialize)); // put reference back write_ref(b,o,NULL); break; } write_char(b,'o'); val_iter_fields(o,serialize_fields_rec,b); write_int(b,0); o = (value)((vobject*)o)->proto; if( o == NULL ) write_char(b,'z'); else { write_char(b,'p'); serialize_rec(b,o); } } } break; case VAL_ARRAY: if( !write_ref(b,o,NULL) ) { int i; int n = val_array_size(o); write_char(b,'a'); write_int(b,n); for(i=0;i<n;i++) serialize_rec(b,val_array_ptr(o)[i]); } break; case VAL_FUNCTION: if( !write_ref(b,o,NULL) ) { neko_module *m; if( val_tag(o) == VAL_PRIMITIVE ) { // assume that alloc_array(0) return a constant array ptr // we don't want to access custom memory (maybe not a ptr) if( ((vfunction*)o)->env != alloc_array(0) ) failure("Cannot Serialize Primitive with environment"); write_char(b,'p'); write_int(b,((vfunction*)o)->nargs); serialize_rec(b,((vfunction*)o)->module); break; } if( val_tag(o) == VAL_JITFUN ) failure("Cannot Serialize JIT method"); write_char(b,'L'); m = (neko_module*)((vfunction*)o)->module; serialize_rec(b,m->name); write_int(b,(int)((int_val*)((vfunction*)o)->addr - m->code)); write_int(b,((vfunction*)o)->nargs); serialize_rec(b,((vfunction*)o)->env); } break; case VAL_INT32: write_char(b,'I'); write_int(b,val_int32(o)); break; case VAL_ABSTRACT: if( val_is_kind(o,k_hash) ) { int i; vhash *h = val_hdata(o); write_char(b,'h'); write_int(b,h->ncells); write_int(b,h->nitems); for(i=0;i<h->ncells;i++) { hcell *c = h->cells[i]; while( c != NULL ) { write_int(b,c->hkey); serialize_rec(b,c->key); serialize_rec(b,c->val); c = c->next; } } break; } default: failure("Cannot Serialize Abstract"); break; } b->nrec--; }
static cst_utterance *cg_predict_params(cst_utterance *utt) { cst_cg_db *cg_db; cst_track *param_track; cst_track *str_track = NULL; cst_item *mcep; const cst_cart *mcep_tree, *f0_tree; int i,j,f,p,fd,o; const char *mname; float f0_val; int fff; int extra_feats = 0; cg_db = val_cg_db(utt_feat_val(utt,"cg_db")); param_track = new_track(); if (cg_db->do_mlpg) /* which should be the default */ fff = 1; /* copy details with stddevs */ else fff = 2; /* copy details without stddevs */ extra_feats = 1; /* voicing */ if (cg_db->mixed_excitation) { extra_feats += 5; str_track = new_track(); cst_track_resize(str_track, utt_feat_int(utt,"param_track_num_frames"), 5); } cst_track_resize(param_track, utt_feat_int(utt,"param_track_num_frames"), (cg_db->num_channels0/fff)- (2 * extra_feats));/* no voicing or str */ for (i=0,mcep=utt_rel_head(utt,"mcep"); mcep; i++,mcep=item_next(mcep)) { mname = item_feat_string(mcep,"name"); for (p=0; cg_db->types[p]; p++) if (cst_streq(mname,cg_db->types[p])) break; if (cg_db->types[0] == NULL) p=0; /* if there isn't a matching tree, use the first one */ /* Predict F0 */ f0_tree = cg_db->f0_trees[p]; f0_val = val_float(cart_interpret(mcep,f0_tree)); param_track->frames[i][0] = f0_val; /* what about stddev ? */ if (cg_db->multimodel) { /* MULTI model */ f = val_int(cart_interpret(mcep,cg_db->param_trees0[p])); fd = val_int(cart_interpret(mcep,cg_db->param_trees1[p])); item_set_int(mcep,"clustergen_param_frame",f); param_track->frames[i][0] = (param_track->frames[i][0]+ CG_MODEL_VECTOR(cg_db,model_vectors0,f,0)+ CG_MODEL_VECTOR(cg_db,model_vectors1,fd,0))/3.0; for (j=2; j<param_track->num_channels; j++) param_track->frames[i][j] = (CG_MODEL_VECTOR(cg_db,model_vectors0,f,(j)*fff)+ CG_MODEL_VECTOR(cg_db,model_vectors1,fd,(j)*fff))/2.0; if (cg_db->mixed_excitation) { o = j; for (j=0; j<5; j++) { str_track->frames[i][j] = (CG_MODEL_VECTOR(cg_db,model_vectors0,f,(o+(2*j))*fff)+ CG_MODEL_VECTOR(cg_db,model_vectors1,fd,(o+(2*j))*fff))/2.0; } } } else { /* SINGLE model */ /* Predict Spectral */ mcep_tree = cg_db->param_trees0[p]; f = val_int(cart_interpret(mcep,mcep_tree)); item_set_int(mcep,"clustergen_param_frame",f); param_track->frames[i][0] = (param_track->frames[i][0]+ CG_MODEL_VECTOR(cg_db,model_vectors0,f,0))/2.0; for (j=2; j<param_track->num_channels; j++) param_track->frames[i][j] = CG_MODEL_VECTOR(cg_db,model_vectors0,f,(j)*fff); if (cg_db->mixed_excitation) { o = j; for (j=0; j<5; j++) { str_track->frames[i][j] = CG_MODEL_VECTOR(cg_db,model_vectors0,f,(o+(2*j))*fff); } } } /* last coefficient is average voicing for cluster */ item_set_float(mcep,"voicing", CG_MODEL_VECTOR(cg_db,model_vectors0,f, cg_db->num_channels0-2)); param_track->times[i] = i * cg_db->frame_advance; } cg_smooth_F0(utt,cg_db,param_track); utt_set_feat(utt,"param_track",track_val(param_track)); if (cg_db->mixed_excitation) utt_set_feat(utt,"str_track",track_val(str_track)); return utt; }
int val_greater(const cst_val *v1,const cst_val *v2) { return val_float(v1) > val_float(v2); }
value lime_al_bufferf (value buffer, value param, value value) { alBufferf (val_int (buffer), val_int (param), val_float (value)); return alloc_null (); }
value lime_al_listener3f (value param, value value1, value value2, value value3) { alListener3f (val_int (param), val_float (value1), val_float (value2), val_float (value3)); return alloc_null (); }
value lime_alc_get_string (value device, value param) { ALCdevice* alcDevice = (ALCdevice*)(intptr_t)val_float (device); return alloc_string (alcGetString (alcDevice, val_int (param))); }
value lime_al_source3f (value source, value param, value value1, value value2, value value3) { alSource3f (val_int (source), val_int (param), val_float (value1), val_float (value2), val_float (value3)); return alloc_null (); }
value lime_renderer_get_type (value renderer) { Renderer* targetRenderer = (Renderer*)(intptr_t)val_float (renderer); return alloc_string (targetRenderer->Type ()); }
value lime_al_speed_of_sound (value speed) { alSpeedOfSound (val_float (speed)); return alloc_null (); }
value lime_al_distance_model (value distanceModel) { alDistanceModel (val_float (distanceModel)); return alloc_null (); }
static void val_buffer_rec( buffer b, value v, vlist *stack ) { char buf[32]; int i, l; vlist *vtmp = stack; while( vtmp != NULL ) { if( vtmp->v == v ) { buffer_append_sub(b,"...",3); return; } vtmp = vtmp->next; } switch( val_type(v) ) { case VAL_INT: buffer_append_sub(b,buf,sprintf(buf,"%d",val_int(v))); break; case VAL_STRING: buffer_append_sub(b,val_string(v),val_strlen(v)); break; case VAL_FLOAT: buffer_append_sub(b,buf,sprintf(buf,FLOAT_FMT,val_float(v))); break; case VAL_NULL: buffer_append_sub(b,"null",4); break; case VAL_BOOL: if( val_bool(v) ) buffer_append_sub(b,"true",4); else buffer_append_sub(b,"false",5); break; case VAL_FUNCTION: buffer_append_sub(b,buf,sprintf(buf,"#function:%d",val_fun_nargs(v))); break; case VAL_OBJECT: { value s = val_field(v,id_string); if( s != val_null ) s = val_callEx(v,s,NULL,0,NULL); if( val_is_string(s) ) buffer_append_sub(b,val_string(s),val_strlen(s)); else { vlist2 vtmp; vtmp.v = v; vtmp.next = stack; vtmp.b = b; vtmp.prev = 0; buffer_append_sub(b,"{",1); val_iter_fields(v,val_buffer_fields,&vtmp); if( vtmp.prev ) buffer_append_sub(b," }",2); else buffer_append_sub(b,"}",1); } break; } case VAL_ARRAY: buffer_append_sub(b,"[",1); l = val_array_size(v); { vlist vtmp; vtmp.v = v; vtmp.next = stack; for(i=0;i<l;i++) { value vi = val_array_ptr(v)[i]; val_buffer_rec(b,vi,&vtmp); if( i != l - 1 ) buffer_append_sub(b,",",1); } } buffer_append_sub(b,"]",1); break; case VAL_INT32: buffer_append_sub(b,buf,sprintf(buf,"%d",val_int32(v))); break; case VAL_ABSTRACT: buffer_append_sub(b,"#abstract",9); break; default: buffer_append_sub(b,"#unknown",8); break; } }
value lime_renderer_unlock (value renderer) { ((Renderer*)(intptr_t)val_float (renderer))->Unlock (); return alloc_null (); }