1 #include <unistd.h>
2 #include <stdlib.h>
3 #include <math.h>
4 #include <stdio.h>
5 #include <stdint.h>
6 #include <sys/time.h>
7 
8 #include <celt.h>
9 #include "common.h"
10 #include "../sbcelt.h"
11 
12 #define USEC_PER_SEC  1000000
13 #define NSEC_PER_USEC 1000
14 
15 // Monotonic microsecond timestamp generator.
16 // The expectation is that gettimeofday() uses
17 // the VDSO and/or the TSC (on modern x86) to
18 // avoid system calls.
mymtime()19 uint64_t mymtime() {
20         struct timeval tv;
21         if (gettimeofday(&tv, NULL) == -1) {
22                 return 0;
23         }
24         return ((uint64_t)tv.tv_sec * USEC_PER_SEC) + (uint64_t)tv.tv_usec;
25 }
26 
main(int argc,char * argv[])27 int main(int argc, char *argv[]) {
28 	int i;
29 	int niter = 10000;
30 
31 	unsigned char buf[127];
32 	FILE *f = fopen("test.dat", "r");
33 	if (f == NULL) {
34 		fprintf(stderr, "unable to open test.dat\n");
35 		return 1;
36 	}
37 	if (fread(buf, 1, 127, f) != 127) {
38 		fprintf(stderr, "unable to read test.dat\n");
39 		return 1;
40 	}
41 	fclose(f);
42 
43 	CELTMode *dm = sbcelt_mode_create(SAMPLE_RATE, SAMPLE_RATE / 100, NULL);
44         CELTDecoder *d = sbcelt_decoder_create(dm, 1, NULL);
45 
46 	float pcmout[FRAME_SIZE];
47 	uint64_t begin = mymtime();
48 	for (i = 0; i < niter; i++) {
49 		if (sbcelt_decode_float(d, buf, 127, pcmout) != CELT_OK) {
50 			fprintf(stderr, "unable to decode...\n");
51 			return 1;
52 		}
53 	}
54 	uint64_t elapsed = mymtime() - begin;
55 
56 	printf("{\"niter\": %i, \"elapsed_usec\": %lu}\n", niter, elapsed);
57 
58 	return 0;
59 }
60