iPhone Dev: short sound and vibration at the same time - iphone

is there any way to play a short sound and let the phone vibrate at the same time?
I found something about AudioQueing, but I'm a newbie and cant wrap my head around that whole process of AudioQueing.
Kind regards from Germany

Yes. What part do you have problems with? Playing sounds, vibrating, or doing both at once? For playing short sounds you can use the AVAudioPlayer class. The vibration is triggered by the following code:
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
Described here, for example.

Related

Play custom sound while vibration on iPhone

In my iPhone application I need to play custom sound while vibration.
I have found here: http://gregheo.com/blog/simple-audio/ that I should use AVAudioPlayer. But how can I play system sound of vibration using AVAudioPlayer? If there is another way to play custom sound and vibration together?
Update
I have found that I can use AVAudioPlayer to play custom sound and Audiosession to play vibro system sound. But maybe someone can advise me a better solution?
This SO post seems to deal with the exact opposite of your issue so it might give you the answer you are looking for:
How to play system sound on iOS without vibration?

Play just a part of the sound (both in and out) with OpenAL (iOS)?

I have a recording that has some unuseful voices at the beginning, and at the end.
How can I play just the middle part of the sound?
I have AL_SEC_OFFSET, that is suitable for the entry point, I already use it, but what about the endpoint?
Is there any smart OpenAL settings for this? Hopeso.
Thanks.
There could be a workaround that fires a timer that stops playing before end.
Any simplier?
OpenAL doesn't have built-in support for stopping playback at a specific sample point. A timer is your best bet in this case, even though it will be somewhat inaccurate.
If you want sample-perfect stopping, you could just load the middle part of the audio file into an ALBuffer rather than the entire thing. I have some code which does that here:
https://github.com/kstenerud/ObjectAL-for-iPhone/blob/master/ObjectAL/ObjectAL/Support/OALAudioFile.m#L188

AudioServices (Easy), AVAudioPlayer (Medium), OpenAL (Hard & Overkill?)

I need to play sounds (~5 seconds each) throughout my iphone application. When they're triggered, they need to play immediately.
For the moment I'm using AudioServices and (as you probably know) the first time you play a sound it lags, then every time there after it's perfect. Is there some code available that's clever enough to preload an AudioServices sound (by playing it silently maybe?). I've read adjusting the system volume programmatically will get your app rejected, so that's not an option. Seems AudioServices isn't made for volume correction from what I can see.
I've looked into OpenAL and while feasible seems a little over kill. AVAudioPlayer seems like a little bit of a better option, I'm using that for background music at present. Extending my music player to handle a 'sound board' might be my last resort.
On the topic of OpenAL, does anyone know of a place with a decent (app store friendly) OpenAL wrapper for the iPhone?
Thanks in advance
Finch could be perfect for you. It’s a tiny wrapper around OpenAL with very low latency and simple API. See also all SO questions tagged ‘Finch’.
If you use an AVAudioPlayer, you can call prepareToPlay when you initialize the object to reduce the delay between calling play and having the audio start.

OpenAL doesn't work when using AVAudioRecorder and AVAudioPlayer

i have been troubled about audio problem for several days. i don't think OpenAL get along with AVAudio functions.
i have my own OpenAL class. ( wrapped the MyOpenAL class )
my app start to record using AVAudioRecorder. i stop recording. and then i clicked the "OpenAL Play"button that play any sound using OpenAL.
i can't hear it.
but i can hear my recording when i clicked the "AVAudioPlayer Play" button using AVAudioPlayer.
i tested oalTouch,avTouch,SpeakHear sample code.
they resulted same.
in oalTouch, when AVAudioPlayer stop, OpenAL stop playing simultaneously. this is why i think so.
Does OpenAL have the problem using AVAudio~ Functions together?
I was googling for a long time. but i couln't find out the solutions and the same problems issue.
thanks for reading mine.
I'm using AVAudioRecorder (to record) and OpenAL (to playback) and they both go quite well. Just wanted to check if you use Play_And_Record as option when you initialize your AVAudioRecorder?

What do you use to play sound in iPhone games?

I have a performance-intensive iPhone game I would like to add sounds to. There seem to be about three main choices: (1) AVAudioPlayer, (2) Audio Queues and (3) OpenAL. I’d hate to write pages of low-level code just to play a sample, so that I would like to use AVAudioPlayer. The problem is that it seems to kill the performace – I’ve done a simple measuring using CFAbsoluteTimeGetCurrent and the play message seems to take somewhere from 9 to 30 ms to finish. That’s quite miserable, considering that 25 ms == 40 fps.
Of course there is the prepareToPlay method that should speed things up. That’s why I wrote a simple class that keeps several AVAudioPlayers at its disposal, prepares them beforehand and then plays the sample using the prepared player. No cigar, still it takes the ~20 ms I mentioned above.
Such performance is unusable for games, so what do you use to play sounds with a decent performance on iPhone? Am I doing something wrong with the AVAudioPlayer? Do you play sounds with Audio Queues? (I’ve written something akin to AVAudioPlayer before 2.2 came out and I would love to spare that experience.) Do you use OpenAL? If yes, is there a simple way to play sounds with OpenAL, or do you have to write pages of code?
Update: Yes, playing sounds with OpenAL is fairly simple.
AVAudioPlayer is very marginal for game audio. Tackling AudioQueue or OpenAL by adapting one of the examples is definitely the way to go. latency is much more controllable that way.
If you're calling play on the main thread, try running it on a separate thread. What I ended up doing is:
#include <dispatch/dispatch.h>
dispatch_queue_t playQueue = dispatch_queue_create("com.example.playqueue", NULL);
AVAudioPlayer* player = ...
dispatch_async(playQueue, ^{
[player play];
});
which fixed the worst of the framerate stuttering I was experiencing.
I use OpenAL and the classes that came with the CrashLanding sample code. It's worked fine so far to play samples and play looped music all at the same time. I'm currently learning how to release the memory I've allocated for a sound (.wav file) when, for example, I want to play some intro music just once.
Use CocosDenshion – it’s free, easy, and works. It wraps AVAudioPlayer for background tracks and OpenAL for sounds.
Do you want to check the buffering with the implementation you're using? It might be somehow related to the 20ms delay you're experiencing. i.e., try to play around with the buffer size.