-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathsupport.h
81 lines (59 loc) · 1.92 KB
/
support.h
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
79
80
81
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <time.h>
#include <limits.h>
#include <assert.h>
#ifdef __APPLE__
#define fwrite_unlocked fwrite
#define fflush_unlocked fflush
#endif
#if CHAR_BIT != 8
#error "Unsupported byte length"
#endif
#ifdef SAMPLING_FORMAT_FLOAT
#define SAMPLING_FORMAT float
#elif !defined(SAMPLING_FORMAT)
#define SAMPLING_FORMAT int16_t
#endif
#ifndef SAMPLING_RATE
#define SAMPLING_RATE 44100
#endif
typedef SAMPLING_FORMAT sample_t;
#define IS_SIGNED(type) ((type) -1 < 0)
#define INTTYPE_MAX(type) (IS_SIGNED(type) ? ~((type) 1 << (sizeof(type) * CHAR_BIT - 1)) : ~(type) 0)
#define DIV_ROUND(n, m) (((n) + (m) / 2) / (m))
#define MIN(A,B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __a : __b; })
#define MAX(A,B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; })
#define CLAMP(x, low, high) MIN(MAX(x, low), high)
#define CLAMP_u(x, min, max) ((unsigned) CLAMP(x, min, max))
#define __getbyte(x, n) ((x >> (n * CHAR_BIT)) & 0xff)
#define __byteswap(x, n, c) (__getbyte(x, n) << ((c - n - 1) * CHAR_BIT))
#define byteswap32(x) ( \
__byteswap((x), 0, 4) | __byteswap((x), 1, 4) | \
__byteswap((x), 2, 4) | __byteswap((x), 3, 4))
struct __malloc_data {
bool nomalloc;
void* (*real_malloc)(size_t);
clock_t ticks_start;
};
struct __read_data {
bool noread;
ssize_t (*real_read)(int, void*, size_t);
};
extern __attribute__ ((visibility ("hidden")))
FILE *__wave_out;
extern __attribute__ ((visibility ("hidden")))
struct __malloc_data __malloc_data;
extern __attribute__ ((visibility ("hidden")))
struct __read_data __read_data;
#ifdef NDEBUG
#define dbgprintf(format, ...) ((void) 0)
#else
#define dbgprintf(format, ...) ((void) fprintf(stderr, format, __VA_ARGS__))
#endif
// macro tests ========================================================
#if byteswap32(0x78563412) != 0x12345678
#error
#endif