Music is driving me mad
by Philip Mansfield · in Torque Game Builder · 04/12/2006 (7:59 am) · 8 replies
I've got a couple of bits of music that I play during my game. A background theme that plays all the time, and an end of level jungle.
When I launch my game, the theme music starts playing, and continues to play throughout the first level. At the end of the first level, I stop the theme music, play the jingle, and then schedule the next level.
When the next level starts, the theme music doesn't come on, but I force it with an alxPlay from the console, I can hear two versions of it going at once. I suspect this means that the theme starts playing again, it's just that I can't hear it.
Anyway, here's the code...
I just don't know why it's doing what it's doing. I've tried issuing alxstopall() followed by the relevant alxplay and I get the same result.
My audio datablocks look like this:
When I launch my game, the theme music starts playing, and continues to play throughout the first level. At the end of the first level, I stop the theme music, play the jingle, and then schedule the next level.
When the next level starts, the theme music doesn't come on, but I force it with an alxPlay from the console, I can hear two versions of it going at once. I suspect this means that the theme starts playing again, it's just that I can't hear it.
Anyway, here's the code...
function dispMenu()
{
Canvas.setContent(mainScreenGui);
if (!alxIsPlaying($gameMusic))
$gameMusic=alxPlay( musicAudio );This is my menu screen, and the music starts playing when the game is launched.function startRound()
{
// if the current round is higher than the number of levels,
if ($roundNum == GameLevelSet.getCount())
{
// complete the game
gameComplete();
}else
{
if (alxIsPlaying($victoryMusic))
alxStop( $victoryMusic );
if (!alxIsPlaying($gameMusic))
alxPlay( musicAudio );This is the start of a round. If the victory tune from the previous level is playing stop it, and if the theme music isn't playing, start it. On Round 1, this all works fine.function roundComplete()
{
if (alxIsPlaying($gameMusic))
alxStop( $gameMusic );
if (!alxIsPlaying($victoryMusic))
$victoryMusic = alxPlay( victoryAudio );
$roundNum++;
schedule(4500, 0, "startRound");Once the round is over, I stop the theme music and play the jingle. Then after a bit of a pause, I start the next round.I just don't know why it's doing what it's doing. I've tried issuing alxstopall() followed by the relevant alxplay and I get the same result.
My audio datablocks look like this:
new AudioDescription(AudioNonLooping)
{
volume = 1.0;
isLooping= false;
is3D = false;
type = $GuiAudioType;
};
new AudioDescription(AudioLooping)
{
volume = 1.0;
isLooping= true;
is3D = false;
type = $GuiAudioType;
};
new AudioDescription(musicLooping)
{
volume = 1.0;
isLooping= true;
is3D = false;
type = $GuiAudioType;
};
new AudioProfile(victoryAudio)
{
filename = "~/data/audio/victory.ogg";
description = "AudioNonLooping";
preload = true;
};
new AudioProfile(musicAudio)
{
filename = "~/data/audio/music.ogg";
description = "musicLooping";
preload = true;
};I added in the musicLooping description in case it made any difference. The only other thing I can think of is changing type=$GuiAudioType but I don't really understand what that is.
#2
Audio Datablocks
Starting and stopping code
If I start the game with music on ($mnuMusicBox.curOption == 2), the music starts playing with no problem. I can navigate the menus without the music giving me any problems. If switch the music off via the menu ($mnuMusicBox.curOption == 1) the music goes off and I navigate the menus in silence.
If I then try to switch the music back on again, I get nothing. Even trying to reactivate the music by hand via the console doesn't give me much joy until I do: alxPlay(menuMusic); and then I get 4 copies playing at once (depending on how many times I'd tried to start the music).
The $mnuMusicBox.curOption variable is being set correctly, as echos in the code show up. If I enter: echo (alxisplaying($menuMusicHandle)); in the console I get the right result back depending on what my menu system says. There is just no actual sound being produced!
If one of you more brainy bods could perhaps point out what may be going wrong, I'd really appreciate it. My games are going to be rather dull with no music :(
07/21/2006 (2:35 pm)
OK, it seems there are still some serious issues either with the final release of TGB, or my brain (I'm not ruling out either at this stage!). I'm having sound problems with another project, so on with the code:Audio Datablocks
new AudioDescription(AudioNonLooping)
{
volume = 1.0;
isLooping= false;
is3D = false;
type = $GuiAudioType;
};
new AudioDescription(AudioLooping)
{
volume = 1.0;
isLooping= true;
is3D = false;
type = $GuiAudioType;
};
new AudioProfile(menuMusic)
{
filename = "~/data/audio/menumusic.ogg";
description = "AudioLooping";
preload = true;
};Starting and stopping code
function checkMenuMusic()
{
switch ($mnuMusicBox.curOption)
{
case 1:
if (alxIsPlaying($menuMusicHandle))
alxStop($menuMusicHandle);
case 2:
if (!alxIsPlaying($menuMusicHandle))
$menuMusicHandle = alxPlay(menuMusic);
}
}I call the checkMenuMusic function everytime I press a cursor key to navigate my menu structure.If I start the game with music on ($mnuMusicBox.curOption == 2), the music starts playing with no problem. I can navigate the menus without the music giving me any problems. If switch the music off via the menu ($mnuMusicBox.curOption == 1) the music goes off and I navigate the menus in silence.
If I then try to switch the music back on again, I get nothing. Even trying to reactivate the music by hand via the console doesn't give me much joy until I do: alxPlay(menuMusic); and then I get 4 copies playing at once (depending on how many times I'd tried to start the music).
The $mnuMusicBox.curOption variable is being set correctly, as echos in the code show up. If I enter: echo (alxisplaying($menuMusicHandle)); in the console I get the right result back depending on what my menu system says. There is just no actual sound being produced!
If one of you more brainy bods could perhaps point out what may be going wrong, I'd really appreciate it. My games are going to be rather dull with no music :(
#3
In addition to the music, I had a bleep sound everytime you moved the menu pointer. By commenting out the bleep my music now behaves itself.
This leads to me to believe that the bleep and music were trying to be played at the same time and causing a bit of an internal conflict. So the question now is how do I get around this?
I suspect it's something to do with playing different sounds on different channels, I'm just not sure how to go about that, and most of the good stuff seems to be in TGE private forums which I can't access.
I'll keep digging, but if anyone knows how this stuff works and could post a bit of code, I'd really appreciate it.
07/21/2006 (2:51 pm)
G'ah! OK, so I've kind of gotten to the bottom of it!In addition to the music, I had a bleep sound everytime you moved the menu pointer. By commenting out the bleep my music now behaves itself.
This leads to me to believe that the bleep and music were trying to be played at the same time and causing a bit of an internal conflict. So the question now is how do I get around this?
I suspect it's something to do with playing different sounds on different channels, I'm just not sure how to go about that, and most of the good stuff seems to be in TGE private forums which I can't access.
I'll keep digging, but if anyone knows how this stuff works and could post a bit of code, I'd really appreciate it.
#4
Then set the type in your music profile to $MusicAudioType
See if that works.
07/21/2006 (2:57 pm)
In client/scripts/audioProfiles.cs:$GuiAudioType = 1; $SimAudioType = 2; $MessageAudioType = 3; [b]$MusicAudioType = 4;[/b]
Then set the type in your music profile to $MusicAudioType
See if that works.
#5
The situation is better now, but the music doesn't reliably play everytime. If I move very quickly between on then off and on again the music goes off and restarts. If I move from on to off, pause for a second or two, and then back to on, the music doesn't restart.
If I comment out the commands to play the beep as I move between the options, the music stops and starts perfectly.
07/21/2006 (3:38 pm)
Spookily enough, I just found:$musicAudioType = 4;
new AudioDescription(AudioChannel1)
{
volume = 1.0;
isLooping = true;
is3D = false;
type = $musicAudioType;
};
$effectsAudioType = 2;
new AudioDescription(AudioChannel2)
{
volume = 1.0;
isLooping = false;
is3D = false;
type = $effectsAudioType;
};in /common/gameScripts/audo.cs I've made a couple of tweaks to it so it reads what's above.The situation is better now, but the music doesn't reliably play everytime. If I move very quickly between on then off and on again the music goes off and restarts. If I move from on to off, pause for a second or two, and then back to on, the music doesn't restart.
If I comment out the commands to play the beep as I move between the options, the music stops and starts perfectly.
#6
;-D
07/23/2006 (12:57 pm)
I would say you need to figure out how important the beep is compared to the music, and adjust accordingly. I bet such issues will be ironed out completly in future versions of TGB. Hopefully. . .;-D
#7
07/23/2006 (1:54 pm)
That's what I did in the end. I have a beep for moving up and down, and did away with the beep for moving left and right between choosing the options.
#8
07/23/2006 (2:05 pm)
Ah, it is good that you shall not go beepless. . .
Torque Owner Philip Mansfield
Default Studio Name
I've dumped the music for the time being, but the sound effects are dropping out, have low volume, or simply not playing at all.
I can't see that I'm doing anything out of the ordinary, which leads me to believe that sound is broken in the beta 2 release of TGB.
If someone could try and shed some light on this issue, I'd really appreciate it, otherwise I'll just have to have a completely silent game :(