I am trying to implement a simple recorder synced with a background track using AudioKit 5.
Unfortunately I faces latency issue when playing back the recorded file, along with the background track.
The latency values returned by the AVAudioSession.sharedInstance() are around 0,01 sec for input and output, when running on the simulator of my macbook pro.
However, the latency measured between the background track and the recorded one is around 1.4 sec.
Do you have any idea of what could cause this huge latency ?
And how to compute it with accuracy, so I can start the recorder late to compensate it ?
Related
I am working on an iOS app where audio recording and playback should happen simultaneously but at different sampling rates.
Recording will be done through a connected USB Audio device, and playback is done through the inbuilt speaker. I am using AudioUnits for both recording and playback.
AVAudioSession category is set to AVAudioSessionCategoryPlayAndRecord.
Problem is that, recording sample rate should be 96kHz whereas playback sample rate should be 8kHz and, both should run simultaneously.
Currently, whenever I use AVAudioSessionCategoryPlayAndRecord and setPreferredSampleRate to 96kHz, ultimately sampleRate property of AVAudioSession remains at 48kHz and I am loosing half of the samples while recording.
If I use AVAudioSessionCategoryRecord recording happens just fine. But I can't run the audio playback simultaneously with this category. I even tried AVAudioSessionCategoryMultiRoute with no luck, here sampleRate remains at 44.1kHz
So, my question is in iOS how to use different sample rates for recording and playback and, still run them simultaneously? Any advice or references are greatly appreciated.
Please let me know if any other details are required.
I ended up using AVAudioSessionCategoryPlayAndRecord category.
Preferred sample rate is set to 48kHz.
To achieve higher sampling rate for recording, I am using setPreferredInputNumberOfChannels. By increasing number of input channels(which affects only recording) you can have different sampling rate for recording.
In case the recording sampling rate is not a multiple of playback sample rate, we may need to add some interleaving/padding to input samples(Assuming you have control over how data is formatted by the USB device)
I'm having trouble with my application where I'm looking to record audio for roughly ten hours at a time. I'm not looking to save a ten hour clip, but rather listen out for short loud noises over that ten hour period and save only them.
Currently I have made a prototype using the AVFoundation framework which records audio in the background, plays it back and monitors the noise levels to check how loud the current audio is. I had an idea of how to get around my problem where I could monitor the noise levels and only save the recording if it exceeds these noise levels. Therefore only recording short second clips and saving on space.
However in order to check the noise levels the audio recorder must be recording all the time and so will currently record that full audio clip.
Could anyone offer me some guidance on the matter please?
There is a talking cat app well known for iOS devices, in which you speak your voice and he repeats. Analyzing this app, you'll see that it stops talking when you stop talking, that is, it stops to capture the audio when not receive another voice.
I was giving a analyzing the methods of AVAudioRecorder class, and not found any method in which to capture when the User stop to talking or recorder stops to receive external audio.
How can I capture when the audio recorder stops to receiving audio.
Process the audio stream as it is coming through. You can look at the frequency and volume of the stream. From there you can determine if the user has stopped talking.
I suggest frequency and volume as the recorder still picks up background audio. If the volume drops dramatically then the sounds the recorder is picking up must be further away from the device than before. The frequency can also lend itself to:
A.) Filter out the background audio in the audio used to replay the audio with a pitch change or any other changes. etc.
B.) I do not know the limits of frequency for the average human. But this covers the use case where the user has stopped talking, but have moved the device in such a way that the recorder still picks up load shuffling from moving fingers near the mic.
I am trying do slow motion for my video file along with audio. In my case, I have to do Ramped Slow motion(Gradually slowing down and speeding up
like parabola not a "Linear Slow Motion".
Ref:Linear slow motion :
Ref : Ramped Slow Motion :
What have i done so far:
Used AVFoundation for first three bullets
From video files, separated audio and video.
Did slow motion for video using AVFoundation api (scaletimeRange).Its really working fine.
The same is not working for audio. Seems there's a bug in apple api itself (Bug ID : 14616144). The relevant question is scaleTimeRange has no effect on audio type AVMutableCompositionTrack
So i switched to Dirac. later found there is a limitation with Dirac's open source edition that it doesn't support Dynamic Time Stretching.
Finally trying to do with OpenAL.
I've taken a sample OpenAL program from Apple developer forum and executed it.
Here are my questions:
Can i store/save the processed audio in OpenAl?if its directly not possible with "OpenAl", can it be done with AVFoundation + OpenAL?
Very importantly, how to do slow motion or stretch the time scale with OpenAL? If i know time stretching, i can apply logic for Ramp Slow Motion.
Is there any other way?
I can't really speak to 1 or 2, but time scaling audio can be as easy as resampling. If you have RAW/PCM audio sampled at 48 kHz and want to playback at half speed, resample to 96 kHz and play the audio at 48 kHz. Since you have twice the number of samples it will take twice as long to play. Generally:
scaledSampleRate = (orignalSampleRate / playRate);
or
playRate = (originalSampleRate / scaledSampleRate);
This will effect the pitch of the track, however that may be the desired effect since that behavior is somewhat is expected in "slow motion" audio. There are more advanced techniques that preserve pitch while scaling time. The open source software Audacity implements these algorithms. You could find inspiration there. There are many resources on the web that explain the tradeoffs of pitch shifting vs time stretching.
http://en.wikipedia.org/wiki/Audio_time-scale/pitch_modification
http://www.dspdimension.com/admin/time-pitch-overview/
Another option you may not have considered is muting the audio during slow motion. That seems to be the technique employed by most AV playback utilities. However, depending on your use case, distorted audio does indicate time is being manipulated.
I have applied slow motion on complete video including audio this might help You check this link : How to do Slow Motion video in IOS
I am creating an iphone application that use audio.
I want to play a beep sound that loop indefinitely.
I found an easy way to do that using the upper layer AVAudioPlayer and the numberOfLoops set to "-1". It works fine.
But now I want to play this audio and be able to change the rate / speed. It may works like the sound played by a car when approaching an obstacle. At the beginning the beep has a low frequency and this frequency accelerate till reaching a continuous sound biiiiiiiiiiiip ...
It seems this is not feasible using the high layer AVAudioPlayer, but even looking at AudioToolBox I found no solution.
Any help?
Take a look at Dave Dribin's A440 sample application, which plays a constant 440 Hz tone on the iPhone / iPad. It uses the lower-level Audio Queue Services, but it does what you're asking (short of the realtime tone adjustment, which would just require a tweak of the existing code).