Programmatically playing MIDI with OpenAL and SF2
I can create a basic MIDI file from scratch verified using TiMidity++, and I know enough OpenAL to play a streamed source from a file.
I'm just wondering if it's possible to create a program in C to play MIDI files by reading in a SF2 and MIDI file and using OpenAL to play the sound. Do I need to use another library? I want to know beforehand because the SF2 format looks pre开发者_StackOverflowtty complicated.
Core audio is where it's at!
If you are doing this on a mac, DLSMusicDevice
does what you want.
if you are on iOS, you will need to do much 'by hand' but it is manageable (tedious, as well). If you go this route, look at the sample code 'mixer host'.
You need to use an CoreAudio. Create an AUGraph with a Sampler connected to an IOUnit. Look at header files AUComponent.h in the AudioUnit framework. Once you've got your audio graph setup you can play a note using the following function:
MusicDeviceMIDIEvent(sampler, status, note, velocity, 0);
精彩评论