summaryrefslogtreecommitdiff
path: root/examples/loop.c
blob: 1be04a9a28418c65d5f70a852c2accec829c057f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <stdio.h>
#include <math.h>
#include <mossrose.h>
#include <portaudio.h>

#define PI 3.14159


#define SAMPLE_RATE 44100
#define N_CHANNELS 8

float f(float t)
{
	const int f0 = 440;
	const int f1 = 880;
	return ( t*f1 ) + ( (1-t)*f0 );
}

int main()
{
	float data[SAMPLE_RATE];
	for (long i=0; i<SAMPLE_RATE; i++) {
		float time = ((float)i)/SAMPLE_RATE;
		data[i] = sin(2*PI*f(time)*time);
	}

	struct mossrose_sound_t sound = {
		.left = data, .right = NULL, .mono = true, .len = SAMPLE_RATE
	};

	int err = mossrose_init(SAMPLE_RATE, N_CHANNELS, true);
	if (err != 0)
		fprintf(stderr, "FAILED TO INITIALIZE MOSSROSE\n");

	int chan = mossrose_play(&sound, -1, 5);
	Pa_Sleep(5000);

	mossrose_terminate();
	return 0;
}