summaryrefslogtreecommitdiff
path: root/examples/example.c
blob: 5e65d82f38456c4161b0c3659cd7c2387050bbad (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <stdio.h>
#include <math.h>
#include <mossrose.h>
#include <portaudio.h>

#define PI 3.14159


#define SAMPLE_RATE 44100
#define N_CHANNELS 8

int main()
{
	float sin1[SAMPLE_RATE];
	const int f1 = 440;
	float sin2[SAMPLE_RATE];
	const int f2 = 512;
	for (long i=0; i<SAMPLE_RATE; i++) {
		float time = ((float)i)/SAMPLE_RATE;
		sin1[i] = sin(2*PI*f1*time);
		sin2[i] = sin(2*PI*f2*time);
	}

	struct mossrose_sound_t sound_440 = {
		.left = sin1, .right = NULL, .mono = true, .len = SAMPLE_RATE
	};
	struct mossrose_sound_t sound_512 = {
		.left = sin2, .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");

	Pa_Sleep(500);

	printf("play 1\n");
	mossrose_play(&sound_512, -1);
	printf("wait\n");
	Pa_Sleep(1000);

	printf("play 2\n");
	mossrose_play(&sound_440, -1);
	printf("wait\n");
	Pa_Sleep(500);

	printf("play 3\n");
	mossrose_play(&sound_512, -1);
	printf("wait\n");
	Pa_Sleep(1000);

	mossrose_terminate();
	return 0;
}