Skip to content

Instantly share code, notes, and snippets.

static inline void dMax_processK(const float *bIn, const float k, float *bOut, int n) {
n &= 0x3;
#if __ARM_NEON__
const float32x4_t x = vdupq_n_f32(k);
while (n) {
vst1q_f32(bOut, vmaxq_f32(vld1q_f32(bIn), x)); // bOut = max(bIn, k)
n -= 4; bIn += 4; bOut += 4;
}
#elif __SSE__
const __m128 x = _mm_set1_ps(k);
@diplojocus
diplojocus / basic_setup.c
Last active August 29, 2015 14:14
Heavy - Getting Started
#include "Heavy_heavy.h"
int main(int argc, const char *argv[]) {
double sampleRate = 44100.0;
Hv_heavy *context = hv_heavy_new(sampleRate);
int numInputChannels = hv_getNumInputChannels(context);
int numOutputChannels = hv_getNumOutputChannels(context);
@diplojocus
diplojocus / inline_process.c
Last active August 29, 2015 14:14
Heavy - Processing Inline Buffers
#include <mm_malloc.h>
#include "Heavy_heavy.h"
int main(int argc, const char *argv[]) {
double sampleRate = 44100.0;
Hv_heavy *context = hv_heavy_new(sampleRate);
int numOutputChannels = hv_getNumOutputChannels(context);
int numIterations = 100;
@diplojocus
diplojocus / process.c
Last active August 29, 2015 14:14
Heavy - Processing Buffers
#include <mm_malloc.h>
#include "Heavy_heavy.h"
int main(int argc, const char *argv[]) {
double sampleRate = 44100.0;
Hv_heavy *context = hv_heavy_new(sampleRate);
int numOutputChannels = hv_getNumOutputChannels(context);
int numIterations = 100;
@diplojocus
diplojocus / sending_messages.c
Last active August 29, 2015 14:14
Heavy - Sending Messages
#include "Heavy_heavy.h"
int main(int argc, const char *argv[]) {
Hv_heavy *context = hv_heavy_new(44100.0);
// create a message with the contents 'test-value 0.5f'
int numElements = 2;
HvMessage *msg = (HvMessage *) hv_alloca(hv_msg_getByteSize(numElements));
hv_msg_init(msg, numElements, 0.0);
hv_msg_setSymbol(msg, 0, "test-value");
@diplojocus
diplojocus / debug.c
Last active August 29, 2015 14:14
Heavy - Print Debugging
#include <stdio.h>
#include "Heavy_heavy.h"
void printHook(double timestampSecs, const char *printLabel, const char *msgString, void *userData) {
printf("[@ %.3f] %s: %s\n", timestampSecs, printLabel, msgString);
}
int main(int argc, const char *argv[]) {
Hv_heavy *context = hv_heavy_new(0, 0, 44100.0);
@diplojocus
diplojocus / heavy_api_patch.c
Last active August 29, 2015 14:14
Patch specific Heavy API methods
/**
* Creates a new patch instance.
* Sample rate should be positive and in Hertz.
*/
Hv_heavy *hv_heavy_new(double sampleRate);
/** Frees a patch instance. */
void hv_heavy_free(Hv_heavy *c);
/** Processes one block of samples for a patch instance. The buffer format is an array of arrays. */
@diplojocus
diplojocus / heavy_api_common.c
Created February 1, 2015 23:59
Commons Heavy API methods
/** Returns the sample rate with which this patch has been configured. */
double hv_getSampleRate(Heavy *c);
/** Returns the number of input channels with which this patch has been configured. */
int hv_getNumInputChannels(Heavy *c);
/** Returns the number of output channels with which this patch has been configured. */
int hv_getNumOutputChannels(Heavy *c);
/** Set the print hook. The function is called whenever a message is sent to a print object. */
@diplojocus
diplojocus / heavy_api_messages.c
Last active August 29, 2015 14:14
Message specific Heavy API methods
/** Returns the byte size of a HvMessage with a number of elements on the heap. */
hv_size_t hv_msg_getByteSize(int numElements);
/** Create a HvMessage on the stack with a number of elements. This message does MUST NOT be freed. */
HvMessage *hv_msg_onStack(hv_uint32_t numElements) {
return (HvMessage *) hv_alloca(hv_msg_getByteSize(numElements)); // this will not work until Utils.h is included
}
/** Initialise a message with the number of elements and a timestamp (in milliseconds). */
void hv_msg_init(HvMessage *m, int numElements, double timestamp);