| ... | ... |
@@ -52,7 +52,7 @@ fi |
| 52 | 52 |
|
| 53 | 53 |
mkdir -p bin |
| 54 | 54 |
CC="${CC:-cc}"
|
| 55 |
-CFLAGS="${CFLAGS:--std=c99 -Wall -Wno-unknown-pragmas}"
|
|
| 55 |
+CFLAGS="${CFLAGS:--std=c89 -Wall -Wno-unknown-pragmas}"
|
|
| 56 | 56 |
case "$(uname -s 2>/dev/null)" in |
| 57 | 57 |
MSYS_NT*|MINGW*) # MSYS2 on Windows |
| 58 | 58 |
FILE_LDFLAGS="-liberty" |
| ... | ... |
@@ -109,4 +109,3 @@ if [ $norun = 1 ]; then exit; fi |
| 109 | 109 |
./bin/uxnasm projects/examples/devices/audio-tests.tal bin/audio-tests.rom |
| 110 | 110 |
|
| 111 | 111 |
./bin/uxnemu -2x bin/audio-tests.rom |
| 112 |
- |
| ... | ... |
@@ -1,6 +1,7 @@ |
| 1 | 1 |
#include "../uxn.h" |
| 2 | 2 |
#include "audio.h" |
| 3 | 3 |
#include <stdbool.h> |
| 4 |
+#include <string.h> |
|
| 4 | 5 |
|
| 5 | 6 |
/* |
| 6 | 7 |
Copyright (c) 2021-2023 Devine Lu Linvega, Andrew Alderwick |
| ... | ... |
@@ -2601,12 +2602,13 @@ next_sample(Sample *sample) {
|
| 2601 | 2602 |
return next; |
| 2602 | 2603 |
} |
| 2603 | 2604 |
|
| 2604 |
-int |
|
| 2605 |
+void |
|
| 2605 | 2606 |
audio_handler(void *ctx, Uint8 *out_stream, int len) {
|
| 2606 | 2607 |
Sint16 *stream = (Sint16 *)out_stream; |
| 2607 | 2608 |
memset(stream, 0x00, len); |
| 2608 | 2609 |
|
| 2609 |
- for (int n = 0; n < N_CHANNELS; n++) {
|
|
| 2610 |
+ int n; |
|
| 2611 |
+ for (n = 0; n < N_CHANNELS; n++) {
|
|
| 2610 | 2612 |
Uint8 device = (3 + n) << 4; |
| 2611 | 2613 |
Uxn *u = (Uxn *)ctx; |
| 2612 | 2614 |
Uint8 *addr = &u->dev[device]; |
| ... | ... |
@@ -2643,163 +2645,12 @@ audio_handler(void *ctx, Uint8 *out_stream, int len) {
|
| 2643 | 2645 |
stream[x++] += next * channel[n].vol_r; |
| 2644 | 2646 |
} |
| 2645 | 2647 |
} |
| 2646 |
- for (int i = 0; i < len; i++) {
|
|
| 2648 |
+ int i; |
|
| 2649 |
+ for (i = 0; i < len; i++) {
|
|
| 2647 | 2650 |
stream[i] <<= 4; |
| 2648 | 2651 |
} |
| 2649 |
- |
|
| 2650 |
- return 1; |
|
| 2651 | 2652 |
} |
| 2652 | 2653 |
|
| 2653 |
-// #define NOTE_PERIOD (SAMPLE_FREQUENCY * 0x4000 / 11025) |
|
| 2654 |
-// #define ADSR_STEP (SAMPLE_FREQUENCY / 0xf) |
|
| 2655 |
- |
|
| 2656 |
-// typedef struct {
|
|
| 2657 |
-// Uint8 *addr; |
|
| 2658 |
-// Uint32 count, advance, period, age, a, d, s, r; |
|
| 2659 |
-// Uint16 i, len; |
|
| 2660 |
-// Sint8 volume[2]; |
|
| 2661 |
-// Uint8 pitch, repeat; |
|
| 2662 |
-// } UxnAudio; |
|
| 2663 |
- |
|
| 2664 |
-// /* clang-format off */ |
|
| 2665 |
- |
|
| 2666 |
-// static Uint32 advances[12] = {
|
|
| 2667 |
-// 0x80000, 0x879c8, 0x8facd, 0x9837f, 0xa1451, 0xaadc1, |
|
| 2668 |
-// 0xb504f, 0xbfc88, 0xcb2ff, 0xd7450, 0xe411f, 0xf1a1c |
|
| 2669 |
-// }; |
|
| 2670 |
- |
|
| 2671 |
-// static double detunes[256] = {
|
|
| 2672 |
-// 1.0000000000000000, 1.0002256593050698, 1.0004513695322617, |
|
| 2673 |
-// 1.0006771306930664, 1.0009029427989777, 1.0011288058614922, |
|
| 2674 |
-// 1.0013547198921082, 1.0015806849023274, 1.0018067009036538, |
|
| 2675 |
-// 1.002032767907594 , 1.0022588859256572, 1.0024850549693551, |
|
| 2676 |
-// 1.0027112750502025, 1.0029375461797159, 1.0031638683694153, |
|
| 2677 |
-// 1.0033902416308227, 1.0036166659754628, 1.0038431414148634, |
|
| 2678 |
-// 1.004069667960554 , 1.0042962456240678, 1.0045228744169397, |
|
| 2679 |
-// 1.0047495543507072, 1.004976285436911 , 1.0052030676870944, |
|
| 2680 |
-// 1.0054299011128027, 1.0056567857255843, 1.0058837215369900, |
|
| 2681 |
-// 1.006110708558573 , 1.0063377468018897, 1.0065648362784985, |
|
| 2682 |
-// 1.0067919769999607, 1.0070191689778405, 1.007246412223704 , |
|
| 2683 |
-// 1.0074737067491204, 1.0077010525656616, 1.0079284496849015, |
|
| 2684 |
-// 1.0081558981184175, 1.008383397877789 , 1.008610948974598 , |
|
| 2685 |
-// 1.0088385514204294, 1.0090662052268706, 1.0092939104055114, |
|
| 2686 |
-// 1.0095216669679448, 1.0097494749257656, 1.009977334290572 , |
|
| 2687 |
-// 1.0102052450739643, 1.0104332072875455, 1.0106612209429215, |
|
| 2688 |
-// 1.0108892860517005, 1.0111174026254934, 1.0113455706759138, |
|
| 2689 |
-// 1.011573790214578 , 1.0118020612531047, 1.0120303838031153, |
|
| 2690 |
-// 1.0122587578762337, 1.012487183484087 , 1.012715660638304 , |
|
| 2691 |
-// 1.0129441893505169, 1.0131727696323602, 1.0134014014954713, |
|
| 2692 |
-// 1.0136300849514894, 1.0138588200120575, 1.0140876066888203, |
|
| 2693 |
-// 1.0143164449934257, 1.0145453349375237, 1.0147742765327674, |
|
| 2694 |
-// 1.0150032697908125, 1.015232314723317 , 1.015461411341942 , |
|
| 2695 |
-// 1.0156905596583505, 1.0159197596842091, 1.0161490114311862, |
|
| 2696 |
-// 1.016378314910953 , 1.0166076701351838, 1.0168370771155553, |
|
| 2697 |
-// 1.0170665358637463, 1.0172960463914391, 1.017525608710318 , |
|
| 2698 |
-// 1.0177552228320703, 1.0179848887683858, 1.0182146065309567, |
|
| 2699 |
-// 1.0184443761314785, 1.0186741975816487, 1.0189040708931674, |
|
| 2700 |
-// 1.019133996077738 , 1.0193639731470658, 1.0195940021128593, |
|
| 2701 |
-// 1.0198240829868295, 1.0200542157806898, 1.0202844005061564, |
|
| 2702 |
-// 1.0205146371749483, 1.0207449257987866, 1.0209752663893958, |
|
| 2703 |
-// 1.0212056589585028, 1.0214361035178368, 1.0216666000791297, |
|
| 2704 |
-// 1.0218971486541166, 1.0221277492545349, 1.0223584018921241, |
|
| 2705 |
-// 1.0225891065786274, 1.02281986332579 , 1.0230506721453596, |
|
| 2706 |
-// 1.023281533049087 , 1.0235124460487257, 1.0237434111560313, |
|
| 2707 |
-// 1.0239744283827625, 1.0242054977406807, 1.0244366192415495, |
|
| 2708 |
-// 1.0246677928971357, 1.0248990187192082, 1.025130296719539 , |
|
| 2709 |
-// 1.0253616269099028, 1.0255930093020766, 1.0258244439078401, |
|
| 2710 |
-// 1.026055930738976 , 1.0262874698072693, 1.0265190611245079, |
|
| 2711 |
-// 1.0267507047024822, 1.0269824005529853, 1.027214148687813 , |
|
| 2712 |
-// 1.0274459491187637, 1.0276778018576387, 1.0279097069162415, |
|
| 2713 |
-// 1.0281416643063788, 1.0283736740398595, 1.0286057361284953, |
|
| 2714 |
-// 1.028837850584101 , 1.0290700174184932, 1.029302236643492 , |
|
| 2715 |
-// 1.0295345082709197, 1.0297668323126017, 1.029999208780365 , |
|
| 2716 |
-// 1.030231637686041 , 1.030464119041462 , 1.0306966528584645, |
|
| 2717 |
-// 1.0309292391488862, 1.0311618779245688, 1.0313945691973556, |
|
| 2718 |
-// 1.0316273129790936, 1.0318601092816313, 1.0320929581168212, |
|
| 2719 |
-// 1.0323258594965172, 1.0325588134325767, 1.0327918199368598, |
|
| 2720 |
-// 1.0330248790212284, 1.033257990697548 , 1.0334911549776868, |
|
| 2721 |
-// 1.033724371873515 , 1.0339576413969056, 1.0341909635597348, |
|
| 2722 |
-// 1.0344243383738811, 1.034657765851226 , 1.034891246003653 , |
|
| 2723 |
-// 1.0351247788430489, 1.0353583643813031, 1.0355920026303078, |
|
| 2724 |
-// 1.0358256936019572, 1.0360594373081489, 1.0362932337607829, |
|
| 2725 |
-// 1.0365270829717617, 1.0367609849529913, 1.0369949397163791, |
|
| 2726 |
-// 1.0372289472738365, 1.0374630076372766, 1.0376971208186156, |
|
| 2727 |
-// 1.0379312868297725, 1.0381655056826686, 1.0383997773892284, |
|
| 2728 |
-// 1.0386341019613787, 1.0388684794110492, 1.039102909750172 , |
|
| 2729 |
-// 1.0393373929906822, 1.0395719291445176, 1.0398065182236185, |
|
| 2730 |
-// 1.0400411602399278, 1.0402758552053915, 1.0405106031319582, |
|
| 2731 |
-// 1.0407454040315787, 1.040980257916207 , 1.0412151647977996, |
|
| 2732 |
-// 1.041450124688316 , 1.0416851375997183, 1.0419202035439705, |
|
| 2733 |
-// 1.0421553225330404, 1.042390494578898 , 1.042625719693516 , |
|
| 2734 |
-// 1.0428609978888699, 1.043096329176938 , 1.043331713569701 , |
|
| 2735 |
-// 1.0435671510791424, 1.0438026417172486, 1.0440381854960086, |
|
| 2736 |
-// 1.0442737824274138, 1.044509432523459 , 1.044745135796141 , |
|
| 2737 |
-// 1.04498089225746 , 1.045216701919418 , 1.0454525647940205, |
|
| 2738 |
-// 1.0456884808932754, 1.0459244502291931, 1.0461604728137874, |
|
| 2739 |
-// 1.046396548659074 , 1.046632677777072 , 1.0468688601798024, |
|
| 2740 |
-// 1.0471050958792898, 1.047341384887561 , 1.0475777272166455, |
|
| 2741 |
-// 1.047814122878576 , 1.048050571885387 , 1.0482870742491166, |
|
| 2742 |
-// 1.0485236299818055, 1.0487602390954964, 1.0489969016022356, |
|
| 2743 |
-// 1.0492336175140715, 1.0494703868430555, 1.0497072096012419, |
|
| 2744 |
-// 1.0499440858006872, 1.0501810154534512, 1.050417998571596 , |
|
| 2745 |
-// 1.0506550351671864, 1.0508921252522903, 1.0511292688389782, |
|
| 2746 |
-// 1.051366465939323 , 1.0516037165654004, 1.0518410207292894, |
|
| 2747 |
-// 1.052078378443071 , 1.0523157897188296, 1.0525532545686513, |
|
| 2748 |
-// 1.0527907730046264, 1.0530283450388465, 1.0532659706834067, |
|
| 2749 |
-// 1.053503649950405 , 1.053741382851941 , 1.0539791694001188, |
|
| 2750 |
-// 1.0542170096070436, 1.0544549034848243, 1.0546928510455722, |
|
| 2751 |
-// 1.0549308523014012, 1.0551689072644284, 1.0554070159467728, |
|
| 2752 |
-// 1.0556451783605572, 1.0558833945179062, 1.056121664430948 , |
|
| 2753 |
-// 1.0563599881118126, 1.0565983655726334, 1.0568367968255465, |
|
| 2754 |
-// 1.0570752818826903, 1.0573138207562065, 1.057552413458239 , |
|
| 2755 |
-// 1.0577910600009348, 1.0580297603964437, 1.058268514656918 , |
|
| 2756 |
-// 1.0585073227945128, 1.0587461848213857, 1.058985100749698 , |
|
| 2757 |
-// 1.0592240705916123, |
|
| 2758 |
-// }; |
|
| 2759 |
- |
|
| 2760 |
-// static UxnAudio uxn_audio[POLYPHONY]; |
|
| 2761 |
- |
|
| 2762 |
-// /* clang-format on */ |
|
| 2763 |
- |
|
| 2764 |
-// static Sint32 |
|
| 2765 |
-// envelope(UxnAudio *c, Uint32 age) |
|
| 2766 |
-// {
|
|
| 2767 |
-// if(!c->r) return 0x0888; |
|
| 2768 |
-// if(age < c->a) return 0x0888 * age / c->a; |
|
| 2769 |
-// if(age < c->d) return 0x0444 * (2 * c->d - c->a - age) / (c->d - c->a); |
|
| 2770 |
-// if(age < c->s) return 0x0444; |
|
| 2771 |
-// if(age < c->r) return 0x0444 * (c->r - age) / (c->r - c->s); |
|
| 2772 |
-// c->advance = 0; |
|
| 2773 |
-// return 0x0000; |
|
| 2774 |
-// } |
|
| 2775 |
- |
|
| 2776 |
-// int |
|
| 2777 |
-// audio_render(int instance, Sint16 *sample, Sint16 *end) |
|
| 2778 |
-// {
|
|
| 2779 |
-// /* |
|
| 2780 |
-// UxnAudio *c = &uxn_audio[instance]; |
|
| 2781 |
-// Sint32 s; |
|
| 2782 |
-// if(!c->advance || !c->period) return 0; |
|
| 2783 |
-// while(sample < end) {
|
|
| 2784 |
-// c->count += c->advance; |
|
| 2785 |
-// c->i += c->count / c->period; |
|
| 2786 |
-// c->count %= c->period; |
|
| 2787 |
-// if(c->i >= c->len) {
|
|
| 2788 |
-// if(!c->repeat) {
|
|
| 2789 |
-// c->advance = 0; |
|
| 2790 |
-// break; |
|
| 2791 |
-// } |
|
| 2792 |
-// c->i %= c->len; |
|
| 2793 |
-// } |
|
| 2794 |
-// s = (Sint8)(c->addr[c->i] + 0x80) * envelope(c, c->age++); |
|
| 2795 |
-// *sample++ += s * c->volume[0] / 0x180; |
|
| 2796 |
-// *sample++ += s * c->volume[1] / 0x180; |
|
| 2797 |
-// } |
|
| 2798 |
-// if(!c->advance) audio_finished_handler(instance); |
|
| 2799 |
-// return 1; |
|
| 2800 |
-// */ |
|
| 2801 |
-// } |
|
| 2802 |
- |
|
| 2803 | 2654 |
void |
| 2804 | 2655 |
audio_start(int idx, Uint8 *d, Uxn *u) |
| 2805 | 2656 |
{
|
| ... | ... |
@@ -2807,22 +2658,16 @@ audio_start(int idx, Uint8 *d, Uxn *u) |
| 2807 | 2658 |
Uint8 off = d[0xf] == 0xff; |
| 2808 | 2659 |
|
| 2809 | 2660 |
if (!off) {
|
| 2810 |
- // Sample. |
|
| 2811 | 2661 |
Uint16 addr = PEEK2(d + 0xa); |
| 2812 | 2662 |
Uint8 *data = &u->ram[addr]; |
| 2813 | 2663 |
Uint16 len = PEEK2(d + 0x8); |
| 2814 | 2664 |
Uint8 volume = d[0xd]; |
| 2815 | 2665 |
bool loop = !!(d[0xf] & 0x80); |
| 2816 |
- |
|
| 2817 |
- // Pitch. |
|
| 2818 | 2666 |
Uint8 pitch = d[0xf] & 0x7f; |
| 2819 |
- |
|
| 2820 |
- // ADSR. |
|
| 2821 | 2667 |
Uint8 attack = d[0x4]; |
| 2822 | 2668 |
Uint8 decay = d[0x5]; |
| 2823 | 2669 |
Uint8 sustain = d[0x6]; |
| 2824 | 2670 |
Uint8 release = d[0x7]; |
| 2825 |
- |
|
| 2826 | 2671 |
note_on(&channel[idx], duration, data, len, volume, attack, decay, sustain, release, pitch, loop); |
| 2827 | 2672 |
} else {
|
| 2828 | 2673 |
note_off(&channel[idx], duration); |
| ... | ... |
@@ -24,4 +24,4 @@ Uint16 audio_get_position(int instance); |
| 24 | 24 |
int audio_render(int instance, Sint16 *sample, Sint16 *end); |
| 25 | 25 |
void audio_start(int instance, Uint8 *d, Uxn *u); |
| 26 | 26 |
void audio_finished_handler(int instance); |
| 27 |
-int audio_handler(void *ctx, Uint8 *out_stream, int len); |
|
| 27 |
+void audio_handler(void *ctx, Uint8 *out_stream, int len); |
| ... | ... |
@@ -70,20 +70,7 @@ clamp(int v, int min, int max) |
| 70 | 70 |
static Uint8 |
| 71 | 71 |
audio_dei(int instance, Uint8 *d, Uint8 port) |
| 72 | 72 |
{
|
| 73 |
- /* |
|
| 74 |
- // Uint8 *addr; |
|
| 75 |
- // Uint16 vu; |
|
| 76 |
- // if(!audio_id) return d[port]; |
|
| 77 |
- // switch(port) {
|
|
| 78 |
- // case 0x4: return audio_get_vu(instance); |
|
| 79 |
- // case 0x2: |
|
| 80 |
- // addr = d + 2; |
|
| 81 |
- // vu = audio_get_position(instance); |
|
| 82 |
- // POKE2(addr, vu); |
|
| 83 |
- // default: return d[port]; |
|
| 84 |
- // } |
|
| 85 |
- */ |
|
| 86 |
- // TODO: get envelope |
|
| 73 |
+ /* TODO: get envelope */ |
|
| 87 | 74 |
switch(port) {
|
| 88 | 75 |
case 0x0: |
| 89 | 76 |
case 0x2: |
| ... | ... |
@@ -386,11 +373,6 @@ handle_events(Uxn *u) |
| 386 | 373 |
emu_restart(u, event.drop.file, 0); |
| 387 | 374 |
SDL_free(event.drop.file); |
| 388 | 375 |
} |
| 389 |
- /* Audio */ |
|
| 390 |
- else if(event.type >= audio0_event && event.type < audio0_event + POLYPHONY) {
|
|
| 391 |
- // Uint8 *addr = &u->dev[0x30 + 0x10 * (event.type - audio0_event)]; |
|
| 392 |
- // uxn_eval(u, PEEK2(addr)); |
|
| 393 |
- } |
|
| 394 | 376 |
/* Mouse */ |
| 395 | 377 |
else if(event.type == SDL_MOUSEMOTION) |
| 396 | 378 |
mouse_pos(u, &u->dev[0x90], clamp(event.motion.x - PAD, 0, uxn_screen.width - 1), clamp(event.motion.y - PAD, 0, uxn_screen.height - 1)); |
| ... | ... |
@@ -543,9 +525,9 @@ main(int argc, char **argv) |
| 543 | 525 |
{
|
| 544 | 526 |
Uint8 dev[0x100] = {0};
|
| 545 | 527 |
Uxn u = {0};
|
| 546 |
- u.dev = &dev; |
|
| 547 | 528 |
Uxn u_audio = {0};
|
| 548 |
- u_audio.dev = &dev; |
|
| 529 |
+ u.dev = (Uint8 *)&dev; |
|
| 530 |
+ u_audio.dev = (Uint8 *)&dev; |
|
| 549 | 531 |
int i = 1; |
| 550 | 532 |
if(i == argc) |
| 551 | 533 |
return system_error("usage", "uxnemu [-v] | uxnemu [-f | -2x | -3x | --] file.rom [args...]");
|