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
3
Question by flexrails · Nov 17, 2009 at 11:59 PM · audiocrossfade

how do i crossfade sound loops in unity?

how do i crossfade sound loops in unity?

Comment
Add comment
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

4 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by Jessy · Nov 18, 2009 at 05:13 AM

There won't be a pop if you did a good job fading, making sure that the wave begins and ends at zero, with a positive or negative slope at both ends. Also, as with making tiling textures, you probably want to "undo your offset" after doing that editing, so the beginning is really the beginning again.

However, I assumed you were talking about real-time crossfading. With Unity 2.6, you can use the Animation Editor to make volume curves! Do keep in mind, though, that Unity uses a linear volume taper, so straight lines will probably sound pretty bad. Check this page out for a general-purpose curve adjustment. You may want to script a property like that instead. However, I bet it will be a lot better for performance if you just use keyframes.

Just keep in mind the curves won't make much visual sense. Use your ears! :-)

Comment
Add comment · 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
2

Answer by Design3.com · Nov 18, 2009 at 04:00 AM

If you're looping one sound over and over, I'd do it manually in a program like Audacity. You can fade out the end and fade in the beginning. If you want a transition without a fade to silence in the middle, you can:

  1. Split the clip in two.
  2. Move the first part so it comes after the second part.
  3. Crossfade between the end of the second part (which is now first) and the beginning of the first part (which is now last).

When Unity loops the clip, the new beginning and end should be seamless and the old beginning and end will be crossfaded nicely. I've only actually tried this method with wrapping textures during UV animation (and not with audio), so it's possible there might be a pop as the clip loops.

Comment
Add comment · Show 1 · 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 flexrails · Nov 18, 2009 at 07:51 AM 0
Share

thanks. i was more thinking of turning down the volume of the one loop while turning up the volume of the other loop AT RUNTI$$anonymous$$$$anonymous$$ so i have the loops prepared upfront. i just want to deter$$anonymous$$e AT RUNTI$$anonymous$$E when to start the one loop and when to start the other. thus i'd like to crossfade from the one currently playing to another.

avatar image
2

Answer by jashan · Nov 28, 2009 at 01:01 PM

In addition to what Jessy said: You can use the API provided by AudioSource to synchronize the two audio loops that you want to crossfade (or simply start them "simultanuously" - but synching them feels safer to me), and also to change the volume. Since Unity 2.6 this also provides sample-exact synchronization (that's done via the property AudioSource.timeSamples. And, also since Unity 2.6 this also works very reliably (I've had an implementation for this in 2.5 which was "off" a few milliseconds most of the time - since 2.6 it just works perfectly; without even changing my implementation).

So, either you do it "in code" changing the volume a little bit each frame (that would be done in Update); or you design your cross-fades in the AnimationEditor as Jessy suggested and then trigger those animations in whichever way is appropriate (e.g. on collisions, or when the user presses a certain key ... you name it - there's all possibilities at your fingertips ;-) ).

The "in-code" approach is probably best when you don't have a fixed way of cross-fading but for instance want to cross-fade by distance or any other funky thing you could think of (e.g. when you get closer to a certain object, loop A is increased and loop B decreased, and when you move away from that object, loop A is decreased and loop B increased).

The solution using the animation editor is preferable when you want a complete crossfade to happen based on some triggering event (reason is that the animation editor gives you more intuitive control on how the crossfade exactly should happen, you can literally loop the crossfade until you feel it's "perfect for the given purpose"). Using animation events, you could even stop the silent audio clip when the fade is done.

Oh, one final thing: You might also want to keep track of the position in the loop. If you have a beat, for instance, you may want the crossfade to start only when the beat starts which can be done easily by tracking the time (given your loops are prepared for doing this kind of thing). Usually, this doesn't have to be totally perfect with fades but "pretty close".

Comment
Add comment · 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
0

Answer by IgorAherne · Nov 28, 2016 at 08:11 PM

https://forum.unity3d.com/threads/audiosource-cross-fade-component.443257/

Comment
Add comment · 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

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

No one has followed this question yet.

Related Questions

Why do AudioMixerSnapshots not crossfade properly when transitioning? 0 Answers

Can 2 iTween components run on the same gameobject simultaneously? 2 Answers

Audio crossfade on single key press 1 Answer

Animation Sometimes Shows Error dt >= 0 0 Answers

5.1 Channels is backwards in unity (non 3D) 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