Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Looping Audio Files at Specific Points

Okay.... I need to know how this is done! How exactly are audio files "tagged" to loop at *specific* points in the file? Is it done inside the file itself or is the game told using a script to loop at that point? And how do you do it? I'm pretty new and I want to add music of my own. In most games, there's usually that first segment of the song that is played but is never played again during the time the song is executed. Only a portion of the song is repeated. But, when I import custom music into rmxp, the WHOLE song is played and automatically looped to the beginning. I want it to loop to a certain point.
 
I appreciate the responses lol ^^. Now, I know .ogg and .mid and .wav files can be looped internally now. I don't know how to do that though haha ^^; and I can't find any tutorials on how exactly to do that. As if everyone should know... Well, I went with that "easier" way that you mentioned, but I realised I don't know how to put the script in! Well, I know how to put it in the game, but I don't know how I can get the game to access the script! I'm completely new to RGSS (I AM learning though) and I don't know how the game would access the code if I don't have anything pointing or referring to it. I know that much from another scripting language. If nothing refers to it, then its just a piece of code that sits there doing nothing. Am I right? Doesn't this apply to RGSS too?
 
There exist another simpliest solution, with this little code:
Code:
class Game_System

  alias old_bgm_play bgm_play

  def bgm_play(bgm)

    me_play(bgm) if (!@playing_bgm or @playing_bgm.name != bgm.name or

      @playing_bgm.pitch != bgm.pitch) and !Dir["Audio/ME/#{bgm.name}.*"].empty?

    old_bgm_play(bgm)

  end

end
Then you have to cut the opening and the loop into two separated files with the same name.
You put the opening in the ME folder and the loop in the BGM folder (which you will play).
I think that it loops better with ogg than mp3.
 
Whew, thanks! It worked! (Yeah, took me a while to figure out that I didn't need the class command and the last "end" command there ^^; Here I am, making an entirely new class...) In the end, I couldn't code the ogg file itself to loop :(. But that's ok. the only problem I'm having now even with that script is that when transitioning from the ME Intro to the BGM main portion, there's a very definite skip. lol it was rather loud too. That's understandable, though. I can't ask for perfection. It's a great script and thank you so much! I'm gonna try to fix the skipping on my own with some other scripts, now that I know how to put them in (haha)
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top