Music, Sound & Speech

From Adventure Game Studio | Wiki
Jump to navigation Jump to search
This article uses deprecated code/functionalities.
Information in this article may be out of date or just plain wrong!

Getting sound/music into your game

How do I get sound/music into my game? Is there a menu or editor within AGS that I can use to add music/sound files into, or what?

Nope. It's actually very simple. To use sound effects, you may need to use script, or the "Game - play sound effect" and "Game - play music" actions in the interaction editor (on the other hand, sound effect for a score increase, can be set in the General pane of the AGS Editor). Check out the PlaySound() command in the AGS manual. To do it via the interaction editor approach, just choose the interaction editor (the button with the letter 'i', which is available in several panes of the editor), you can use room/object/whatever interactions and choose the correct event (like "player enters room" or "player looks at hotspot" or whatever), and find the "Game - play sound" or "Game - Play music" event. Then, simply choose the sound/music number. For music, you might also be able to set a certain background music file to play upon entering a room. This can be found in the Rooms/Settings pane, with a "Play music on load" checkbox and a text box beside it, where you can type in the number. If you way Music4.mid or Music4.mp3 (only one Music4.* file can exist at a time) to play, simply type in the number 4.

For speech, that's a whole different matter altogether. You need to use scripting, whether it's text scripting or dialog scripting. Check the manual for more information on speech. (Simply search for "Speech" under the Index tab.)

Music/speech/sound not working properly or at all

My music/speech/sound doesn't work.

This article/section was written for an older version of AGS.
AGS 2.7 uses new, easier, Object-Oriented scripting and so this article needs updating to reflect the new style scripts.

newer AGS versions have subfolders of the game folder for music and speech (AGS 2.71+) and sound effects (2.72)

Even though this is too general a question to ask (what happens exactly, what did you do, what does your script look like?), there are several steps you can take to double-check that everything is okay:

  1. Make sure you enable sound and midi options at File->Setup Game, if you dont, it wont work, that simple
  2. Did you remember to name them "MusicXX.???" or "SoundXX.???" accordingly? XX would be the order number (like Music4.mid or Sound23.voc), and ??? would be the file format extension (MID, MP3, OGG, XM, etc. for music; WAV, VOC, MP3, OGG, etc. for sound/speech).
  3. If you're using speech, did you remember to use the correct scripting format? Check the manual for more information on this.
  4. Try clicking Game –> Rebuild VOX files. This will re-build all the files that AGS uses to store the music/sound. If you added new files, you must do this every time. See the question below on adding sound/music files and not being able to hear them.
  5. Next, make sure that all of the music/sound files are in the main game directory, the same place that the RoomXX.crm files should be located. If this doesn't work, try moving them to the "Compiled" folder of your game's directory. Some people have had success with this.
  6. Also, please make sure that you have DirectX 7 or higher installed.
  7. If you are unsure, click on Start then Run... and type in dxdiag. Hit Enter and you will run the DirectX Diagnostic tool. It should tell you the DX version on the bottom of the window. (You might have to Search for "dxdiag.exe" in order to run this program.) Most games nowadays come with DirectX. The newer the game, the newer the version. It is also available online at Microsoft's web site, though it is a pretty large download. Finally, make sure that if you are using WAV files, that they are all in uncompressed PCM format only.
  8. It is also possible that Explorer was initially set to Hide extensions for known file types. If that's the case then your file is actually named something like MUSIC1.MID.MID. To disable this, go into Explorer, then click on Tools, then Folder Options.... In the View tab, look for the checkbox labeled Hide extensions for known file types and uncheck it. Then click OK and you're all set.

However, if none of this works, ask us at the AGS Beginners' Forum. If it's too tough for us to answer, we'll move it to the Advanced Tech Forum. If they can't answer it, then take a machine gun to your computer and start cross-dressing. We'll all be better off anyway. :P

Inability to hear new music/sound/speech after adding them in

I added new music/sound/speech files and now I can't hear them. What should I do?

AGS uses a Speech.VOX or Music.VOX file to store all the sound files into (with some exceptions such as MIDI files, which are stored inside the game data files). If you add new music/sound, you need to click on Game -> Rebuild VOX files to re-compile all the .VOX files used by AGS.

Error: "Unable to initialize your audio hardware (problem: Failed to init digital sound driver)"

When I test my game (which has NO sound or music yet), OR when I play someone else's game, I get an error that says, “Unable to initialize your audio hardware (problem: Failed to init digital sound driver)”. What is the problem?

Well, so far three things have helped some people:

  1. First off, make sure Windows Media Player isn't already running in the background. This can screw things up. Close all programs that even use WMP, like some FireFox extensions do. There also might be other programs that use the digital sound driver, like Winamp, QuickTime Player, and Real Video Player. I'm not sure if these programs use the same drivers that AGS does, but it's worth closing them all just in case.
  2. Go into your DirectX settings program (usually "dxdiag.exe", sometimes in a "386" folder). Click on the sounds tab and move the slider to "Full Acceleration". Try it now.
  3. Also, a much quicker way is to open up the Game Setup window in AGS and change the digital sound setting from "Default Direct Sound" to "Default WaveOut Device".

Adding footstep sounds to each of your characters' footsteps

How would I set it up so that every time my character takes a step (their foot hits the floor/ground), AGS plays a footstep sound? And how would I change the footstep sound depending on the surface type?

In the View Editor, you can set a sound for any frame of any view you want. Choose the frame where the character's foot seems to hit the ground/floor and click the "NO SND" text under that frame. You will be able to set the sound that plays.

As for surface type, make each surface type a different region. You can change the sounds by using the "Player walks on region" interaction of each Region in the room. Then use the SetFrameSound() text script command to set the sound of each of the frames you have altered.

Just a side note: This function can be useful for a LOT of other things. For example, you could have it so that your character has the ability to become injured. Maybe at that point, you could change his view to one where he limps, with each footstep playing a grunt sound. To make it even more realistic, you could randomize the grunt sound as well, with the SetFrameSound() command and the repeatedly_execute game function. Just a thought.

Getting the background music to play continuously from room to room

What do I have to do in order to keep my background music playing from room to room?

Quite simply, nothing. Just don't tell AGS to stop playing the music until you reach the room in which you want the music to stop. Then, just play new music or stop it altogether, whichever you want. AGS plays music from room to room automatically until you tell it otherwise.

However, if you change tracks and then come back to the original music, it will start againfrom the beginning unless you use the Continuous Music Module.

Fading out MIDI music upon entering a new room

How would I go about fading out MIDI music, say, upon entering a new room where the music is longer desired?

Since crossfading music only works with MP3, OGG, and the like, here is what you do for MIDI music. In the global script, before anything, add the following:

 int FadeOutFlag=0,ActualTime,EnterRoomTime;
 //DateTime* curtime;  //Uncomment for V2.7+

Inside the header script, add:

 import int FadeOutFlag;
 import int EnterRoomTime;
 import int ActualTime;

Inside any room where you want the custom fade-out to occur, add the interaction "When player enters screen", which runs the script:

 FadeOutFlag = 1;
 EnterRoomTime = GetRawTime(); //Comment for V2.7+
 //curtime = DateTime.Now; //Uncomment for V2.7+
 //EnterRoomTime = curtime.RawTime; //Uncomment for V2.7+

In case the player leaves the room before the fadeout, you should also add the interaction "When player leaves room", running the following script:

 FadeOutFlag = 0;

Finally, inside repeatedly_execute(), add:

 int TimeDif; // Difference in seconds between
              // the actual time and the time when
              // the player entered the room
 ActualTime = GetRawTime(); //gets actual time, comment for V2.7+
 //curtime = DateTime.Now; //Uncomment for V2.7+
 //ActualTime = curtime.RawTime; //Uncomment for V2.7+
 if (FadeOutFlag == 1) //if the player entered the room
   TimeDif = ActualTime - EnterRoomTime; // how many seconds has the player been in the room?
   if (TimeDif >= 11)  // if player has been 11 seconds inside room
       StopMusic(); // stop music
       FadeOutFlag = 0; // flag goes back to normal
       SetMusicMasterVolume(80);  // music volume back to normal
       SetMusicMasterVolume(80 - (TimeDif * 8)); // lower music volume

And that's it! Many thanks to rozojc for the code! (Note: if you're using AGS V2.7 and above, you may need to comment the lines marked with comment "Comment for V2.7+" and uncomment the lines marked with comment "Uncomment for V2.7+".)