-
Notifications
You must be signed in to change notification settings - Fork 0
/
robin.h
666 lines (567 loc) · 20.7 KB
/
robin.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
/*
robin.h - v0.1
MIDI frequency modulation synthesizer
*/
#ifndef ROBIN_H
#define ROBIN_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifdef RBN_STATIC
#define RBNDEF static
#else
#define RBNDEF extern
#endif
#ifndef RBN_CHAN_COUNT
#define RBN_CHAN_COUNT 1
#endif
#ifndef RBN_PROGRAM_COUNT
#define RBN_PROGRAM_COUNT 1
#endif
#ifndef RBN_VOICE_COUNT
#define RBN_VOICE_COUNT 64
#endif
#ifndef RBN_OPERATOR_COUNT
#define RBN_OPERATOR_COUNT 8
#endif
#ifndef RBN_ENVPT_COUNT
#define RBN_ENVPT_COUNT 6
#endif
#ifndef RBN_FILTER_COUNT
#define RBN_FILTER_COUNT 4
#endif
#ifndef RBN_BLOCK_SAMPLES
#define RBN_BLOCK_SAMPLES 64
#endif
typedef enum rbn_result {
rbn_success,
rbn_unknown_msg_type,
rbn_unknown_control,
rbn_unknown_sample_format,
rbn_out_of_voice,
} rbn_result;
typedef enum rbn_sample_format {
rbn_f32,
rbn_s16,
} rbn_sample_format;
typedef enum rbn_msg_type {
rbn_end_of_track = 0x2f,
rbn_set_tempo = 0x51,
rbn_note_off = 0x80,
rbn_note_on = 0x90,
rbn_key_pressure = 0xa0,
rbn_control_change = 0xb0,
rbn_program_change = 0xc0,
rbn_channel_pressure = 0xd0,
rbn_pitch_bend = 0xe0,
} rbn_msg_type;
typedef enum rbn_control {
rbn_bank_select,
rbn_modulation_wheel,
rbn_breath,
rbn_volume = 7,
rbn_balance,
rbn_pan = 10,
rbn_expression,
rbn_nrpn = 98,
rbn_rpn = 100,
rbn_max_controls,
} rbn_control;
typedef enum rbn_filter_type {
rbn_filter_none,
rbn_filter_lowpass,
rbn_filter_highpass,
} rbn_filter_type;
typedef struct rbn_envelope {
struct {
float time, value;
} points[RBN_ENVPT_COUNT];
// Linear ramp to zero after sustain
// 0 means instantaneous
// -1 means stay at sustain value
float release_time;
} rbn_envelope;
typedef struct rbn_operator {
rbn_envelope volume_envelope;
rbn_envelope pitch_envelope;
float freq_offset;
float freq_ratio;
float noise;
float output;
} rbn_operator;
typedef struct rbn_filter {
rbn_filter_type type;
float cutoff;
} rbn_filter;
typedef struct rbn_program {
rbn_operator operators[RBN_OPERATOR_COUNT];
rbn_filter filters[RBN_FILTER_COUNT];
float op_matrix[RBN_OPERATOR_COUNT][RBN_OPERATOR_COUNT];
float fil_matrix[RBN_OPERATOR_COUNT][RBN_FILTER_COUNT];
// Cached
uint64_t sustain_samples;
uint64_t release_samples;
uint32_t operator_usage_mask;
} rbn_program;
typedef struct rbn_voice {
float phases[RBN_OPERATOR_COUNT];
float values[RBN_OPERATOR_COUNT];
float volumes[RBN_OPERATOR_COUNT];
float pitches[RBN_OPERATOR_COUNT];
uint64_t press_index;
uint64_t release_index;
uint64_t inactive_index;
rbn_program* program;
float base_freq_rate;
float velocity;
uint8_t channel;
uint8_t key;
} rbn_voice;
typedef struct rbn_channel {
float volume[2];
float pan;
float pitch_bend;
uint8_t program;
uint8_t controls[rbn_max_controls];
} rbn_channel;
typedef union rbn_msg {
uint32_t u32;
uint8_t u8[4];
struct {
uint8_t channel;
uint8_t type;
union {
uint8_t key;
uint8_t instrument;
uint8_t control;
};
union {
uint8_t velocity;
uint8_t value;
};
};
} rbn_msg;
typedef struct rbn_config {
uint32_t sample_rate;
} rbn_config;
typedef struct rbn_output_config {
void* left_buffer;
void* right_buffer;
intptr_t stride;
uint64_t sample_count;
rbn_sample_format sample_format;
} rbn_output_config;
typedef struct rbn_instance {
rbn_config config;
uint64_t sample_index;
uint64_t output_index;
uint64_t rendered_samples;
float dynamic_range;
rbn_channel channels[RBN_CHAN_COUNT];
rbn_program programs[RBN_PROGRAM_COUNT];
rbn_voice voices[RBN_VOICE_COUNT];
float sample_buffer[RBN_BLOCK_SAMPLES * 2];
// Cached
float inv_sample_rate;
} rbn_instance;
RBNDEF rbn_result rbn_init(rbn_instance* inst, const rbn_config* config);
RBNDEF rbn_result rbn_shutdown(rbn_instance* inst);
RBNDEF rbn_result rbn_refresh(rbn_instance* inst);
RBNDEF rbn_result rbn_reset(rbn_instance* inst);
RBNDEF rbn_result rbn_render(rbn_instance* inst, rbn_output_config* output_config);
RBNDEF rbn_result rbn_send_msg(rbn_instance* inst, rbn_msg msg);
RBNDEF rbn_result rbn_play_note(rbn_instance* inst, uint8_t channel, uint8_t key, uint8_t velocity);
RBNDEF rbn_result rbn_stop_note(rbn_instance* inst, uint8_t channel, uint8_t key);
RBNDEF rbn_result rbn_stop_all_notes(rbn_instance* inst);
RBNDEF rbn_result rbn_set_program(rbn_instance* inst, uint8_t channel, uint8_t program);
RBNDEF rbn_result rbn_set_pitch_bend(rbn_instance* inst, uint8_t channel, float value);
#ifdef __cplusplus
}
#endif
#endif // ROBIN_H
#ifdef RBN_IMPLEMENTATION
#ifdef __cplusplus
extern "C" {
#endif
#define RBN_PI 3.1416f
#define RBN_TAU 6.2832f
#define RBN_INV_TAU (1.f/6.2832f)
#define RBN_OPERATOR_USED(prg, op) (prg->operator_usage_mask & (1 << op))
#ifndef RBN_SIN
#include <math.h>
#define RBN_SIN(x) sinf(x)
#endif
#ifndef RBN_COS
#include <math.h>
#define RBN_COS(x) cosf(x)
#endif
#ifndef RBN_POW
#include <math.h>
#define RBN_POW(x,y) powf(x,y)
#endif
#ifndef RBN_RAND
#include <stdlib.h>
#define RBN_RAND() (((float)rand() / (RAND_MAX / 2)) - 1.f)
#endif
#ifndef RBN_MEMCPY
#include <string.h>
#define RBN_MEMCPY memcpy
#endif
#ifndef RBN_MEMSET
#include <string.h>
#define RBN_MEMSET memset
#endif
static float rbn_max(float a, float b) {
return a > b ? a : b;
}
static void rbn_channel_update_volumes(rbn_channel* channel) {
const float channel_volume = (channel->controls[rbn_volume] / 126.f) * (channel->controls[rbn_expression] / 126.f);
const float pan = channel->controls[rbn_pan] / 126.f;
channel->volume[0] = channel_volume * RBN_COS((RBN_PI / 2.f) * pan);
channel->volume[1] = channel_volume * RBN_SIN((RBN_PI / 2.f) * pan);
}
static void rbn_voice_compute_base_freq_rate(const rbn_instance* inst, rbn_voice* voice) {
const rbn_channel* channel = inst->channels + voice->channel;
const float key = (voice->key - 69.f) + channel->pitch_bend;
const float frequency = 440.f * RBN_POW(2.f, key / 12.f);
voice->base_freq_rate = frequency / inst->config.sample_rate;
}
static void rbn_compute_envelope(const rbn_instance* inst, const rbn_voice* voice, const rbn_envelope* envelope, float current, float* rate) {
float sustain_value = 0.f;
float sustain_time = 0.f;
const float press_time = (float)(inst->sample_index - voice->press_index) * inst->inv_sample_rate;
const int has_released = voice->release_index != UINT64_MAX && voice->release_index <= inst->sample_index;
for(uintptr_t i = 0; i < RBN_ENVPT_COUNT; i++) {
if(!has_released && envelope->points[i].time >= press_time) {
const float next_time = envelope->points[i].time;
const float next_value = envelope->points[i].value;
const float time_to_next = next_time - press_time;
*rate = (next_value - current) / rbn_max(time_to_next * inst->config.sample_rate, RBN_BLOCK_SAMPLES);
return;
}
if(i == 0 || envelope->points[i].time > 0.f) {
sustain_value = envelope->points[i].value;
sustain_time = envelope->points[i].time;
} else {
break;
}
}
if(!has_released || envelope->release_time < 0.f) {
*rate = (sustain_value - current) / RBN_BLOCK_SAMPLES;
return;
}
if(envelope->release_time > 0.f) {
const float release_time = (float)(inst->sample_index - voice->release_index) * inst->inv_sample_rate;
const float time_to_zero = envelope->release_time - release_time;
*rate = -current / rbn_max(time_to_zero * inst->config.sample_rate, RBN_BLOCK_SAMPLES);
} else { // Go to zero
*rate = -current / RBN_BLOCK_SAMPLES;
}
}
static rbn_result rbn_render_voice_block(rbn_instance* inst, rbn_voice* voice, rbn_channel* channel, float* samples) {
float values[RBN_OPERATOR_COUNT];
float volume_rates[RBN_OPERATOR_COUNT];
float pitch_rates[RBN_OPERATOR_COUNT];
const float base_freq_rate = voice->base_freq_rate;
const float velocity = voice->velocity;
const rbn_program* program = voice->program;
const rbn_operator* operators = program->operators;
float* volumes = voice->volumes;
float* pitches = voice->pitches;
for(uintptr_t i = 0; i < RBN_OPERATOR_COUNT; i++) {
if(RBN_OPERATOR_USED(program, i)) {
rbn_compute_envelope(inst, voice, &operators[i].volume_envelope, volumes[i], volume_rates + i);
rbn_compute_envelope(inst, voice, &operators[i].pitch_envelope, pitches[i], pitch_rates + i);
}
}
for(uintptr_t i = 0; i < RBN_BLOCK_SAMPLES; i++) {
for(uintptr_t j = 0; j < RBN_OPERATOR_COUNT; j++) {
if(!RBN_OPERATOR_USED(program, j)) {
continue; // Unused operator
}
float phase = voice->phases[j];
for(uintptr_t k = 0; k < RBN_OPERATOR_COUNT; k++) {
if(RBN_OPERATOR_USED(program, k)) {
phase += program->op_matrix[k][j] * voice->values[k] * RBN_INV_TAU;
}
}
const float noisef = program->operators[j].noise;
const float noise = RBN_RAND();
values[j] = (RBN_SIN(phase * RBN_TAU) * (1.f - noisef) + noise * noisef) * volumes[j];
volumes[j] += volume_rates[j];
}
for(uintptr_t j = 0; j < RBN_OPERATOR_COUNT; j++) {
if(!RBN_OPERATOR_USED(program, j)) {
continue; // Unused operator
}
const float value = values[j] * operators[j].output * velocity;
samples[i * 2 + 0] += value * channel->volume[0];
samples[i * 2 + 1] += value * channel->volume[1];
voice->phases[j] += base_freq_rate * operators[j].freq_ratio * RBN_POW(2.f, pitches[j]);
voice->values[j] = values[j];
pitches[j] += pitch_rates[j];
}
}
for(uintptr_t i = 0; i < RBN_OPERATOR_COUNT; i++) {
if(RBN_OPERATOR_USED(program, i)) {
voice->phases[i] = fmodf(voice->phases[i], 1.f);
}
}
inst->rendered_samples += RBN_BLOCK_SAMPLES;
return rbn_success;
}
static rbn_result rbn_render_block(rbn_instance* inst, float* samples) {
for(uintptr_t v = 0; v < RBN_VOICE_COUNT; v++) {
rbn_voice* voice = inst->voices + v;
if(voice->inactive_index > inst->sample_index) {
rbn_render_voice_block(inst, voice, inst->channels + voice->channel, samples);
}
}
return rbn_success;
}
static float rbn_compute_dynamic_range(rbn_instance* inst, float sample) {
const float range = fabsf(sample) * 1.01f;
if(range > inst->dynamic_range) {
inst->dynamic_range = range;
}
return sample / inst->dynamic_range;
}
static uint64_t rbn_output_samples(rbn_instance* inst, rbn_output_config* output_config) {
uint64_t output_sample_count = inst->sample_index - inst->output_index;
if(output_sample_count == 0) {
return output_config->sample_count;
}
if(output_sample_count > output_config->sample_count) {
output_sample_count = output_config->sample_count;
}
float* bsamples = inst->sample_buffer + (inst->output_index % RBN_BLOCK_SAMPLES) * 2;
float* lf32samples = (float*)output_config->left_buffer;
float* rf32samples = (float*)output_config->right_buffer;
int16_t* li16samples = (int16_t*)output_config->left_buffer;
int16_t* ri16samples = (int16_t*)output_config->right_buffer;
switch(output_config->sample_format) {
case rbn_f32:
for(uintptr_t i = 0; i < output_sample_count; i++) {
*lf32samples = rbn_compute_dynamic_range(inst, *bsamples++);
*rf32samples = rbn_compute_dynamic_range(inst, *bsamples++);
lf32samples += output_config->stride;
rf32samples += output_config->stride;
}
output_config->left_buffer = lf32samples;
output_config->right_buffer = rf32samples;
break;
case rbn_s16:
for(uintptr_t i = 0; i < output_sample_count; i++) {
*li16samples = (int16_t)(rbn_compute_dynamic_range(inst, *bsamples++) * 0x8000);
*ri16samples = (int16_t)(rbn_compute_dynamic_range(inst, *bsamples++) * 0x8000);
li16samples += output_config->stride;
ri16samples += output_config->stride;
}
output_config->left_buffer = li16samples;
output_config->right_buffer = ri16samples;
break;
}
inst->output_index += output_sample_count;
output_config->sample_count -= output_sample_count;
return output_config->sample_count;
}
rbn_result rbn_init(rbn_instance* inst, const rbn_config* config) {
RBN_MEMSET(inst, 0, sizeof(rbn_instance));
RBN_MEMCPY(&inst->config, config, sizeof(*config));
rbn_reset(inst);
inst->inv_sample_rate = 1.f / config->sample_rate;
for(uintptr_t i = 0; i < RBN_CHAN_COUNT; i++) {
rbn_channel* channel = inst->channels + i;
channel->controls[rbn_volume] = 127; // Full volume
channel->controls[rbn_expression] = 127; // Full expression
channel->controls[rbn_balance] = 64; // Centered balance
channel->controls[rbn_pan] = 64; // Centered pan
rbn_channel_update_volumes(channel);
}
return rbn_refresh(inst);
}
rbn_result rbn_shutdown(rbn_instance* inst) {
return rbn_success;
}
rbn_result rbn_refresh(rbn_instance* inst) {
for(uintptr_t i = 0; i < RBN_PROGRAM_COUNT; i++) {
rbn_program* program = inst->programs + i;
program->sustain_samples = 0;
program->release_samples = RBN_BLOCK_SAMPLES;
program->operator_usage_mask = 0;
for(uintptr_t j = 0; j < RBN_OPERATOR_COUNT; j++) {
rbn_operator* op = program->operators + j;
// Compute max release time in samples
if(op->volume_envelope.release_time > 0.f) {
uint64_t release_samples = (uint64_t)(op->volume_envelope.release_time * inst->config.sample_rate);
if(release_samples > program->release_samples) {
program->release_samples = release_samples;
}
}
// Compute max time to sustain in samples
for(uintptr_t k = 0; k < RBN_ENVPT_COUNT; k++) {
if(op->volume_envelope.points[k].time > 0.f) {
uint64_t sustain_samples = (uint64_t)(op->volume_envelope.points[k].time * inst->config.sample_rate);
if(sustain_samples > program->sustain_samples) {
program->sustain_samples = sustain_samples;
}
}
}
// Check operator usage
if(op->output > 0.f) {
program->operator_usage_mask |= 1 << j;
}
}
// Recurse operator usage via matrix
for(uintptr_t j = 0; j < RBN_OPERATOR_COUNT; j++) {
for(uintptr_t k = 0; k < RBN_OPERATOR_COUNT; k++) {
if((program->operator_usage_mask & (1 << j))
&& !(program->operator_usage_mask & (1 << k))
&& program->op_matrix[k][j]) {
program->operator_usage_mask |= 1 << k;
j = k = j > k ? j : k;
}
}
}
}
return rbn_success;
}
rbn_result rbn_reset(rbn_instance* inst) {
RBN_MEMSET(&inst->voices, 0, sizeof(inst->voices));
inst->sample_index = 0;
inst->output_index = 0;
inst->rendered_samples = 0;
inst->dynamic_range = 1.f;
return rbn_success;
}
rbn_result rbn_render(rbn_instance* inst, rbn_output_config* output_config) {
while(rbn_output_samples(inst, output_config) > 0) {
memset(inst->sample_buffer, 0, sizeof(inst->sample_buffer));
rbn_result result = rbn_render_block(inst, inst->sample_buffer);
if(result != rbn_success) {
return result;
}
inst->sample_index += RBN_BLOCK_SAMPLES;
}
return rbn_success;
}
rbn_result rbn_send_msg(rbn_instance* inst, rbn_msg msg) {
rbn_channel* channel = inst->channels + msg.channel;
switch(msg.type) {
case rbn_end_of_track:
case rbn_set_tempo: break; // Ignore
case rbn_note_off:
return rbn_stop_note(inst, msg.channel, msg.key);
case rbn_note_on:
if(msg.velocity > 0) {
return rbn_play_note(inst, msg.channel, msg.key, msg.velocity);
} else {
return rbn_stop_note(inst, msg.channel, msg.key);
}
case rbn_control_change:
//printf("%d %d %d %d\n", msg.channel, msg.type, msg.key, msg.velocity);
if(msg.control < rbn_max_controls) {
channel->controls[msg.control] = msg.value;
switch(msg.control) {
case rbn_volume: case rbn_expression: case rbn_pan: case rbn_balance:
rbn_channel_update_volumes(channel);
break;
}
} else {
return rbn_unknown_control;
}
break;
case rbn_program_change: rbn_set_program(inst, msg.channel, msg.instrument); break;
case rbn_pitch_bend: return rbn_set_pitch_bend(inst, msg.channel, ((msg.u8[2] | (msg.u8[3] << 7)) - 0x2000) / (float)0x1000); break;
default:
//printf("%d %d %d %d\n", msg.channel, msg.type, msg.key, msg.velocity);
return rbn_unknown_msg_type;
}
return rbn_success;
}
rbn_result rbn_play_note(rbn_instance* inst, uint8_t channel, uint8_t key, uint8_t velocity) {
for(uintptr_t i = 0; i < RBN_VOICE_COUNT; i++) {
rbn_voice* voice = inst->voices + i;
const int active = voice->inactive_index > inst->sample_index;
if(!active) {
RBN_MEMSET(voice, 0, sizeof(rbn_voice));
voice->inactive_index = UINT64_MAX;
voice->press_index = inst->sample_index;
voice->release_index = UINT64_MAX;
voice->program = inst->programs + inst->channels[channel].program;
voice->channel = channel;
voice->key = key;
voice->velocity = velocity / 127.f;
#ifdef RBN_KEYMAP_CHANNEL
if(channel == RBN_KEYMAP_CHANNEL) {
voice->key = 60;
voice->program = inst->programs + RBN_KEYMAP_OFFSET + key;
// Keymapped notes are instantly off
voice->release_index = voice->press_index + voice->program->sustain_samples;
voice->inactive_index = voice->release_index + voice->program->release_samples;
}
#endif
rbn_voice_compute_base_freq_rate(inst, voice);
return rbn_success;
}
}
return rbn_out_of_voice;
}
rbn_result rbn_stop_note(rbn_instance* inst, uint8_t channel, uint8_t key) {
for(uintptr_t i = 0; i < RBN_VOICE_COUNT; i++) {
rbn_voice* voice = inst->voices + i;
const int active = voice->inactive_index > inst->sample_index;
if(active && voice->channel == channel && voice->key == key) {
voice->release_index = inst->sample_index;
voice->inactive_index = inst->sample_index + voice->program->release_samples;
}
}
return rbn_success;
}
rbn_result rbn_stop_all_notes(rbn_instance* inst) {
RBN_MEMSET(inst->voices, 0, RBN_VOICE_COUNT * sizeof(rbn_voice));
return rbn_success;
}
rbn_result rbn_set_program(rbn_instance* inst, uint8_t channel, uint8_t program) {
inst->channels[channel].program = program;
return rbn_success;
}
rbn_result rbn_set_pitch_bend(rbn_instance* inst, uint8_t channel, float value) {
inst->channels[channel].pitch_bend = value;
for(uintptr_t i = 0; i < RBN_VOICE_COUNT; i++) {
rbn_voice* voice = inst->voices + i;
const int active = voice->inactive_index > inst->sample_index;
// Update pitch bend for active unreleased voices
if(voice->channel == channel && active && voice->release_index == UINT64_MAX) {
rbn_voice_compute_base_freq_rate(inst, voice);
}
}
return rbn_success;
}
#ifdef __cplusplus
}
#endif
#endif // RBN_IMPLEMENTATION
/*
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org>
*/