Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by renezuidhof · Aug 19, 2014 at 08:46 PM · audiosyncmicrophonerecording

Delay with Microphone.Start

Hi!

I have a problem regarding recording audio and playing it back insync with other audio. I am trying stuff for a few days already but i can't figure it out :(

I want to make an app where the user can record his own audio over a playing audioclip (looping). So when he is done, both tracks should be played simultaneously and in sync.

So what i am doing is the following:


 Audio class (pseudocode kinda)
 
  Update(){
     if(AudioSource.timesamples < previousTimesample)        
         if(isRecording){
             StopRecording()
         } else {
             StartRecording()
         }
     }
     previousTimesample = AudioSource.timesamples
  }

-------------------------------

This should start (and stop) a new recording when the current track is starting from its beginning. On the PC this is not a problem and it's pretty much insync, but on mobile devices there is a little difference (which i expected). What i expected was that in the beginning of the recorded audio a few milliseconds would miss. But to my surprise, instead of less there is more! Below is an example of the waveforms. The first waveform is the looping audio, the second one is the recorded audio. The first peak in this example (with the black line in front of it) should be insync, but as you can see it is not! :(

alt text

Summary

With the code, i expect that the peak of the second waveform should be a little bit sooner then the first waveform. But it's the opposite. Does someone know why this happens?

Also, i can image it is not all very clear. Please ask for clarification if you don't get it! :)

untitled2.png (4.1 kB)
Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image renezuidhof · Aug 20, 2014 at 04:24 PM 0
Share

Does anyone have an idea?

avatar image CanisLupus · Aug 21, 2014 at 10:17 AM 0
Share

Does the problem happen even the first time the track starts? Unity's $$anonymous$$icrophone class is a little weird, as it doesn't tell you when it's ready to record. You call $$anonymous$$icrophone.Start(...) but it doesn't start recording right away, and the problem is magnified on mobile platforms. We must actively poll it until the recording position is correct, using while($$anonymous$$icrophone.GetPosition(micName) <= 0); after calling Start. This stops your application until the recording position becomes positive. I realize this is horrible, but it's needed and, as far as I know, Unity does not provide a better way. If you're not already doing this, try it. If it solves your problem I'll convert this comment into an answer. If not, I currently have no other ideas :)

avatar image renezuidhof · Aug 21, 2014 at 01:38 PM 0
Share

This is the behaviour i also expect. But what happens is that it starts recording to soon :o In theory (code wise) i expect it to start a little bit after my Update function calls StartRecording. In that case the peak of the second waveform should be sooner then the first one. But as you can see in the waveform the peak is after the first one.

As a workaround i am now going to try to start recording sooner and then just cut the piece out of it that i want.

avatar image fruitservice · Sep 10, 2014 at 08:52 AM 0
Share

I just ran into exactly the same problem. i guess, it is not about when the recording starts but about latency. the hardware needs some time to encode the recorded voice, so even though the recording is already running, the data comes in a bit later, that is why you seem to have "more" recorded data. in fact, it is just delayed. but i have actually no idea how to find out, what the amount of the latency is. did you find a good solution?

avatar image renezuidhof · Nov 28, 2014 at 02:48 PM 0
Share

@fruitservice: Check my answer on my own post below ;) I have tried weeks to find the latency without any good results. The solution i posted below worked pretty good for me.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by renezuidhof · Aug 24, 2014 at 04:39 PM

In case anyone will bump into this problem. I'm going to make a 'calibrate microphone' function (let my phone make some loud noise). It will save the time between expected audio-input and actual audio-input.

Demo here: https://play.google.com/store/apps/details?id=com.zuidsoft.loopstation2

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image youngexplorer · Jul 15, 2015 at 01:46 AM 0
Share

Can you provide some insight how to $$anonymous$$imize the delay?

avatar image jamesburford · Nov 29, 2015 at 10:08 AM 0
Share

Hi @renezuidhof,

I've been struggling for a couple of days with a similar thing. Can you provide some insight on how you did it?

Thanks

James

avatar image renezuidhof jamesburford · Nov 29, 2015 at 03:24 PM 0
Share

I play an audioclip of 3 seconds with a clicking sound every second. At the time the audioclip starts playing i also start recording with the microphone. Now i analyze the recorded audio to find the peaks of the clicking sounds. Because the first peak should ideally be after exactly one second you can check the actual time of the first peak. So the difference between the expected peak and the actual peak is your delay.

avatar image jamesburford renezuidhof · Nov 29, 2015 at 10:42 PM 0
Share

Ahhh interesting.

Thanks for the answer.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

24 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How can I set audio to play as if it was into the recording device? 1 Answer

Recording audio from another audio source 1 Answer

Guys i need help with audio! 0 Answers

Unity 5 and using a microphone 1 Answer

Voice Recording issue ?? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges