File: test.cpp

package info (click to toggle)
btanks 0.9.8083-9
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 43,616 kB
  • sloc: cpp: 46,425; ansic: 12,005; xml: 4,262; python: 313; sh: 13; makefile: 13
file content (78 lines) | stat: -rw-r--r-- 2,085 bytes parent folder | download | duplicates (5)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "context.h"
#include "source.h"
#include <stdlib.h>

#define WINDOW_BITS 9

typedef clunk::mdct_context<WINDOW_BITS, clunk::vorbis_window_func, float> mdct_type;
typedef clunk::fft_context<WINDOW_BITS - 2, float> fft_type;

int main(int argc, char *argv[]) {
	if (argc > 1 && argv[1][0] == 'b' && argv[1][1] == 'm') {
		mdct_type mdct;
		for(int i = 0; i < 1000000; ++i) 
			mdct.mdct();
		return 0;
	}
	if (argc > 1 && argv[1][0] == 'b' && argv[1][1] == 'f') {
		fft_type fft;
		for(int i = 0; i < 2000000; ++i) 
			fft.fft();
		return 0;
	}
	if (argc > 1 && argv[1][0] == 't') {
		fft_type fft;
		for(int i = 0; i < fft_type::N; ++i) {
			fft.data[i] = std::complex<float>((i / 4) & 1, 0);
		}
		fft.fft();
		for(int i = 0; i < fft_type::N; ++i) {
			printf("%f, %f = %f\n", fft.data[i].real(), fft.data[i].imag(), std::abs(fft.data[i]));
		}
		fft.ifft();

		for(int i = 0; i < fft_type::N; ++i) {
			fft.data[i] -= std::complex<float>((i / 4) & 1, 0);
			printf("%f, %f\n", fft.data[i].real(), fft.data[i].imag());
		}
		
		return 0;
	}
	clunk::Context context;
	context.init(44100, 2, 1024);
	
	clunk::Object * o = context.create_object();
	clunk::Sample * s = context.create_sample();

	s->load("scissors.wav");
	static const int d = 2, n = 6;
	
	context.save("test_out.raw");
/*	o->play("l", new clunk::Source(s, false, clunk::v3<float>(-d, 0, 0)));
	sleep(1);
	//o->play("c", new clunk::Source(s, false, clunk::v3<float>(0, 0, 0)));
	//sleep(1);
	o->play("r", new clunk::Source(s, false, clunk::v3<float>(d, 0, 0)));
	sleep(1);

	o->play("u", new clunk::Source(s, false, clunk::v3<float>(0, d, 0)));
	sleep(1);

	o->play("b", new clunk::Source(s, false, clunk::v3<float>(0, 0, d)));
	sleep(1);
*/

	for(int i = 0; i <= n; ++i) {
		float a = M_PI * i / n;
		o->play("s", new clunk::Source(s, false, clunk::v3<float>(-cos(a), -sin(a), 0) * d));
		usleep(500000);
	}

/*	for(int i = 0; i <= n; ++i) {
		float a = M_PI * i / n;
		o->play("s", new clunk::Source(s, false, clunk::v3<float>(cos(a), -0.25f, sin(a)) * d));
		usleep(500000);
	}
*/	usleep(500000);
	return 0;
}