Mac Audio framework - iphone

I know that AVFoundation framework works on iPhone.
Does the same framework be used for Mac as well to play and record sounds???
Basically I want to write an application to play 2 music files parallelly and record the music that is being played. Is it possible???

No, AVFoundation is for the iPhone only.
What does work cross platform (iPhone, OS X) is the Audio Queue framework. It is more difficult to use but there are plenty of examples available. It is also more low level so it will allow you to do stuff like playing and recording.

Related

Using MediaPlayer and AVFoundation Framework simultaniously in XCode

I'm an inexperienced XCode use and programmer in general so keep that in mind. I'm trying to use the microphone on the iPhone while at the same time allowing the user to play audio while using the "iPod music picker", but when the user selects music and plays it the recorder stops working? I have no idea what is going on here? Also, on a side note, how do you implement forward and back iPod buttons?
Thanks so much!
Sounds like this is an Audio Session issue - you're probably in a mode where you can either play or record, but not both at the same time.
Check out the Audio Session Programming Guide which should explain how to configure your session.
AVAudioSessionCategoryPlayAndRecord — Use this category for an application that inputs and outputs audio. The input and output need not occur simultaneously, but can if needed. This is the category to use for audio chat applications.
AVAudioSessionCategoryAmbient - This category allows audio from the iPod, Safari, and other built-in applications to play while your application is playing audio. You could, for example, use this category for an application that provides a virtual musical instrument that a user plays along to iPod audio.

Can I record videos on iPhone 3G using AVFoundation?

Is it possible to record video on iphone 3g with ios 4.1 using AVFoundation?
I m able to record audio and can pick still image using AVFoundation but not able to record video.
If you see the AVFoundation reference documentation its stated that
You should typically use the
highest-level abstraction available
that allows you to perform the tasks
you want. For example:
If you simply want to play movies, you can use the Media Player
Framework (MPMoviePlayerController or
MPMoviePlayerViewController), or for
web-based media you could use a
UIWebView object.
To record video when you need only minimal control over format, use the
UIKit framework
(UIImagePickerController).
As long as a device has a camera, you should be able to record using AVFoundation, check out the AVCam demo code from WWDC 2010 to see how you can do that.

What is the Mac equivalent of AVAudioPlayer?

I am porting an iPhone app to Mac. On iPhone I use AVAudioPlayer for playing sounds, but it doesn't exist on Mac. What would be the Mac equivalent for playing audio (hopefully as simple as AVAudioPlayer so I can port my app easily)?
Additionally, are there any open source libraries / samples / wrappers available for playing music and sound files on Mac?
As of OS X 10.7, AVAudioPlayer is available on the Mac and Apple recommends using this wherever possible.
Depending on what capabilities you need, Core Audio might be unnecessarily complex. The obvious simple way is NSSound. It's also possible to use a hidden QTMovieView to play sound.
I've written a framework for audio playback, called SFBAudioEngine: http://github.com/sbooth/SFBAudioEngine
It might be a bit more than you're looking for, but it is more capable than NSSound and supports formats (FLAC, Musepack, Ogg Vorbis) that Core Audio doesn't handle natively.
Take a look at Core Audio:
Core Audio is designed to handle all audio needs in Mac OS X. You can use Core Audio to generate, record, mix, edit, process, and play audio.

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

Can iphone mix two sound files or build custom equalizer?

Can iphone mix two sound files or build custom equalizer?
I have studied for weeks about this problem,
and it seems unable to use iphone-sdk to mix two or more sound files or to build custom equalizer.
Is anyone have the experience to do this?
Yes you can. AVAudioPlayer can play multiple sounds and you can control the volume for each. Or you can use Audio Units and have more control over the audio data.
aurioTouch is a good sample app for what you are thinking of.
For simple playback of sound files you can use the AVAudioPlayer class introduced in the 2.2 SDK. It provides playback and volume controls for playing any audio file. As far as I am aware, there are no restrictions on the number of sound files you can play on the iPhone. The only restriction on playing sound files is that you may only play one AAC or MP3 compressed file at a time, the rest of the files must be either uncompressed or in the IMA4 format.
If your needs are more low-level (If you need to do DSP) you might want to look at AudioQueue Services or AudioUnits - two Mac OS X audio processing APIs that are also available on the iPhone.