How to loop an mp3 without gaps in monotouch? - iphone

I am wishing to seamlessly loop mp3's for an app written in MonoTouch using the AVAudioPlayer and cannot find any examples on how to achieve this. I have found a great library at http://gamua.com/blog/2012/05/gapless-mp3-audio-on-ios/ however it is written for objective c.
I wish for the audio to continue to play even when the device is locked and have played around with the AudioSession initilizer but failed to have this working also.
I am not able to find examples or libraries to assist in achieving results.

For queuing up songs without any spaces in between, make sure to use AVQueuePlayer, it allows you to pre-load songs. If you just want to loop the same song, just set NumberOfLoops to 0 on AVAudioPlayer and it will loop forever.
For playing audio in the background, you also need to declare UIBackgroundModes in your Info.plist. See this guy's article here. He's using Obj-C, but you should be able to port his code to MonoTouch.

Related

iOS Mixing audio, Audio Toolbox vs Audio Units

I've been searching for a while and can't come to a good conclusion.
I am trying to create an app that can "record" beats that a user makes on a 4x4 button array. Each button has a sound tied to it and after they hit record, I want to mix the audio that gets played and save it to a file so they can listen to it and play over it later.
What makes this even trickier is that there will be a metronome playing and I do not want to mix the metronome sound into the audio that is getting saved.
From what I have found, the only way to go is Audio Units for these features, but I am reluctant to since it seems a little overkill and somewhat complicated to learn. Can Audio Toolbox make this any easier?
Thanks!
In generally, using a AudioToolBox easily implements.
more information, see below sample code. it's a lot of help.
MixerHost

How to play record the sound programmatically and how to play that recorded audio?

I am developing one application. In that I want to record the sounds and I want to play that recorded sound file. I know the frameworks for doing this. But how to develop programmatically by using that frameworks?
You can refer to this link:
I have implemented this code in one of my apps and it works completely fine.
How do I record audio on iPhone with AVAudioRecorder?
For Playing the sound you have option to use AVAudioRecorder.
Hope this helps.
The best way to do it - and I am talking from painful experience here - is with the RemoteIO audio unit. You can also do it with AudioQueue, but it has a higher latency, and the queue type approach becomes very problematic.
So, I think that they are really different tools for different jobs. Note that you won't play a sound file as such. You will play the contents of a buffer held in memory. As long as the buffer is not too large, this should not be an issue.
So, going with RemoteIO, you will find this blog and tutorial very useful. It includes code samples.
Using RemoteIO audio unit By MICHAEL TYSON

Recording sounds created within an iPhone app

I'm new to programming in Objective-c and the iPhone but I am working on an app to teach myself. I have been trying to figure out how to record sounds on the iPhone. Apple provides excellent documentation for recording from the microphone with AVAudioRecorder but I want to record sounds made by my app, or even just record sounds when buttons are pressed (button is pressed, certain audio gets recorded).
I have no clue how to do this and can't seem to find anything that would help me along this path, only microphone stuff.
Can anyone share ideas or code that would make this possible?
Thanks
Once you move beyond the convenience classes like AVAudioRecorder, you've got a lot of studying to do.
I would start with:
Getting Started with Audio and Video
Multimedia Programming Guide:Audio
Core Audio Overview
Audio programming is a very large and complex subject. If you want to customize, be prepared to spend some time learning it.
I've made a sample app that records sounds/audio and has a playback. Hope this helps! https://github.com/casspangell/AudioMic

iphone - any way to manipulate recorded audio?

Specifically, I just want to record something, reverse it, and play it back. I've looked through the apple docs and couldn't find anything about editing audio. Is it possible?
Yes, it is definitely possible. Last I checked the Apple Core Audio docs were not very good, but it has been a few months since I've worked with it. Here are the steps that I would follow.
Record the audio sample.
Reverse the audio by looping through the first half of the array and swapping the value located there with one an equidistant from the end of the array.
Play the resulting audio clip.
Quite frankly, the first step is probably the hardest. Here is a decent article about doing audio on the iPhone including recording. Make sure you look at all of the different parts of the article. Here is another article about recording sound on the iPhone, but using a different framework. There are really several ways to go about recording on the iPhone though, last I checked, if you want to play audio while you are recording you have to use RemoteIO.
Edit:
If you would like to use RemoteIO(which I preferred), then this site is pretty helpful for getting started with it. Also, the aurioTouch sample program that Apple provides is immensely helpful (though more than you want).
If you don't need RemoteIO (because it can be a major pain though it is more low-level and thus more flexible), then try the SpeakHere sample program. It is made just to record and play back. However, I just looked at it and it writes the recording to a file rather than a buffer which isn't what you want. I would recommend going with RemoteIO for that reason (unless you can find a way to have it write to a buffer instead).

play two sounds simultaneously iphone sdk

I am trying to make a small music app on the iphone. I want to have an octave a piano which will respond to touches and play the key or keys that the user touches. How would i be able to get two or more sounds to play at the same time so it sounds like a chord? I tried using AVFoundation but the two sounds just play one after the other.
You would have to use AudioQueueServices. The docs are here:
Apple.com - AudioQueueServices Reference
Essentially you would have to write some code to open up multiple outputs, and then prime the queue and have them block before AudioQueueStart(AudioQueueRef aq) until everything was primed and ready and then let them go.
AVAudioPlayer isn't really good enough for this sort of thing, unfortunately.
If you create multiple AVAudioPlayers you can play them at the same time, and they will mix per the restrictions outlined in the documentation (not all file types can be played simultaneously).
If you allocate them first, then play them in order, they will play at virtually the same time.
If you need absolutely perfect timing, use the AudioQueue as described above or use OpenAL.