File: midi_player_mem.txt

package info (click to toggle)
fluidsynth 2.4.4%2Bdfsg-1%2Bdeb13u1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,328 kB
  • sloc: ansic: 43,529; cpp: 1,434; xml: 1,020; makefile: 71; sh: 46
file content (64 lines) | stat: -rw-r--r-- 2,089 bytes parent folder | download | duplicates (3)
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
/*!

\page MIDIPlayerMem Playing a MIDI file from memory

FluidSynth can be also play MIDI files directly from a buffer in memory. If
you need to play a file from a stream (such as stdin, a network, or a
high-level file interface), you can load the entire file into a buffer first,
and then use this approach. Use the same technique as above, but rather than
calling fluid_player_add(), load it into memory and call
fluid_player_add_mem() instead. Once you have passed a buffer to
fluid_player_add_mem(), it is copied, so you may use it again or free it
immediately (it is your responsibility to free it if you allocated it).

\code
#include <stdlib.h>
#include <string.h>
#include <fluidsynth.h>

/* An example midi file */
const char MIDIFILE[] = {
    0x4d, 0x54, 0x68, 0x64, 0x00, 0x00, 0x00, 0x06,
    0x00, 0x01, 0x00, 0x01, 0x01, 0xe0, 0x4d, 0x54,
    0x72, 0x6b, 0x00, 0x00, 0x00, 0x20, 0x00, 0x90,
    0x3c, 0x64, 0x87, 0x40, 0x80, 0x3c, 0x7f, 0x00,
    0x90, 0x43, 0x64, 0x87, 0x40, 0x80, 0x43, 0x7f,
    0x00, 0x90, 0x48, 0x64, 0x87, 0x40, 0x80, 0x48,
    0x7f, 0x83, 0x60, 0xff, 0x2f, 0x00
};

int main(int argc, char** argv)
{
    int i;
    void* buffer;
    size_t buffer_len;
    fluid_settings_t* settings;
    fluid_synth_t* synth;
    fluid_player_t* player;
    fluid_audio_driver_t* adriver;
    settings = new_fluid_settings();
    synth = new_fluid_synth(settings);
    player = new_fluid_player(synth);
    adriver = new_fluid_audio_driver(settings, synth);
    /* process command line arguments */
    for (i = 1; i < argc; i++) {
        if (fluid_is_soundfont(argv[i])) {
           fluid_synth_sfload(synth, argv[1], 1);
        }
    }
    /* queue up the in-memory midi file */
    fluid_player_add_mem(player, MIDIFILE, sizeof(MIDIFILE));
    /* play the midi file */
    fluid_player_play(player);
    /* wait for playback termination */
    fluid_player_join(player);
    /* cleanup */
    delete_fluid_audio_driver(adriver);
    delete_fluid_player(player);
    delete_fluid_synth(synth);
    delete_fluid_settings(settings);
    return 0;
}
\endcode

*/