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 /
  • Help Room /
avatar image
14
Question by DoctorSauce · Nov 05, 2012 at 06:36 AM · audioloopseamlessbackground music

How do i make Unity seamlessly loop my background music?

I spent like an hour getting this clip of music to loop seamlessly and when I finally got it, I put it into my game as background music that looped. But then I noticed all my work to make it loop seamlessly was for nothing, because what it looks like is that Unity is adding a split second of blank audio at the beginning of my mp3 file, so I have an obvious pause in the loop that sounds terrible. How do I prevent Unity from screwing up all my work and not adding the blank audio at the beginning?

Comment
Add comment · Show 4
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 Althaen · Nov 05, 2012 at 08:42 AM 0
Share

How did you put it in the game exactly?

avatar image dannyskim · Nov 05, 2012 at 06:13 PM 0
Share

It shouldn't make a difference which ever way you import it.

avatar image DoctorSauce · Nov 05, 2012 at 08:37 PM 0
Share

Ok thanks guys, I finally have it figured out. One more reallly realllly dumb question.... how do I mark the topic as answered? hahahaha I'm totally serious, I know I probably sound like an idiot.

avatar image dannyskim · Nov 05, 2012 at 08:39 PM 0
Share

I believe you should be able to mark alucardj's comment as an answer, hover over the buttons. I can't remember if they added that functionality or not.

4 Replies

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

Answer by AlucardJay · Nov 05, 2012 at 07:12 AM

I can only give you my noob experience.

You have to save your audio as a .wav (for some reason, a small amount of data is added to the beginning/end of the MP3, I am assuming for ID tag and track info, image etc). Then in the Inspector settings of the sound, select Audio Format : Native (WAV)

Create an empty GameObject.

Add an Audio Source component.

In the Inspector, Select Play on Awake and Loop.

Finally drag-and-drop your audio into Audio Clip in the Inspector.

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 DoctorSauce · Nov 10, 2012 at 05:41 AM 0
Share

Thanks, this really helped.

avatar image NinjaISV · Feb 03, 2015 at 04:29 PM 0
Share

Thanks! Spent hours trying to figure this out.

avatar image hema_dubal · Dec 20, 2017 at 12:19 PM 0
Share

Thanks a lot! Helped me!

avatar image FireJojoBoy · Nov 20, 2020 at 12:48 PM 0
Share

Thaaaanks :D

avatar image
7

Answer by unfa · Sep 05, 2016 at 04:18 PM

MP3 is no good for seamless looping, because it indeed messes up the timing, inserting a small pause in the beginning of the file. This has nothing to do with tags (they are inserted at the end of the file, and would not be interpreted as audio data anyway).

Try using WAV or Ogg Vorbis, because these formats keep things loopable.

Comment
Add comment · Show 2 · 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 harryblack · Feb 08, 2019 at 05:44 AM 0
Share

@unfa First of all I am a big fan of yours :D your youtube channel is like extremely informative and fun :D

Secondly can the loop markers in DAWs somehow help in looping within the game. Say like I mark some point as loop in FL Studio can Unity somehow loop using this marker?

avatar image Jon_Brant · Jul 25, 2019 at 09:11 AM 0
Share

Thanks, I noticed my files do this even in Windows if they're mp3.

avatar image
2

Answer by electro61 · Sep 25, 2014 at 07:46 AM

I wrote up a post that explains how to create seamless looping files and convert them for in game use! It should answer any questions you have :)

http://www.playdotsound.com/portfolio-item/tutorial-how-to-create-seamless-looping-music-and-sfx-files-for-video-games/

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 Untherow · Aug 11, 2017 at 08:12 AM

Maybe this is not relevant anymore since Unity can compress WAV files directly to very compact seamlessly looping OGG files and can't see any benefit using MP3s nowadays, but I actually were able to loop MP3 files surprisingly well with a script I wrote. :)

  /// <summary>
 /// Trims silence from both ends in an AudioClip.
 /// Makes mp3 files seamlessly loopable.
 /// </summary>
 /// <param name="inputAudio"></param>
 /// <param name="threshold"></param>
 /// <returns></returns>
 AudioClip trimSilence(AudioClip inputAudio, float threshold = 0.05f)
 {

     // Copy samples from input audio to an array. AudioClip uses interleaved format so the length in samples is multiplied by channel count
     float[] samplesOriginal = new float[inputAudio.samples * inputAudio.channels];
     inputAudio.GetData(samplesOriginal, 0);

     // Find first and last sample (from any channel) that exceed the threshold
     int audioStart = Array.FindIndex(samplesOriginal, sample => sample > threshold),
         audioEnd = Array.FindLastIndex(samplesOriginal, sample => sample > threshold);

     // Copy trimmed audio data into another array
     float[] samplesTrimmed = new float[audioEnd - audioStart];
     Array.Copy(samplesOriginal, audioStart, samplesTrimmed, 0, samplesTrimmed.Length);

     // Create new AudioClip for trimmed audio data
     AudioClip trimmedAudio = AudioClip.Create(inputAudio.name, samplesTrimmed.Length / inputAudio.channels, inputAudio.channels, inputAudio.frequency, false);
     trimmedAudio.SetData(samplesTrimmed, 0);

     return trimmedAudio;
 }
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 bthes · Jan 28, 2018 at 11:59 AM 0
Share

Excellent :) Thanks

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

25 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 avatar image

Related Questions

Trouble automatically importing Audioclip's into unity for background music,bulk audio importing 0 Answers

How to change Music between Scenes 0 Answers

How do I save the background music in the settings? 0 Answers

How should I prep audio assets for looping so as to avoid pops clicks etc. 0 Answers

PlayOnAwake Audiosource will only play when it's set to loop? bug? 1 Answer


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