How to play MID file in iphone? - iphone

Is it possible to play MIDI files on iOS?
This would be the MIDI format file I was trying to play back.
Which framework / library could be used to play MIDI files on iOS?

Short answer : use the CoreMIDI framework to read the file, and the Core Audio framework to make sound (you'll also need to add the AudioToolbox framework).
Here's a tutorial on the subject
Basically, you can use the MusicPlayer object found in the AudioToolbox framework to read your file, then use the MusicPlayer to play notes on an AUSampler Audio Unit.

Related

iPhone applications internal audio recording

I want to record audio that is played by my application in a file. does somebody have any idea to do that? it is also achieved in talking tomcat application.
There are two ways to record and play an audio file on an iPhone:
You could use the standard Core Audio Framework which is provided in Objective-C and C Code.
Or what probably would be easier is using the only in IOS available AVAudio* Classes.
Have a look at the AVAudioRecorder class. Its pretty simple to use and if you google for this class name you will find plenty of example code:
API - AVAudioRecorder

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 pretty 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);

audio frameworks in iPhone

I would like to know the follwing information about iPhone audio system
Heirarchy of the audio framework in iPhone OS.
i know that there are 3 main audio frameworks in iPhone OS.i.e
AVFoundation Framework
CoreAudio Framework
OpenAL Framework
what are the audio formats supported in each of the above framework?I mean will all the framework support all audio formats or are they dependent about the audio formats it support?
Thank You
For AVFoundation,CoreAudio pls check this link -- LINK
And for OpenAL this link might help you -- Link

Play midi file on the iPhone

Is it possible to play .mid files directly via some API, or one have to convert the midi file to e.g. AAC first?
(2 years later…) You can use MusicPlayer and MusicSequence APIs. Available in iOS 5.
There is no Apple API for this. You could write your own, which i think would depend on what you are hoping it is going sound like.
There is lots of available source code for reading midi files and there are a few open source synths for the iphone - or you could use openAl for triggering samples. It probably isn't going to sound like Garageband tho.
If you want it to sound as good as possible you will have to convert it first.

What's the difference between the Apple audio frameworks?

In the documentation I see several Apple frameworks for audio. All of them seem to be targeted at playing and recording audio. So I wonder what the big differences are between these?
Audio Toolbox
Audio Unit
AV Foundation
Core Audio
Did I miss a guide that gives a good overview of all these?
I made a brief graphical overview of Core Audio and its (containing) frameworks:
The framework closest to the hardware is Audio Unit. Based on that there is OpenAL and AudioToolbox with AudioQueue. On top, you can find the Media Player and AVFoundation (Audio & Video) frameworks.
Now it depends on what you want to do: just a small recording, use AVFoundation, which is the easiest one to use. (Media Player has no options for recording, it is - as the name says - just a media player.)
Do you want to do serious real-time signal processing? Use Audio Unit. But believe me, this is the hardest way. :-)
With iOS 8.0 Apple introduced AVAudioEngine, an Objective-C/Swift based audio graph system in AV Foundation. This encapsulates some dirty C-stuff from Audio Units. Due to the complexity of Audio Unit it is maybe worth a look.
Further readings in the Apple Documentation:
Core Audio Overview: Introduction
Multimedia Programming Guide
Audio & Video Starting Point
Core Audio is the lowest-level of all the frameworks and also the oldest.
Audio Toolbox is just above Core Audio and provides many different APIs that make it easier to deal with sound but still gives you a lot of control. There's ExtAudioFile, AudioConverter, and several other useful APIs.
Audio Unit is a framework for working with audio processing chains for both sampled audio data and MIDI. It's where the mixer and the various filters and effects such as reverb live.
AV Foundation is a new and fairly high-level API for recording and playing audio on the iPhone OS. All of them are available on both OS X and iOS, though AV Foundation requires OS X 10.8+.
Core Audio is not actually a framework, but an infrastructure that contains many different frameworks. Any audio that comes out of you iOS speaker is, in fact, managed by Core Audio.
The lowest-level in Core Audio that you can get is by using Audio Units, which you can work with by using the AudioToolbox and the AudioUnit frameworks.
The AudioToolbox framework also provides a bit higher level abstractions to deal with playing/recording of audio using AudioQueues, or managing various audio formats by using various Converter and File Services.
Finally, AV Foundation provides high level access to playing one specific file, and MediaPlayer gives you access (and playback) to your iPod library.
This site has a short and excellent overview of core features the different API's:
http://cocoawithlove.com/2011/03/history-of-ios-media-apis-iphone-os-20.html
Here you can find an overview of all iOS and OSX audio frameworks:
https://developer.apple.com/library/ios/documentation/MusicAudio/Conceptual/CoreAudioOverview/WhatsinCoreAudio/WhatsinCoreAudio.html#//apple_ref/doc/uid/TP40003577-CH4-SW4