how to use simpleaudioengine to play audio in a specified duration - iphone

i want to use SimpleAudioEngine to play a 2s mp3, but not so simple. I want to this audio plays 4s, that it, this mp3's duration should be 4s. Any good idea can solve this problem, Thank u very much

Edit the file to be 4 seconds using audacity audio editor. You can extend the file without changing the pitch of the audio. Then export the file as a separate mp3 file. Then just pay the file normally.

Related

Make unity play high frequency audio exact like the original wav file for hearing test

I am making a unity hearing test, I already manage to do all the code to play the audios, the problem is that unity is changing the way the files are played, for eg one of the files is 18000 Hz, when I open the file and play out of unity it is imposible to me hear anything, but if I play in unity I can hear it very clearly, what can be messing with the audio?
I am keeping the original audio sample rate and my audio sourcer is with default settings, here is the code to play the audio:
void PlayAudio(AudioClip auc) {
aus.PlayOneShot(auc, 1);
}`
here is the audio source:
as you can see normal settings
Thanks for hearing me
I faced a similar problem and used this script for simple sinewave generation
For audio files I chose FMOD

How to record mic input and an audio track on iPhone at the same time

I am looking to record and save a music/song file with one or more audio track(s) let's say a max of two tracks playing simultaneously while recording my vocals via the headset or the microphone. The finished product will be a single song file(mp3 or other format).
Also, the code should have the ability to filter out outside noise/interferance and add basic effects.
Appreciate any and all Xcode help!
I have done same thing using AVAudioSessionCategoryPlayAndRecord.
in my code, played karaoke file in MPMoviePlayer and at same time takes input from mic.
output is audio from MPMoviePlayer and it will be used as input also + input from mic.
i started to save this input in caf file, and upon finish product should be single file.

Trying to play an audio file

I'm trying to play an audio file in a cocos2d application. Here is the line which tries to play the sound:
[[SimpleAudioEngine sharedEngine] playEffect:#"pig_squeal.wav"];
If I put a log near this line, the log appears, and I can play the sound with iTunes. But when the sound should be played, there is a message displayed:
AudioStreamBasicDescription: 2 ch, 44100 Hz, 'lpcm' (0x00000C2C) 8.24-bit little-endian signed integer, deinterleaved
What's the problem?
This was discussed in comments but I've amalgamated all the possibilities of why it may not work here.:
That's not an error message, just some information.
Is the sound definitely in your library and a part of the target?
You haven't changed the volume of the SimpleAudioEngine or the volume of your device isn't all the way down?
Click the sound in your library. Press Option+Command+1 to bring up the file editor. Scroll down to "Target Membership" and ensure the sound is checked for your target.
Try a different sound effect too? Try and narrow the problem down to "is it SimpleAudioEngine".
Also try and playBackgroundMusic for a sound (This was the solution in this case)
And try an mp3
There isn't a problem. It's a status message written to the log when you initialise the current OpenAL context using alcMakeContextCurrent. As far as I'm aware, you can't get rid of the message.
There is no problems with your code for the Playing of the Sound. Please check the Sound file has been added to the project also do check the format of the sound. It should play the Sound whenever you call the Play Effect. Please also try to PRELOAD the sound effect in the init method.
that message means the song was read correctly and should be playing. possible reasons you don't hear it?
volume turned down.
device malfunctioning
audio has silence in it
audio file is large and will take a long time to load.
sound has been redirect to come out of the headphones or the ear piece (even if not attached)
But the sound is loading and most likely playing.
If you are getting a crash while running in device from xcode pls try this(worked for me). Dissconnect the device from Xcode and run the app in the device. I dont know why it worked like that. But when I did this there was no crash.

How to play sound on "Ringer & Alert Volume" level

In my app I want to have an alarm/notification on "Ringer & Alert Volume" level.
In other words on the volume level which phone rings or alarms are used on (Preferences/Sound/Ringer and Alerts). It is different from the system volume level which changes with the volume buttons.
It should also play more than 30 sec.
I know it's possible because some clock apps can do that.
UPDATE:
OK I found an unideal solution. If use AudioServicesCreateSystemSoundID and load my own sound file (aif, wav, etc no mp3 or other compressed audio) than it works.
The only problem is that it has to be 30 sec or shorter, but I can can cut it into 30sec pieces and play them piece by piece.
It does not work when on silent switch on which is a problem for me.
Code:
SystemSoundID mySound;
AudioServicesCreateSystemSoundID(CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("mySound"), CFSTR("aif"), NULL), &mySound);
AudioServicesPlaySystemSound(mySound);
I suspect that OpenAL should do that. Does anyone has a simple example which loads a aif/wav file and plays it on iPhone. I found some complicated examples, but all I need is just play and stop a sound (even if it's leaking that's fine).
I found it out myself. I have to use AudioServicesCreateSystemSoundID and load my own sound file (aif, wav, etc no mp3 or other compressed audio)
The only problem is that it has to be 30 sec or shorter, but I can can cut it into 30sec pieces and play them piece by piece.
It does not work when on silent switch on
Code:
SystemSoundID mySound;
AudioServicesCreateSystemSoundID(CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("mySound"), CFSTR("aif"), NULL), &mySound);
AudioServicesPlaySystemSound(mySound);
You should look into AVAudioPlayer class. It will allow you to play sound files of any duration and you can control the volume output for the specified files you wish to play. I'm not in front of my mac otherwise I would provide code. Let me know if you need further instruction.

Play audio and video at a same time in iPhone application

Is it possible to play audio and video file at a same time? I want to play different audio file and video file at a same time and also want control for both, so is it possible?
Sorry, not that I know of. The movie view automatically stops all audio files and takes up the whole screen, so you are forced to listen to the audio for the video.
If the audio is part of the video file, yes.
If it's an MP3 file or some other external type how are you planning on playing it? The phone might allow this to happen depending on what you're up too.
You might be in luck soon though...
Another helpful link is here.