static void sEnv_sendMessage(HvBase *_c, SignalEnvelope *o, float rms, void (*sendMessage)(HvBase *, int, const HvMessage *)) { // finish RMS calculation. sqrt is removed as it can be combined with the log operation. // result is normalised such that 1 RMS == 100 dB rms = 10.0f * log10f(rms) + 100.0f; // prepare the outgoing message. Schedule it at the beginning of the next block. HvMessage *const m = HV_MESSAGE_ON_STACK(1); msg_initWithFloat(m, ctx_getBlockStartTimestamp(_c) + HV_N_SIMD, (rms < 0.0f) ? 0.0f : rms); ctx_scheduleMessage(Base(_c), m, sendMessage, 0); hv_memcpy(o->buffer, o->buffer+o->period, sizeof(float)*(o->numSamplesInBuffer - o->period)); o->numSamplesInBuffer -= o->period; }
void cSlice_onMessage(HvBase *_c, ControlSlice *o, int letIn, const HvMessage *const m, void (*sendMessage)(HvBase *, int, const HvMessage *const)) { switch (letIn) { case 0: { // if the start point is greater than the number of elements in the source message, do nothing if (o->i < msg_getNumElements(m)) { int x = msg_getNumElements(m) - o->i; // number of elements in the new message if (o->n > 0) x = hv_min_i(x, o->n); HvMessage *n = HV_MESSAGE_ON_STACK(x); msg_init(n, x, msg_getTimestamp(m)); hv_memcpy(&n->elem, &m->elem+o->i, x*sizeof(Element)); sendMessage(_c, 0, n); } else { // if nothing can be sliced, send a bang out of the right outlet HvMessage *n = HV_MESSAGE_ON_STACK(1); msg_initWithBang(n, msg_getTimestamp(m)); sendMessage(_c, 1, n); } break; } case 1: { if (msg_isFloat(m,0)) { o->i = (int) msg_getFloat(m,0); if (msg_isFloat(m,1)) { o->n = (int) msg_getFloat(m,1); } } break; } case 2: { if (msg_isFloat(m,0)) { o->n = (int) msg_getFloat(m,0); } break; } default: break; } }