void Levels_popDownTo(Levels *self, int targetLevel) { Level *level; while (level = List_top(self->stack), level->precedence <= targetLevel && level->type != ARG) { Level_finish(List_pop(self->stack)); self->currentLevel--; } }
PID_TYPE UDBIndex_nextPid(UDBIndex *self) { PID_TYPE hole = (PID_TYPE)List_top(self->holes); if (hole) { return hole; } return JFile_setPositionToEnd(self->file) / sizeof(UDBIndexEntry); }
void Levels_attachToTopAndPush(Levels *self, IoMessage *msg, int precedence) { Level *level = NULL; { Level *top = List_top(self->stack); Level_attachAndReplace(top, msg); } { // TODO: Check for overflow of the pool. if (self->currentLevel >= IO_OP_MAX_LEVEL) { IoState_error_(IoObject_state(msg), NULL, "compile error: Overflowed operator stack. Only %d levels of operators currently supported.", IO_OP_MAX_LEVEL-1); } level = &self->pool[self->currentLevel++]; Level_setAwaitingFirstArg(level, msg, precedence); List_append_(self->stack, level); } }
static IoToken *IoLexer_currentToken(IoLexer *self) { return List_top(self->tokenStream); }
Level *Levels_currentLevel(Levels *self) { return List_top(self->stack); }
int IoAudioMixer_mixOneChunk(IoAudioMixer *self, IoObject *locals, IoMessage *m) { UArray *mixBuffer = DATA(self)->mixBuffer; List *sounds = DATA(self)->sounds; List *soundsToRemove = DATA(self)->soundsToRemove; AudioEvent *e = List_top(DATA(self)->events); List *activeEvents = DATA(self)->activeEvents; int frame; /*int samplesPerBuffer = DATA(self)->samplesPerBuffer;*/ int samplesPerBuffer = UArray_size(DATA(self)->mixBuffer) / (sizeof(float) * 2); UArray_setAllBytesTo_(mixBuffer, 0); while ( e && (!e->ioTriggerSound)) { List_append_(DATA(self)->activeEvents, List_pop(DATA(self)->events)); e = List_top(DATA(self)->events); } if (List_size(activeEvents)) IoAudioMixer_processActiveEvents(self); if (List_size(soundsToRemove)) IoAudioMixer_processSoundRemovals(self); for (frame = 0; frame < samplesPerBuffer; frame ++) { int index = frame * 2; int i; float *ol = UArray_floatPointerAt_(mixBuffer, index); float *or = UArray_floatPointerAt_(mixBuffer, index+1); for (i = 0; i < List_size(sounds); i++) { IoSound *ioSound = List_at_(sounds, i); Sound *sound = IoSound_rawSound(ioSound); float left, right; char done = Sound_nextFloat(sound, &left, &right); if (done && !Sound_isLooping(sound)) { List_append_(soundsToRemove, ioSound); continue; } (*ol) += left; (*or) += right; while (e && ((!e->ioTriggerSound) || ((e->ioTriggerSound == ioSound) && (e->sample == Sound_position(sound)))) ) { List_append_(DATA(self)->activeEvents, List_pop(DATA(self)->events)); e = List_top(DATA(self)->events); } } (*ol) *= DATA(self)->scale; (*or) *= DATA(self)->scale; if (List_size(activeEvents)) IoAudioMixer_processActiveEvents(self); if (List_size(soundsToRemove)) IoAudioMixer_processSoundRemovals(self); } /* adjust pitch and tempo */ { //double t1 = ((double)clock())/((double)CLOCKS_PER_SEC); //double t2; int receivedSamples = 1; SoundTouch_putSamples(DATA(self)->soundTouch, (float *)UArray_bytes(mixBuffer), samplesPerBuffer); //printf("put %i\n", samplesPerBuffer); //while (receivedSamples) { UArray_setSize_(DATA(self)->buffer, 10000*8); receivedSamples = SoundTouch_receiveSamples(DATA(self)->soundTouch, (float *)UArray_bytes(DATA(self)->buffer), UArray_size(DATA(self)->buffer) / (sizeof(float) * 2)); UArray_setSize_(DATA(self)->buffer, receivedSamples * (sizeof(float) * 2)); //printf("received %i\n", receivedSamples); if (receivedSamples) { if (receivedSamples < 5000) { #ifdef DEBUG printf("non-blocking write\n"); #endif IoMessage_locals_performOn_(DATA(self)->nonBlockingWriteMessage, self, DATA(self)->ioAudioDevice); } else { IoMessage_locals_performOn_(DATA(self)->writeMessage, self, DATA(self)->ioAudioDevice); } } #ifdef DEBUG t2 = ((double)clock())/((double)CLOCKS_PER_SEC); printf("tempo: %1.1f %i -> %i in %0.2f sec\n", DATA(self)->tempo, samplesPerBuffer, receivedSamples, (float)(t2 - t1)); #endif } //printf("\n"); return receivedSamples; } /* need to change this to be dynamic, so we can easily record the output */ /*IoAudioDevice_justWrite(DATA(self)->ioAudioDevice, locals, m, buffer);*/ return UArray_size(DATA(self)->buffer) / 8; }