wavspa 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +196 -0
- data/Rakefile +2 -0
- data/bin/wavfft +167 -0
- data/bin/wavlet +160 -0
- data/example/Call_To_Quarters-fft.png +0 -0
- data/example/Call_To_Quarters-wavelet.png +0 -0
- data/ext/wavspa/fb/extconf.rb +3 -0
- data/ext/wavspa/fb/rb_fb.c +690 -0
- data/ext/wavspa/fft/extconf.rb +6 -0
- data/ext/wavspa/fft/fft.c +918 -0
- data/ext/wavspa/fft/fft.h +62 -0
- data/ext/wavspa/fft/fftsg.c +3314 -0
- data/ext/wavspa/fft/rb_fft.c +458 -0
- data/ext/wavspa/wavelet/extconf.rb +37 -0
- data/ext/wavspa/wavelet/rb_wavelet.c +706 -0
- data/ext/wavspa/wavelet/walet.c +803 -0
- data/ext/wavspa/wavelet/walet.h +59 -0
- data/lib/wav.rb +87 -0
- data/lib/wavspa/common.rb +74 -0
- data/lib/wavspa/version.rb +3 -0
- data/lib/wavspa/wavfft/main.rb +130 -0
- data/lib/wavspa/wavfft/preset.rb +54 -0
- data/lib/wavspa/wavlet/main.rb +139 -0
- data/lib/wavspa/wavlet/preset.rb +38 -0
- data/wavspa.gemspec +47 -0
- metadata +119 -0
@@ -0,0 +1,690 @@
|
|
1
|
+
/*
|
2
|
+
* Simple Frame buffer
|
3
|
+
*
|
4
|
+
* Copyright (C) 2016 Hiroshi Kuwagata <kgt9221@gmail.com>
|
5
|
+
*/
|
6
|
+
|
7
|
+
#include "ruby.h"
|
8
|
+
|
9
|
+
#include <stdint.h>
|
10
|
+
#include <string.h>
|
11
|
+
|
12
|
+
#define N(x) (sizeof((x))/sizeof(*(x)))
|
13
|
+
#define RUNTIME_ERROR(...) rb_raise(rb_eRuntimeError, __VA_ARGS__)
|
14
|
+
#define ARGUMENT_ERROR(...) rb_raise(rb_eArgError, __VA_ARGS__)
|
15
|
+
#define RB_FFT(p) ((rb_fft_t*)(p))
|
16
|
+
#define EQ_STR(val,str) (rb_to_id(val) == rb_intern(str))
|
17
|
+
|
18
|
+
typedef struct {
|
19
|
+
int width;
|
20
|
+
int height;
|
21
|
+
int step;
|
22
|
+
int margin_x;
|
23
|
+
int margin_y;
|
24
|
+
|
25
|
+
int stride;
|
26
|
+
int size;
|
27
|
+
|
28
|
+
VALUE buf;
|
29
|
+
} rb_fb_t;
|
30
|
+
|
31
|
+
/*
|
32
|
+
* from M+ font (M+ gothic 10r)
|
33
|
+
*/
|
34
|
+
const uint8_t font[] = {
|
35
|
+
0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x00, /* 0x00 */
|
36
|
+
0x00, 0x00, 0x00, 0x60, 0xf0, 0x60, 0x00, 0x00, 0x00, 0x00, /* 0x01 */
|
37
|
+
0x50, 0xa8, 0x50, 0xa8, 0x50, 0xa8, 0x50, 0xa8, 0x50, 0xa8, /* 0x02 */
|
38
|
+
0x90, 0xf0, 0x90, 0x90, 0x00, 0xf8, 0x20, 0x20, 0x20, 0x00, /* 0x03 */
|
39
|
+
0xf0, 0x80, 0xf0, 0x80, 0x00, 0xf0, 0x80, 0xf0, 0x80, 0x00, /* 0x04 */
|
40
|
+
0xf0, 0x90, 0x80, 0xf0, 0x00, 0xf0, 0x90, 0xe0, 0x90, 0x00, /* 0x05 */
|
41
|
+
0x80, 0x80, 0x80, 0xf0, 0x00, 0xf0, 0x80, 0xf0, 0x80, 0x00, /* 0x06 */
|
42
|
+
0x60, 0x90, 0x90, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x07 */
|
43
|
+
0x00, 0x40, 0x40, 0xf0, 0x40, 0x40, 0x00, 0xf0, 0x00, 0x00, /* 0x08 */
|
44
|
+
0x90, 0xd0, 0xb0, 0x90, 0x00, 0x80, 0x80, 0x80, 0xf0, 0x00, /* 0x09 */
|
45
|
+
0x90, 0x90, 0xa0, 0xc0, 0x00, 0xf8, 0x20, 0x20, 0x20, 0x00, /* 0x0a */
|
46
|
+
0x20, 0x20, 0x20, 0x20, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0b */
|
47
|
+
0x00, 0x00, 0x00, 0x00, 0xe0, 0x20, 0x20, 0x20, 0x20, 0x20, /* 0x0c */
|
48
|
+
0x00, 0x00, 0x00, 0x00, 0x38, 0x20, 0x20, 0x20, 0x20, 0x20, /* 0x0d */
|
49
|
+
0x20, 0x20, 0x20, 0x20, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0e */
|
50
|
+
0x20, 0x20, 0x20, 0x20, 0xf8, 0x20, 0x20, 0x20, 0x20, 0x20, /* 0x0f */
|
51
|
+
0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10 */
|
52
|
+
0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x11 */
|
53
|
+
0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x12 */
|
54
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, /* 0x13 */
|
55
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, /* 0x14 */
|
56
|
+
0x20, 0x20, 0x20, 0x20, 0x38, 0x20, 0x20, 0x20, 0x20, 0x20, /* 0x15 */
|
57
|
+
0x20, 0x20, 0x20, 0x20, 0xe0, 0x20, 0x20, 0x20, 0x20, 0x20, /* 0x16 */
|
58
|
+
0x20, 0x20, 0x20, 0x20, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x17 */
|
59
|
+
0x00, 0x00, 0x00, 0x00, 0xf8, 0x20, 0x20, 0x20, 0x20, 0x20, /* 0x18 */
|
60
|
+
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, /* 0x19 */
|
61
|
+
0x00, 0x20, 0x40, 0x80, 0x40, 0x20, 0x00, 0xf0, 0x00, 0x00, /* 0x1a */
|
62
|
+
0x00, 0x40, 0x20, 0x10, 0x20, 0x40, 0x00, 0xf0, 0x00, 0x00, /* 0x1b */
|
63
|
+
0x00, 0x00, 0x00, 0xf0, 0x50, 0x50, 0x90, 0x90, 0x00, 0x00, /* 0x1c */
|
64
|
+
0x00, 0x20, 0x20, 0xf0, 0x40, 0xf0, 0x40, 0x40, 0x00, 0x00, /* 0x1d */
|
65
|
+
0x00, 0x30, 0x40, 0x40, 0xf0, 0x40, 0x40, 0xb0, 0x00, 0x00, /* 0x1e */
|
66
|
+
0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1f */
|
67
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20 */
|
68
|
+
0x00, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x20, 0x00, 0x00, /* 0x21 */
|
69
|
+
0x50, 0x50, 0x50, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x22 */
|
70
|
+
0x00, 0x50, 0x50, 0xf0, 0x50, 0xf0, 0x50, 0x50, 0x00, 0x00, /* 0x23 */
|
71
|
+
0x00, 0x20, 0x70, 0xa0, 0xe0, 0x70, 0x50, 0xe0, 0x40, 0x00, /* 0x24 */
|
72
|
+
0x00, 0xc0, 0xc0, 0x10, 0x60, 0x80, 0x30, 0x30, 0x00, 0x00, /* 0x25 */
|
73
|
+
0x00, 0x40, 0xa0, 0xa0, 0x40, 0xb0, 0xa0, 0x50, 0x00, 0x00, /* 0x26 */
|
74
|
+
0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x27 */
|
75
|
+
0x10, 0x20, 0x20, 0x40, 0x40, 0x40, 0x20, 0x20, 0x10, 0x00, /* 0x28 */
|
76
|
+
0x80, 0x40, 0x40, 0x20, 0x20, 0x20, 0x40, 0x40, 0x80, 0x00, /* 0x29 */
|
77
|
+
0x00, 0x00, 0x50, 0x20, 0xf0, 0x20, 0x50, 0x00, 0x00, 0x00, /* 0x2a */
|
78
|
+
0x00, 0x00, 0x20, 0x20, 0xf0, 0x20, 0x20, 0x00, 0x00, 0x00, /* 0x2b */
|
79
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x40, 0x00, /* 0x2c */
|
80
|
+
0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2d */
|
81
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, /* 0x2e */
|
82
|
+
0x00, 0x10, 0x10, 0x20, 0x20, 0x40, 0x40, 0x80, 0x80, 0x00, /* 0x2f */
|
83
|
+
0x00, 0x60, 0x90, 0xb0, 0xd0, 0x90, 0x90, 0x60, 0x00, 0x00, /* 0x30 */
|
84
|
+
0x00, 0x20, 0x60, 0xa0, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, /* 0x31 */
|
85
|
+
0x00, 0x60, 0x90, 0x10, 0x20, 0x40, 0x80, 0xf0, 0x00, 0x00, /* 0x32 */
|
86
|
+
0x00, 0xf0, 0x10, 0x20, 0x60, 0x10, 0x90, 0x60, 0x00, 0x00, /* 0x33 */
|
87
|
+
0x00, 0x20, 0x60, 0xa0, 0xa0, 0xf0, 0x20, 0x20, 0x00, 0x00, /* 0x34 */
|
88
|
+
0x00, 0xf0, 0x80, 0xe0, 0x10, 0x10, 0x90, 0x60, 0x00, 0x00, /* 0x35 */
|
89
|
+
0x00, 0x60, 0x80, 0xe0, 0x90, 0x90, 0x90, 0x60, 0x00, 0x00, /* 0x36 */
|
90
|
+
0x00, 0xf0, 0x10, 0x20, 0x20, 0x40, 0x40, 0x40, 0x00, 0x00, /* 0x37 */
|
91
|
+
0x00, 0x60, 0x90, 0x90, 0x60, 0x90, 0x90, 0x60, 0x00, 0x00, /* 0x38 */
|
92
|
+
0x00, 0x60, 0x90, 0x90, 0x90, 0x70, 0x10, 0x60, 0x00, 0x00, /* 0x39 */
|
93
|
+
0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, /* 0x3a */
|
94
|
+
0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x20, 0x40, 0x00, 0x00, /* 0x3b */
|
95
|
+
0x00, 0x10, 0x20, 0x40, 0x80, 0x40, 0x20, 0x10, 0x00, 0x00, /* 0x3c */
|
96
|
+
0x00, 0x00, 0x00, 0xf0, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00, /* 0x3d */
|
97
|
+
0x00, 0x80, 0x40, 0x20, 0x10, 0x20, 0x40, 0x80, 0x00, 0x00, /* 0x3e */
|
98
|
+
0x00, 0xe0, 0x10, 0x10, 0x20, 0x40, 0x00, 0x40, 0x00, 0x00, /* 0x3f */
|
99
|
+
0x00, 0x60, 0x90, 0xb0, 0xa0, 0xb0, 0x80, 0x70, 0x00, 0x00, /* 0x40 */
|
100
|
+
0x00, 0x60, 0x90, 0x90, 0xf0, 0x90, 0x90, 0x90, 0x00, 0x00, /* 0x41 */
|
101
|
+
0x00, 0xe0, 0x90, 0x90, 0xe0, 0x90, 0x90, 0xe0, 0x00, 0x00, /* 0x42 */
|
102
|
+
0x00, 0x60, 0x90, 0x80, 0x80, 0x80, 0x80, 0x70, 0x00, 0x00, /* 0x43 */
|
103
|
+
0x00, 0xe0, 0x90, 0x90, 0x90, 0x90, 0x90, 0xe0, 0x00, 0x00, /* 0x44 */
|
104
|
+
0x00, 0xf0, 0x80, 0x80, 0xe0, 0x80, 0x80, 0xf0, 0x00, 0x00, /* 0x45 */
|
105
|
+
0x00, 0xf0, 0x80, 0x80, 0xe0, 0x80, 0x80, 0x80, 0x00, 0x00, /* 0x46 */
|
106
|
+
0x00, 0x70, 0x80, 0x80, 0xb0, 0x90, 0x90, 0x70, 0x00, 0x00, /* 0x47 */
|
107
|
+
0x00, 0x90, 0x90, 0x90, 0xf0, 0x90, 0x90, 0x90, 0x00, 0x00, /* 0x48 */
|
108
|
+
0x00, 0x70, 0x20, 0x20, 0x20, 0x20, 0x20, 0x70, 0x00, 0x00, /* 0x49 */
|
109
|
+
0x00, 0x10, 0x10, 0x10, 0x10, 0x90, 0x90, 0x60, 0x00, 0x00, /* 0x4a */
|
110
|
+
0x00, 0x90, 0xa0, 0xc0, 0xc0, 0xa0, 0x90, 0x90, 0x00, 0x00, /* 0x4b */
|
111
|
+
0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xf0, 0x00, 0x00, /* 0x4c */
|
112
|
+
0x00, 0x90, 0xb0, 0xd0, 0x90, 0x90, 0x90, 0x90, 0x00, 0x00, /* 0x4d */
|
113
|
+
0x00, 0x90, 0xd0, 0xb0, 0x90, 0x90, 0x90, 0x90, 0x00, 0x00, /* 0x4e */
|
114
|
+
0x00, 0x60, 0x90, 0x90, 0x90, 0x90, 0x90, 0x60, 0x00, 0x00, /* 0x4f */
|
115
|
+
0x00, 0xe0, 0x90, 0x90, 0x90, 0xe0, 0x80, 0x80, 0x00, 0x00, /* 0x50 */
|
116
|
+
0x00, 0x60, 0x90, 0x90, 0x90, 0x90, 0x90, 0x60, 0x40, 0x30, /* 0x51 */
|
117
|
+
0x00, 0xe0, 0x90, 0x90, 0xe0, 0x90, 0x90, 0x90, 0x00, 0x00, /* 0x52 */
|
118
|
+
0x00, 0x70, 0x80, 0x80, 0x60, 0x10, 0x10, 0xe0, 0x00, 0x00, /* 0x53 */
|
119
|
+
0x00, 0xf8, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, /* 0x54 */
|
120
|
+
0x00, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x60, 0x00, 0x00, /* 0x55 */
|
121
|
+
0x00, 0x90, 0x90, 0x90, 0x90, 0x90, 0xa0, 0xc0, 0x00, 0x00, /* 0x56 */
|
122
|
+
0x00, 0x90, 0x90, 0x90, 0x90, 0xd0, 0xb0, 0x90, 0x00, 0x00, /* 0x57 */
|
123
|
+
0x00, 0x90, 0x90, 0x90, 0x60, 0x90, 0x90, 0x90, 0x00, 0x00, /* 0x58 */
|
124
|
+
0x00, 0x90, 0x90, 0x90, 0xa0, 0x40, 0x40, 0x40, 0x00, 0x00, /* 0x59 */
|
125
|
+
0x00, 0xf0, 0x10, 0x20, 0x40, 0x80, 0x80, 0xf0, 0x00, 0x00, /* 0x5a */
|
126
|
+
0x70, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x70, 0x00, /* 0x5b */
|
127
|
+
0x00, 0x80, 0x80, 0x40, 0x40, 0x20, 0x20, 0x10, 0x10, 0x00, /* 0x5c */
|
128
|
+
0xe0, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0xe0, 0x00, /* 0x5d */
|
129
|
+
0x20, 0x50, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x5e */
|
130
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, /* 0x5f */
|
131
|
+
0x40, 0x40, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60 */
|
132
|
+
0x00, 0x00, 0x00, 0x60, 0x10, 0x70, 0x90, 0x70, 0x00, 0x00, /* 0x61 */
|
133
|
+
0x00, 0x80, 0x80, 0xe0, 0x90, 0x90, 0x90, 0xe0, 0x00, 0x00, /* 0x62 */
|
134
|
+
0x00, 0x00, 0x00, 0x60, 0x90, 0x80, 0x80, 0x70, 0x00, 0x00, /* 0x63 */
|
135
|
+
0x00, 0x10, 0x10, 0x70, 0x90, 0x90, 0x90, 0x70, 0x00, 0x00, /* 0x64 */
|
136
|
+
0x00, 0x00, 0x00, 0x60, 0x90, 0xf0, 0x80, 0x70, 0x00, 0x00, /* 0x65 */
|
137
|
+
0x00, 0x30, 0x40, 0x40, 0xf0, 0x40, 0x40, 0x40, 0x00, 0x00, /* 0x66 */
|
138
|
+
0x00, 0x00, 0x00, 0x70, 0x90, 0x90, 0x90, 0x70, 0x10, 0x60, /* 0x67 */
|
139
|
+
0x00, 0x80, 0x80, 0xe0, 0x90, 0x90, 0x90, 0x90, 0x00, 0x00, /* 0x68 */
|
140
|
+
0x20, 0x00, 0x00, 0x60, 0x20, 0x20, 0x20, 0x70, 0x00, 0x00, /* 0x69 */
|
141
|
+
0x20, 0x00, 0x00, 0x60, 0x20, 0x20, 0x20, 0x20, 0x20, 0xc0, /* 0x6a */
|
142
|
+
0x00, 0x80, 0x80, 0x90, 0xa0, 0xc0, 0xa0, 0x90, 0x00, 0x00, /* 0x6b */
|
143
|
+
0x00, 0x60, 0x20, 0x20, 0x20, 0x20, 0x20, 0x30, 0x00, 0x00, /* 0x6c */
|
144
|
+
0x00, 0x00, 0x00, 0xf0, 0xa8, 0xa8, 0xa8, 0xa8, 0x00, 0x00, /* 0x6d */
|
145
|
+
0x00, 0x00, 0x00, 0xe0, 0x90, 0x90, 0x90, 0x90, 0x00, 0x00, /* 0x6e */
|
146
|
+
0x00, 0x00, 0x00, 0x60, 0x90, 0x90, 0x90, 0x60, 0x00, 0x00, /* 0x6f */
|
147
|
+
0x00, 0x00, 0x00, 0xe0, 0x90, 0x90, 0x90, 0xe0, 0x80, 0x80, /* 0x70 */
|
148
|
+
0x00, 0x00, 0x00, 0x70, 0x90, 0x90, 0x90, 0x70, 0x10, 0x10, /* 0x71 */
|
149
|
+
0x00, 0x00, 0x00, 0xb0, 0xc0, 0x80, 0x80, 0x80, 0x00, 0x00, /* 0x72 */
|
150
|
+
0x00, 0x00, 0x00, 0x70, 0x80, 0x60, 0x10, 0xe0, 0x00, 0x00, /* 0x73 */
|
151
|
+
0x00, 0x40, 0x40, 0xf0, 0x40, 0x40, 0x40, 0x30, 0x00, 0x00, /* 0x74 */
|
152
|
+
0x00, 0x00, 0x00, 0x90, 0x90, 0x90, 0x90, 0x70, 0x00, 0x00, /* 0x75 */
|
153
|
+
0x00, 0x00, 0x00, 0x90, 0x90, 0x90, 0xa0, 0xc0, 0x00, 0x00, /* 0x76 */
|
154
|
+
0x00, 0x00, 0x00, 0x90, 0x90, 0xd0, 0xb0, 0x90, 0x00, 0x00, /* 0x77 */
|
155
|
+
0x00, 0x00, 0x00, 0x90, 0x90, 0x60, 0x90, 0x90, 0x00, 0x00, /* 0x78 */
|
156
|
+
0x00, 0x00, 0x00, 0x90, 0x90, 0x90, 0x90, 0x70, 0x10, 0x60, /* 0x79 */
|
157
|
+
0x00, 0x00, 0x00, 0xf0, 0x20, 0x40, 0x80, 0xf0, 0x00, 0x00, /* 0x7a */
|
158
|
+
0x30, 0x40, 0x40, 0x40, 0x80, 0x40, 0x40, 0x40, 0x30, 0x00, /* 0x7b */
|
159
|
+
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, /* 0x7c */
|
160
|
+
0xc0, 0x20, 0x20, 0x20, 0x10, 0x20, 0x20, 0x20, 0xc0, 0x00, /* 0x7d */
|
161
|
+
0x00, 0x50, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x7e */
|
162
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x7f */
|
163
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80 */
|
164
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x81 */
|
165
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x82 */
|
166
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x83 */
|
167
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x84 */
|
168
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x85 */
|
169
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x86 */
|
170
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x87 */
|
171
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88 */
|
172
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x89 */
|
173
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x8a */
|
174
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x8b */
|
175
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x8c */
|
176
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x8d */
|
177
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x8e */
|
178
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x8f */
|
179
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90 */
|
180
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x91 */
|
181
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x92 */
|
182
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x93 */
|
183
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x94 */
|
184
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x95 */
|
185
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x96 */
|
186
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x97 */
|
187
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98 */
|
188
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x99 */
|
189
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x9a */
|
190
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x9b */
|
191
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x9c */
|
192
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x9d */
|
193
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x9e */
|
194
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x9f */
|
195
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0 */
|
196
|
+
0x00, 0x20, 0x00, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, /* 0xa1 */
|
197
|
+
0x00, 0x20, 0x20, 0x70, 0xa0, 0xa0, 0xa0, 0x70, 0x20, 0x00, /* 0xa2 */
|
198
|
+
0x00, 0x30, 0x40, 0x40, 0xf0, 0x40, 0x40, 0xb0, 0x00, 0x00, /* 0xa3 */
|
199
|
+
0x00, 0x00, 0x90, 0x60, 0x60, 0x60, 0x90, 0x00, 0x00, 0x00, /* 0xa4 */
|
200
|
+
0x00, 0x90, 0xa0, 0x40, 0xf0, 0x40, 0xf0, 0x40, 0x00, 0x00, /* 0xa5 */
|
201
|
+
0x20, 0x20, 0x20, 0x20, 0x00, 0x20, 0x20, 0x20, 0x20, 0x00, /* 0xa6 */
|
202
|
+
0x60, 0x90, 0x80, 0x60, 0x90, 0x60, 0x10, 0x90, 0x60, 0x00, /* 0xa7 */
|
203
|
+
0x00, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8 */
|
204
|
+
0x00, 0xf0, 0x90, 0x60, 0x40, 0x60, 0x90, 0xf0, 0x00, 0x00, /* 0xa9 */
|
205
|
+
0x00, 0x60, 0x10, 0x70, 0x90, 0x70, 0x00, 0xf0, 0x00, 0x00, /* 0xaa */
|
206
|
+
0x00, 0x10, 0x20, 0x50, 0xa0, 0x50, 0x20, 0x10, 0x00, 0x00, /* 0xab */
|
207
|
+
0x00, 0x00, 0x00, 0x00, 0xf0, 0x10, 0x10, 0x00, 0x00, 0x00, /* 0xac */
|
208
|
+
0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xad */
|
209
|
+
0x00, 0xf0, 0x90, 0x60, 0x40, 0x40, 0x90, 0xf0, 0x00, 0x00, /* 0xae */
|
210
|
+
0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xaf */
|
211
|
+
0x60, 0x90, 0x90, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0 */
|
212
|
+
0x00, 0x40, 0x40, 0xf0, 0x40, 0x40, 0x00, 0xf0, 0x00, 0x00, /* 0xb1 */
|
213
|
+
0xc0, 0x20, 0x40, 0x80, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb2 */
|
214
|
+
0xe0, 0x20, 0x40, 0x20, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb3 */
|
215
|
+
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb4 */
|
216
|
+
0x00, 0x00, 0x00, 0x90, 0x90, 0x90, 0xb0, 0xd0, 0x80, 0x80, /* 0xb5 */
|
217
|
+
0x00, 0xf0, 0xd0, 0xd0, 0xd0, 0x50, 0x50, 0x50, 0x00, 0x00, /* 0xb6 */
|
218
|
+
0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb7 */
|
219
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x20, 0x40, /* 0xb8 */
|
220
|
+
0x40, 0xc0, 0x40, 0x40, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb9 */
|
221
|
+
0x60, 0x90, 0x90, 0x60, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00, /* 0xba */
|
222
|
+
0x00, 0x80, 0x40, 0xa0, 0x50, 0xa0, 0x40, 0x80, 0x00, 0x00, /* 0xbb */
|
223
|
+
0x40, 0xc0, 0x40, 0x40, 0x30, 0x50, 0x70, 0x10, 0x00, 0x00, /* 0xbc */
|
224
|
+
0x40, 0xc0, 0x40, 0x40, 0x70, 0x10, 0x20, 0x70, 0x00, 0x00, /* 0xbd */
|
225
|
+
0xe0, 0x40, 0x20, 0xc0, 0x30, 0x50, 0x70, 0x10, 0x00, 0x00, /* 0xbe */
|
226
|
+
0x00, 0x20, 0x00, 0x20, 0x40, 0x80, 0x80, 0x70, 0x00, 0x00, /* 0xbf */
|
227
|
+
0x20, 0x00, 0x60, 0x90, 0x90, 0xf0, 0x90, 0x90, 0x00, 0x00, /* 0xc0 */
|
228
|
+
0x40, 0x00, 0x60, 0x90, 0x90, 0xf0, 0x90, 0x90, 0x00, 0x00, /* 0xc1 */
|
229
|
+
0x90, 0x00, 0x60, 0x90, 0x90, 0xf0, 0x90, 0x90, 0x00, 0x00, /* 0xc2 */
|
230
|
+
0xa0, 0x00, 0x60, 0x90, 0x90, 0xf0, 0x90, 0x90, 0x00, 0x00, /* 0xc3 */
|
231
|
+
0x50, 0x00, 0x60, 0x90, 0x90, 0xf0, 0x90, 0x90, 0x00, 0x00, /* 0xc4 */
|
232
|
+
0x90, 0x90, 0x60, 0x90, 0x90, 0xf0, 0x90, 0x90, 0x00, 0x00, /* 0xc5 */
|
233
|
+
0x00, 0xf0, 0xa0, 0xa0, 0xf0, 0xa0, 0xa0, 0xb0, 0x00, 0x00, /* 0xc6 */
|
234
|
+
0x00, 0x60, 0x90, 0x80, 0x80, 0x80, 0x80, 0x70, 0x20, 0x40, /* 0xc7 */
|
235
|
+
0x20, 0x00, 0xf0, 0x80, 0xe0, 0x80, 0x80, 0xf0, 0x00, 0x00, /* 0xc8 */
|
236
|
+
0x40, 0x00, 0xf0, 0x80, 0xe0, 0x80, 0x80, 0xf0, 0x00, 0x00, /* 0xc9 */
|
237
|
+
0x90, 0x00, 0xf0, 0x80, 0xe0, 0x80, 0x80, 0xf0, 0x00, 0x00, /* 0xca */
|
238
|
+
0x50, 0x00, 0xf0, 0x80, 0xe0, 0x80, 0x80, 0xf0, 0x00, 0x00, /* 0xcb */
|
239
|
+
0x10, 0x00, 0x70, 0x20, 0x20, 0x20, 0x20, 0x70, 0x00, 0x00, /* 0xcc */
|
240
|
+
0x20, 0x00, 0x70, 0x20, 0x20, 0x20, 0x20, 0x70, 0x00, 0x00, /* 0xcd */
|
241
|
+
0x90, 0x00, 0x70, 0x20, 0x20, 0x20, 0x20, 0x70, 0x00, 0x00, /* 0xce */
|
242
|
+
0x50, 0x00, 0x70, 0x20, 0x20, 0x20, 0x20, 0x70, 0x00, 0x00, /* 0xcf */
|
243
|
+
0x00, 0xe0, 0x50, 0x50, 0xf0, 0x50, 0x50, 0xe0, 0x00, 0x00, /* 0xd0 */
|
244
|
+
0xa0, 0x00, 0x90, 0xd0, 0xb0, 0x90, 0x90, 0x90, 0x00, 0x00, /* 0xd1 */
|
245
|
+
0x20, 0x00, 0x60, 0x90, 0x90, 0x90, 0x90, 0x60, 0x00, 0x00, /* 0xd2 */
|
246
|
+
0x40, 0x00, 0x60, 0x90, 0x90, 0x90, 0x90, 0x60, 0x00, 0x00, /* 0xd3 */
|
247
|
+
0x90, 0x00, 0x60, 0x90, 0x90, 0x90, 0x90, 0x60, 0x00, 0x00, /* 0xd4 */
|
248
|
+
0xa0, 0x00, 0x60, 0x90, 0x90, 0x90, 0x90, 0x60, 0x00, 0x00, /* 0xd5 */
|
249
|
+
0x50, 0x00, 0x60, 0x90, 0x90, 0x90, 0x90, 0x60, 0x00, 0x00, /* 0xd6 */
|
250
|
+
0x00, 0x00, 0x90, 0x90, 0x60, 0x90, 0x90, 0x00, 0x00, 0x00, /* 0xd7 */
|
251
|
+
0x10, 0x60, 0x90, 0xb0, 0xd0, 0x90, 0x90, 0x60, 0x80, 0x00, /* 0xd8 */
|
252
|
+
0x20, 0x00, 0x90, 0x90, 0x90, 0x90, 0x90, 0x60, 0x00, 0x00, /* 0xd9 */
|
253
|
+
0x40, 0x00, 0x90, 0x90, 0x90, 0x90, 0x90, 0x60, 0x00, 0x00, /* 0xda */
|
254
|
+
0x90, 0x00, 0x90, 0x90, 0x90, 0x90, 0x90, 0x60, 0x00, 0x00, /* 0xdb */
|
255
|
+
0x50, 0x00, 0x90, 0x90, 0x90, 0x90, 0x90, 0x60, 0x00, 0x00, /* 0xdc */
|
256
|
+
0x40, 0x00, 0x90, 0x90, 0xa0, 0x40, 0x40, 0x40, 0x00, 0x00, /* 0xdd */
|
257
|
+
0x80, 0xe0, 0x90, 0x90, 0x90, 0xe0, 0x80, 0x80, 0x00, 0x00, /* 0xde */
|
258
|
+
0x00, 0x60, 0x90, 0x90, 0xe0, 0x90, 0x90, 0xe0, 0x80, 0x80, /* 0xdf */
|
259
|
+
0x20, 0x00, 0x00, 0x60, 0x10, 0x70, 0x90, 0x70, 0x00, 0x00, /* 0xe0 */
|
260
|
+
0x40, 0x00, 0x00, 0x60, 0x10, 0x70, 0x90, 0x70, 0x00, 0x00, /* 0xe1 */
|
261
|
+
0x90, 0x00, 0x00, 0x60, 0x10, 0x70, 0x90, 0x70, 0x00, 0x00, /* 0xe2 */
|
262
|
+
0xa0, 0x00, 0x00, 0x60, 0x10, 0x70, 0x90, 0x70, 0x00, 0x00, /* 0xe3 */
|
263
|
+
0x50, 0x00, 0x00, 0x60, 0x10, 0x70, 0x90, 0x70, 0x00, 0x00, /* 0xe4 */
|
264
|
+
0x90, 0x60, 0x00, 0x60, 0x10, 0x70, 0x90, 0x70, 0x00, 0x00, /* 0xe5 */
|
265
|
+
0x00, 0x00, 0x00, 0xf0, 0x20, 0x70, 0xa0, 0xf0, 0x00, 0x00, /* 0xe6 */
|
266
|
+
0x00, 0x00, 0x00, 0x60, 0x90, 0x80, 0x80, 0x70, 0x20, 0x40, /* 0xe7 */
|
267
|
+
0x20, 0x00, 0x00, 0x60, 0x90, 0xf0, 0x80, 0x70, 0x00, 0x00, /* 0xe8 */
|
268
|
+
0x40, 0x00, 0x00, 0x60, 0x90, 0xf0, 0x80, 0x70, 0x00, 0x00, /* 0xe9 */
|
269
|
+
0x90, 0x00, 0x00, 0x60, 0x90, 0xf0, 0x80, 0x70, 0x00, 0x00, /* 0xea */
|
270
|
+
0x50, 0x00, 0x00, 0x60, 0x90, 0xf0, 0x80, 0x70, 0x00, 0x00, /* 0xeb */
|
271
|
+
0x10, 0x00, 0x00, 0x60, 0x20, 0x20, 0x20, 0x70, 0x00, 0x00, /* 0xec */
|
272
|
+
0x20, 0x00, 0x00, 0x60, 0x20, 0x20, 0x20, 0x70, 0x00, 0x00, /* 0xed */
|
273
|
+
0x90, 0x00, 0x00, 0x60, 0x20, 0x20, 0x20, 0x70, 0x00, 0x00, /* 0xee */
|
274
|
+
0x50, 0x00, 0x00, 0x60, 0x20, 0x20, 0x20, 0x70, 0x00, 0x00, /* 0xef */
|
275
|
+
0x70, 0xc0, 0x20, 0x60, 0x90, 0x90, 0x90, 0x60, 0x00, 0x00, /* 0xf0 */
|
276
|
+
0xa0, 0x00, 0x00, 0xe0, 0x90, 0x90, 0x90, 0x90, 0x00, 0x00, /* 0xf1 */
|
277
|
+
0x20, 0x00, 0x00, 0x60, 0x90, 0x90, 0x90, 0x60, 0x00, 0x00, /* 0xf2 */
|
278
|
+
0x40, 0x00, 0x00, 0x60, 0x90, 0x90, 0x90, 0x60, 0x00, 0x00, /* 0xf3 */
|
279
|
+
0x90, 0x00, 0x00, 0x60, 0x90, 0x90, 0x90, 0x60, 0x00, 0x00, /* 0xf4 */
|
280
|
+
0xa0, 0x00, 0x00, 0x60, 0x90, 0x90, 0x90, 0x60, 0x00, 0x00, /* 0xf5 */
|
281
|
+
0x50, 0x00, 0x00, 0x60, 0x90, 0x90, 0x90, 0x60, 0x00, 0x00, /* 0xf6 */
|
282
|
+
0x00, 0x40, 0x40, 0x00, 0xf0, 0x00, 0x40, 0x40, 0x00, 0x00, /* 0xf7 */
|
283
|
+
0x00, 0x00, 0x10, 0x60, 0x90, 0xf0, 0x90, 0x60, 0x80, 0x00, /* 0xf8 */
|
284
|
+
0x20, 0x00, 0x00, 0x90, 0x90, 0x90, 0x90, 0x70, 0x00, 0x00, /* 0xf9 */
|
285
|
+
0x40, 0x00, 0x00, 0x90, 0x90, 0x90, 0x90, 0x70, 0x00, 0x00, /* 0xfa */
|
286
|
+
0x90, 0x00, 0x00, 0x90, 0x90, 0x90, 0x90, 0x70, 0x00, 0x00, /* 0xfb */
|
287
|
+
0x50, 0x00, 0x00, 0x90, 0x90, 0x90, 0x90, 0x70, 0x00, 0x00, /* 0xfc */
|
288
|
+
0x40, 0x00, 0x00, 0x90, 0x90, 0x90, 0x90, 0x70, 0x10, 0x60, /* 0xfd */
|
289
|
+
0x00, 0x80, 0x80, 0xe0, 0x90, 0x90, 0x90, 0xe0, 0x80, 0x80, /* 0xfe */
|
290
|
+
0x50, 0x00, 0x00, 0x90, 0x90, 0x90, 0x90, 0x70, 0x10, 0x60, /* 0xff */
|
291
|
+
};
|
292
|
+
|
293
|
+
static VALUE wavspa_module;
|
294
|
+
static VALUE fb_klass;
|
295
|
+
|
296
|
+
static const char* opts_keys[] = {
|
297
|
+
"column_step",
|
298
|
+
"margin_x",
|
299
|
+
"margin_y",
|
300
|
+
};
|
301
|
+
|
302
|
+
static ID opts_ids[N(opts_keys)];
|
303
|
+
|
304
|
+
static void
|
305
|
+
rb_fb_mark(void* _ptr)
|
306
|
+
{
|
307
|
+
rb_fb_t* ptr;
|
308
|
+
|
309
|
+
ptr = (rb_fb_t*)_ptr;
|
310
|
+
|
311
|
+
if (ptr->buf != Qnil) {
|
312
|
+
rb_gc_mark(ptr->buf);
|
313
|
+
}
|
314
|
+
}
|
315
|
+
|
316
|
+
static void
|
317
|
+
rb_fb_free(void* _ptr)
|
318
|
+
{
|
319
|
+
((rb_fb_t*)_ptr)->buf = Qnil;
|
320
|
+
}
|
321
|
+
|
322
|
+
static size_t
|
323
|
+
rb_fb_size(const void* _ptr)
|
324
|
+
{
|
325
|
+
size_t ret;
|
326
|
+
rb_fb_t* ptr;
|
327
|
+
|
328
|
+
ptr = (rb_fb_t*)_ptr;
|
329
|
+
ret = sizeof(*ptr) + ((ptr->buf != Qnil)? RSTRING_LEN(ptr->buf): 0);
|
330
|
+
|
331
|
+
return ret;
|
332
|
+
}
|
333
|
+
|
334
|
+
static const struct rb_data_type_struct fb_data_type = {
|
335
|
+
"Simple frame buffer for WAV file spectrum analyzer",
|
336
|
+
{rb_fb_mark, rb_fb_free, rb_fb_size, {NULL, NULL}},
|
337
|
+
NULL,
|
338
|
+
NULL,
|
339
|
+
};
|
340
|
+
|
341
|
+
static VALUE
|
342
|
+
rb_fb_alloc(VALUE self)
|
343
|
+
{
|
344
|
+
rb_fb_t* ptr;
|
345
|
+
|
346
|
+
ptr = ALLOC(rb_fb_t);
|
347
|
+
memset(ptr, 0, sizeof(*ptr));
|
348
|
+
|
349
|
+
ptr->width = -1;
|
350
|
+
ptr->height = -1;
|
351
|
+
ptr->step = 1;
|
352
|
+
ptr->margin_x = 0;
|
353
|
+
ptr->margin_y = 0;
|
354
|
+
ptr->size = -1;
|
355
|
+
ptr->buf = Qnil;
|
356
|
+
|
357
|
+
return TypedData_Wrap_Struct(fb_klass, &fb_data_type, ptr);
|
358
|
+
}
|
359
|
+
|
360
|
+
static VALUE
|
361
|
+
rb_fb_initialize(int argc, VALUE* argv, VALUE self)
|
362
|
+
{
|
363
|
+
rb_fb_t* ptr;
|
364
|
+
VALUE width;
|
365
|
+
VALUE height;
|
366
|
+
VALUE opt;
|
367
|
+
VALUE opts[N(opts_ids)];
|
368
|
+
|
369
|
+
/*
|
370
|
+
* extract context data
|
371
|
+
*/
|
372
|
+
TypedData_Get_Struct(self, rb_fb_t, &fb_data_type, ptr);
|
373
|
+
|
374
|
+
/*
|
375
|
+
* parse argument
|
376
|
+
*/
|
377
|
+
rb_scan_args(argc, argv, "21", &width, &height, &opt);
|
378
|
+
|
379
|
+
/*
|
380
|
+
* eval argument
|
381
|
+
*/
|
382
|
+
Check_Type(width, T_FIXNUM);
|
383
|
+
Check_Type(height, T_FIXNUM);
|
384
|
+
|
385
|
+
if (FIX2INT(width) < 1 || FIX2INT(height) < 1){
|
386
|
+
ARGUMENT_ERROR("too small");
|
387
|
+
}
|
388
|
+
|
389
|
+
if (opt != Qnil) {
|
390
|
+
Check_Type(opt, T_HASH);
|
391
|
+
rb_get_kwargs(opt, opts_ids, 0, N(opts_ids), opts);
|
392
|
+
|
393
|
+
// :column_step
|
394
|
+
if (opts[0] != Qundef) ptr->step = FIX2INT(opts[0]);
|
395
|
+
|
396
|
+
// :margin_x
|
397
|
+
if (opts[1] != Qundef) ptr->margin_x = FIX2INT(opts[1]);
|
398
|
+
|
399
|
+
// :margin_y
|
400
|
+
if (opts[2] != Qundef) ptr->margin_y = FIX2INT(opts[2]);
|
401
|
+
}
|
402
|
+
|
403
|
+
ptr->width = FIX2INT(width);
|
404
|
+
ptr->height = FIX2INT(height);
|
405
|
+
|
406
|
+
ptr->stride = (ptr->margin_x + (ptr->width * ptr->step)) * 3;
|
407
|
+
ptr->size = ptr->stride * (ptr->height + ptr->margin_y);
|
408
|
+
ptr->buf = rb_str_buf_new(ptr->size);
|
409
|
+
|
410
|
+
/*
|
411
|
+
* clear buffer
|
412
|
+
*/
|
413
|
+
rb_str_set_len(ptr->buf, ptr->size);
|
414
|
+
memset(RSTRING_PTR(ptr->buf), 0, RSTRING_LEN(ptr->buf));
|
415
|
+
|
416
|
+
return self;
|
417
|
+
}
|
418
|
+
|
419
|
+
static VALUE
|
420
|
+
rb_fb_width(VALUE self)
|
421
|
+
{
|
422
|
+
rb_fb_t* ptr;
|
423
|
+
|
424
|
+
/*
|
425
|
+
* extract context data
|
426
|
+
*/
|
427
|
+
TypedData_Get_Struct(self, rb_fb_t, &fb_data_type, ptr);
|
428
|
+
|
429
|
+
return INT2FIX(ptr->margin_x + (ptr->width * ptr->step));
|
430
|
+
}
|
431
|
+
|
432
|
+
static VALUE
|
433
|
+
rb_fb_height(VALUE self)
|
434
|
+
{
|
435
|
+
rb_fb_t* ptr;
|
436
|
+
|
437
|
+
/*
|
438
|
+
* extract context data
|
439
|
+
*/
|
440
|
+
TypedData_Get_Struct(self, rb_fb_t, &fb_data_type, ptr);
|
441
|
+
|
442
|
+
return INT2FIX(ptr->height + ptr->margin_y);
|
443
|
+
}
|
444
|
+
|
445
|
+
static VALUE
|
446
|
+
rb_fb_to_s(VALUE self)
|
447
|
+
{
|
448
|
+
rb_fb_t* ptr;
|
449
|
+
|
450
|
+
/*
|
451
|
+
* extract context data
|
452
|
+
*/
|
453
|
+
TypedData_Get_Struct(self, rb_fb_t, &fb_data_type, ptr);
|
454
|
+
|
455
|
+
return ptr->buf;
|
456
|
+
}
|
457
|
+
|
458
|
+
static VALUE
|
459
|
+
rb_fb_put_column(VALUE self, VALUE col, VALUE dat)
|
460
|
+
{
|
461
|
+
rb_fb_t* ptr;
|
462
|
+
uint8_t* p;
|
463
|
+
uint8_t r;
|
464
|
+
uint8_t g;
|
465
|
+
uint8_t b;
|
466
|
+
int i;
|
467
|
+
int j;
|
468
|
+
int k;
|
469
|
+
|
470
|
+
/*
|
471
|
+
* extract context data
|
472
|
+
*/
|
473
|
+
TypedData_Get_Struct(self, rb_fb_t, &fb_data_type, ptr);
|
474
|
+
|
475
|
+
/*
|
476
|
+
* check argument
|
477
|
+
*/
|
478
|
+
Check_Type(col, T_FIXNUM);
|
479
|
+
Check_Type(dat, T_ARRAY);
|
480
|
+
|
481
|
+
if (FIX2INT(col) < 0 || FIX2INT(col) >= ptr->width) {
|
482
|
+
ARGUMENT_ERROR("invalid column number");
|
483
|
+
}
|
484
|
+
|
485
|
+
if (RARRAY_LEN(dat) != (ptr->height * 3)) {
|
486
|
+
ARGUMENT_ERROR("invalid data length");
|
487
|
+
}
|
488
|
+
|
489
|
+
/*
|
490
|
+
* put pixel data
|
491
|
+
*/
|
492
|
+
p = (uint8_t*)RSTRING_PTR(ptr->buf) +
|
493
|
+
((ptr->margin_x + (FIX2INT(col) * ptr->step)) * 3);
|
494
|
+
i = 0;
|
495
|
+
|
496
|
+
for (j = 0; j < ptr->height; j++) {
|
497
|
+
r = FIX2ULONG(rb_ary_entry(dat, i++)) & 0xff;
|
498
|
+
g = FIX2ULONG(rb_ary_entry(dat, i++)) & 0xff;
|
499
|
+
b = FIX2ULONG(rb_ary_entry(dat, i++)) & 0xff;
|
500
|
+
|
501
|
+
for (k = 0; k < ptr->step; k++) {
|
502
|
+
p[0] = r;
|
503
|
+
p[1] = g;
|
504
|
+
p[2] = b;
|
505
|
+
|
506
|
+
p += 3;
|
507
|
+
}
|
508
|
+
|
509
|
+
p += (ptr->stride - (k * 3));
|
510
|
+
}
|
511
|
+
|
512
|
+
return self;
|
513
|
+
}
|
514
|
+
|
515
|
+
static void
|
516
|
+
put_string(rb_fb_t* ptr, int row, int col,
|
517
|
+
VALUE rstr, uint8_t r, uint8_t g, uint8_t b)
|
518
|
+
{
|
519
|
+
uint8_t* head;
|
520
|
+
uint8_t* tail;
|
521
|
+
uint8_t* p0;
|
522
|
+
char* str;
|
523
|
+
int len;
|
524
|
+
|
525
|
+
uint8_t* p;
|
526
|
+
const uint8_t* gl; // as Glyph
|
527
|
+
int i;
|
528
|
+
int j;
|
529
|
+
uint8_t m;
|
530
|
+
|
531
|
+
head = (uint8_t*)RSTRING_PTR(ptr->buf);
|
532
|
+
tail = head + RSTRING_LEN(ptr->buf);
|
533
|
+
p0 = head + ((row * ptr->stride) + (col * 3));
|
534
|
+
str = RSTRING_PTR(rstr);
|
535
|
+
len = RSTRING_LEN(rstr);
|
536
|
+
|
537
|
+
for (i = 0; i < len; i++) {
|
538
|
+
p = p0 + (i * 6 * 3);
|
539
|
+
gl = font + (str[i] * 10);
|
540
|
+
|
541
|
+
for (j = 0; j < 10; j++) {
|
542
|
+
for (m = 0x80; m >= 0x08; m >>= 1) {
|
543
|
+
if ((gl[j] & m) && (p + 0 >= head) && (p + 3 < tail)) {
|
544
|
+
p[0] = r;
|
545
|
+
p[1] = g;
|
546
|
+
p[2] = b;
|
547
|
+
}
|
548
|
+
|
549
|
+
p += 3;
|
550
|
+
}
|
551
|
+
|
552
|
+
p += (ptr->stride - (5 * 3));
|
553
|
+
}
|
554
|
+
}
|
555
|
+
}
|
556
|
+
|
557
|
+
static VALUE
|
558
|
+
rb_fb_hline(VALUE self, VALUE row, VALUE label)
|
559
|
+
{
|
560
|
+
rb_fb_t* ptr;
|
561
|
+
uint8_t* p;
|
562
|
+
int i;
|
563
|
+
int j;
|
564
|
+
int w;
|
565
|
+
|
566
|
+
/*
|
567
|
+
* extract context data
|
568
|
+
*/
|
569
|
+
TypedData_Get_Struct(self, rb_fb_t, &fb_data_type, ptr);
|
570
|
+
|
571
|
+
/*
|
572
|
+
* check argument
|
573
|
+
*/
|
574
|
+
Check_Type(row, T_FIXNUM);
|
575
|
+
Check_Type(label, T_STRING);
|
576
|
+
|
577
|
+
if (FIX2INT(row) < 0 || FIX2INT(row) >= ptr->height) {
|
578
|
+
ARGUMENT_ERROR("invalid column number");
|
579
|
+
}
|
580
|
+
|
581
|
+
/*
|
582
|
+
* put line
|
583
|
+
*/
|
584
|
+
p = (uint8_t*)RSTRING_PTR(ptr->buf) + (FIX2INT(row) * ptr->stride);
|
585
|
+
w = ptr->margin_x + (ptr->width * ptr->step);
|
586
|
+
|
587
|
+
for (i = 0; i < w; i++) {
|
588
|
+
for (j = 0; j < ptr->step; j++) {
|
589
|
+
int v;
|
590
|
+
v = p[0] + 0xff;
|
591
|
+
p[0] = (v <= 0xff)? v: 0xff;
|
592
|
+
|
593
|
+
v = p[1] + 0x00;
|
594
|
+
p[1] = (v <= 0xff)? v: 0xff;
|
595
|
+
|
596
|
+
v = p[2] + 0x00;
|
597
|
+
p[2] = (v <= 0xff)? v: 0xff;
|
598
|
+
}
|
599
|
+
|
600
|
+
p += 3;
|
601
|
+
}
|
602
|
+
|
603
|
+
/*
|
604
|
+
* put label
|
605
|
+
*/
|
606
|
+
put_string(ptr, FIX2INT(row) - 11, 4, label, 0xff, 0x00, 0x00);
|
607
|
+
|
608
|
+
return self;
|
609
|
+
}
|
610
|
+
|
611
|
+
static VALUE
|
612
|
+
rb_fb_vline(VALUE self, VALUE col, VALUE label)
|
613
|
+
{
|
614
|
+
rb_fb_t* ptr;
|
615
|
+
uint8_t* p;
|
616
|
+
int i;
|
617
|
+
int h;
|
618
|
+
|
619
|
+
/*
|
620
|
+
* extract context data
|
621
|
+
*/
|
622
|
+
TypedData_Get_Struct(self, rb_fb_t, &fb_data_type, ptr);
|
623
|
+
|
624
|
+
/*
|
625
|
+
* check argument
|
626
|
+
*/
|
627
|
+
Check_Type(col, T_FIXNUM);
|
628
|
+
Check_Type(label, T_STRING);
|
629
|
+
|
630
|
+
if (FIX2INT(col) < 0 || FIX2INT(col) >= ptr->width) {
|
631
|
+
ARGUMENT_ERROR("invalid column number");
|
632
|
+
}
|
633
|
+
|
634
|
+
/*
|
635
|
+
* put line
|
636
|
+
*/
|
637
|
+
p = (uint8_t*)RSTRING_PTR(ptr->buf) +
|
638
|
+
((ptr->margin_x + (FIX2INT(col) * ptr->step)) * 3);
|
639
|
+
h = ptr->margin_y + ptr->height;
|
640
|
+
|
641
|
+
for (i = 0; i < h; i++) {
|
642
|
+
int v;
|
643
|
+
v = p[0] + 0x40;
|
644
|
+
p[0] = (v <= 0xff)? v: 0xff;
|
645
|
+
|
646
|
+
v = p[1] + 0x40;
|
647
|
+
p[1] = (v <= 0xff)? v: 0xff;
|
648
|
+
|
649
|
+
v = p[2] + 0xff;
|
650
|
+
p[2] = (v <= 0xff)? v: 0xff;
|
651
|
+
|
652
|
+
p += ptr->stride;
|
653
|
+
}
|
654
|
+
|
655
|
+
/*
|
656
|
+
* put label
|
657
|
+
*/
|
658
|
+
put_string(ptr,
|
659
|
+
ptr->height + 14,
|
660
|
+
ptr->margin_x + (FIX2INT(col) * ptr->step) + 4,
|
661
|
+
label,
|
662
|
+
0x80,
|
663
|
+
0x80,
|
664
|
+
0xff);
|
665
|
+
|
666
|
+
return self;
|
667
|
+
}
|
668
|
+
|
669
|
+
void
|
670
|
+
Init_fb()
|
671
|
+
{
|
672
|
+
int i;
|
673
|
+
|
674
|
+
wavspa_module = rb_define_module("WavSpectrumAnalyzer");
|
675
|
+
fb_klass = rb_define_class_under(wavspa_module,
|
676
|
+
"FrameBuffer", rb_cObject);
|
677
|
+
|
678
|
+
rb_define_alloc_func(fb_klass, rb_fb_alloc);
|
679
|
+
rb_define_method(fb_klass, "initialize", rb_fb_initialize, -1);
|
680
|
+
rb_define_method(fb_klass, "width", rb_fb_width, 0);
|
681
|
+
rb_define_method(fb_klass, "height", rb_fb_height, 0);
|
682
|
+
rb_define_method(fb_klass, "to_s", rb_fb_to_s, 0);
|
683
|
+
rb_define_method(fb_klass, "put_column", rb_fb_put_column, 2);
|
684
|
+
rb_define_method(fb_klass, "hline", rb_fb_hline, 2);
|
685
|
+
rb_define_method(fb_klass, "vline", rb_fb_vline, 2);
|
686
|
+
|
687
|
+
for (i = 0; i < (int)N(opts_keys); i++) {
|
688
|
+
opts_ids[i] = rb_intern_const(opts_keys[i]);
|
689
|
+
}
|
690
|
+
}
|