Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
1
Question by Kaim · Oct 02, 2013 at 08:09 PM · audioaccessing from any scriptendless loop

music loops specific time of the song

hello, is the pimera time I write and I'm using unity some time ago. good to the point. You can make a loop with a song ogg vorbis from a specific time? not repeat the whole song?. I ask this because in a program called RPG Maker can do, if within the song is called LoopStart and LOOPLENGTH information indicating from where do the loop. there will be some script to do this?

Comment
Add comment · Show 1
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 Benproductions1 · Oct 16, 2013 at 02:01 AM 0
Share

How about you just stop playing the music and start it again at the repeat point. Just look at the Documentation

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by astracat111 · Oct 24, 2016 at 05:23 AM

In the newest rpg maker mv they released their core source. Here's the code in javascript that they use to get the metadata info from an ogg file. This is in javascript, and won't work in Unity, but you'll get the basic idea. You're going to have to loop through the metadata and find where an entry says "LOOPSTART" or "LOOPLENGTH" or even "LOOPEND" or whatever you' like. You might have to use an external dll to read the file.

 WebAudio.prototype._readOgg = function(array) {
     var index = 0;
     while (index < array.length) {
         if (this._readFourCharacters(array, index) === 'OggS') {
             index += 26;
             var vorbisHeaderFound = false;
             var numSegments = array[index++];
             var segments = [];
             for (var i = 0; i < numSegments; i++) {
                 segments.push(array[index++]);
             }
             for (i = 0; i < numSegments; i++) {
                 if (this._readFourCharacters(array, index + 1) === 'vorb') {
                     var headerType = array[index];
                     if (headerType === 1) {
                         this._sampleRate = this._readLittleEndian(array, index + 12);
                     } else if (headerType === 3) {
                         this._readMetaData(array, index, segments[i]);
                     }
                     vorbisHeaderFound = true;
                 }
                 index += segments[i];
             }
             if (!vorbisHeaderFound) {
                 break;
             }
         } else {
             break;
         }
     }
 };

 WebAudio.prototype._readMetaData = function(array, index, size) {
     for (var i = index; i < index + size - 10; i++) {
         if (this._readFourCharacters(array, i) === 'LOOP') {
             var text = '';
             while (array[i] > 0) {
                 text += String.fromCharCode(array[i++]);
             }
             if (text.match(/LOOPSTART=([0-9]+)/)) {
                 this._loopStart = parseInt(RegExp.$1);
             }
             if (text.match(/LOOPLENGTH=([0-9]+)/)) {
                 this._loopLength = parseInt(RegExp.$1);
             }
             if (text == 'LOOPSTART' || text == 'LOOPLENGTH') {
                 var text2 = '';
                 i += 16;
                 while (array[i] > 0) {
                     text2 += String.fromCharCode(array[i++]);
                 }
                 if (text == 'LOOPSTART') {
                     this._loopStart = parseInt(text2);
                 } else {
                     this._loopLength = parseInt(text2);
                 }
             }
         }
     }
 };

You can implement this yourself in Unity. I'm planning to myself so when I do I'll send you back the source.

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 Cynikal · Oct 24, 2016 at 04:06 AM

The simplest solution? Look on the asset store and use any of the top audio tools on there.

What you could do though, is cut up the loop files, then instead of using Audio.Play, use Audio.PlayDelayed, and just loop it.

You can also set the loop start, and loop end points, then just stop, and then play at the new start again.. However this might cause hiccups in the sound quality.

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

17 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

Related Questions

OnAudioRead Buffer Changing Sizes? 1 Answer

How to access Vive controllers in a script attached on a simple game object(a cube)? 0 Answers

2 audiolisteners in 1 scene 0 Answers

Endless "Importing assets" loading window in Unity editor 2 Answers

How to play an audio one shot clip on a collision 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