Rev | Line | |
---|
[169] | 1 | //midi.c: |
---|
| 2 | |
---|
| 3 | #include "roard.h" |
---|
| 4 | |
---|
[185] | 5 | int midi_init (void) { |
---|
| 6 | int i; |
---|
| 7 | char * files[] = { |
---|
| 8 | "/dev/console", |
---|
| 9 | #ifdef __linux__ |
---|
| 10 | "/dev/tty0", |
---|
| 11 | "/dev/vc/0", |
---|
| 12 | #endif |
---|
| 13 | NULL |
---|
| 14 | }; |
---|
| 15 | |
---|
| 16 | g_console = -1; |
---|
[191] | 17 | g_midi_cb_stoptime = 0; |
---|
[185] | 18 | |
---|
| 19 | for (i = 0; files[i] != NULL; i++) { |
---|
| 20 | if ( (g_console = open(files[i], O_WRONLY|O_NOCTTY, 0)) != -1 ) |
---|
| 21 | break; |
---|
| 22 | } |
---|
| 23 | |
---|
[187] | 24 | if ( g_console != -1 ) { |
---|
| 25 | return 0; |
---|
| 26 | } else { |
---|
| 27 | return -1; |
---|
| 28 | } |
---|
[185] | 29 | } |
---|
| 30 | |
---|
| 31 | int midi_free (void) { |
---|
| 32 | if ( g_console != -1 ) |
---|
| 33 | close(g_console); |
---|
| 34 | return 0; |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | int midi_cb_play(float t, float freq, int override) { |
---|
[191] | 38 | float samples_per_sec /* S/s */ = g_sa->rate * g_sa->channels; |
---|
| 39 | |
---|
[189] | 40 | /* |
---|
| 41 | #define MIDI_CB_NOOVERRIDE 0 |
---|
| 42 | #define MIDI_CB_OVERRIDE 1 |
---|
| 43 | */ |
---|
[191] | 44 | if ( g_midi_cb_stoptime && override != MIDI_CB_OVERRIDE ) |
---|
| 45 | return -1; |
---|
| 46 | |
---|
| 47 | g_midi_cb_stoptime = ROAR_MATH_OVERFLOW_ADD(g_pos, samples_per_sec*t); |
---|
| 48 | midi_cb_start(freq); |
---|
| 49 | |
---|
| 50 | return 0; |
---|
[185] | 51 | } |
---|
| 52 | |
---|
[190] | 53 | int midi_cb_update (void) { |
---|
| 54 | if ( g_midi_cb_stoptime <= g_pos ) |
---|
[189] | 55 | midi_cb_stop(); |
---|
| 56 | |
---|
| 57 | return 0; |
---|
| 58 | } |
---|
| 59 | |
---|
[185] | 60 | int midi_cb_start(float freq) { |
---|
| 61 | // On linux this uses ioctl KIOCSOUND |
---|
[188] | 62 | #ifdef __linux__ |
---|
| 63 | if ( g_console == -1 ) |
---|
| 64 | return -1; |
---|
| 65 | |
---|
| 66 | if ( ioctl(g_console, KIOCSOUND, (int)(1193180.0/freq)) == -1 ) |
---|
| 67 | return -1; |
---|
| 68 | |
---|
| 69 | return 0; |
---|
| 70 | #else |
---|
[185] | 71 | return -1; |
---|
[188] | 72 | #endif |
---|
[185] | 73 | } |
---|
| 74 | |
---|
| 75 | int midi_cb_stop (void) { |
---|
| 76 | #ifdef __linux__ |
---|
| 77 | return midi_cb_start(0); |
---|
| 78 | #else |
---|
| 79 | return -1; |
---|
| 80 | #endif |
---|
| 81 | } |
---|
| 82 | |
---|
[169] | 83 | //ll |
---|
Note: See
TracBrowser
for help on using the repository browser.