Audio alxPlay problems
by J. Alan Atherton · in Torque Game Engine · 04/20/2005 (12:31 am) · 16 replies
I have two music tracks which play beautifully... one with the Startup screen, and one in-game. Those play nicely. Any other sounds that I use, such as voice indicating which "phase" the game round is in (think announcer) do not work _unless_ I play it twice in a row. That is:
alxplay(...);
alxplay(...);
With that kludge I can hear the sound, although it is a little quieter than I would like (even after toying with various volume parameters). This is done in script, and no other audio is playing (not even music) at the time these voices are played.
I have not noticed a null audio description, as explained in this thread:
www.garagegames.com/mg/forums/result.thread.php?qt=16013
Can anyone throw me a bone for what causes such strange behavior?
(Please, no "TGE audio code stinks" posts)
For reference, here's some code:
alxplay(...);
alxplay(...);
With that kludge I can hear the sound, although it is a little quieter than I would like (even after toying with various volume parameters). This is done in script, and no other audio is playing (not even music) at the time these voices are played.
I have not noticed a null audio description, as explained in this thread:
www.garagegames.com/mg/forums/result.thread.php?qt=16013
Can anyone throw me a bone for what causes such strange behavior?
(Please, no "TGE audio code stinks" posts)
For reference, here's some code:
$PhaseAudioType = 4;
/// ...
new AudioDescription(AudioPhase)
{
volume = 250.0;
isLooping= false;
is3D = false;
type = $SimAudioType;
};
/// much later in the file:
new AudioProfile(AudioBuildWalls)
{
filename = "~/data/sound/buildWalls.ogg";
description = "AudioPhase";
preload = true;
};/// Different file alxStop($SoundPlaying); // Just in case $SoundPlaying = alxPlay(AudioBuildWalls); $SoundPlaying = alxPlay(AudioBuildWalls);
#2
What's interesting is that I couldn't hear the sound with a volume of 1. I increased it, and I think it maxed out at 100, where I could actually hear it. But that, of course, is only after playing it multiple times in a row. I just checked again, and turning it back to 1 keeps it at high volume. Strange how things change...
The sound file plays, so I don't think there's anything wrong with the sound file itself. In fact, I tried changing the "buttonOver" sound in the GUI to my "bombsAway" sound, and that works nicely too. So something is being done in the GUI that makes the sound work. Something else is making the audio in the Sim _not_ work.
Something I noticed with a little more research is a function call alxCreateSource. I see a few other places where this is used in script. When do we need to use this function?
04/20/2005 (7:57 am)
Thanks for the response, Billy. What's interesting is that I couldn't hear the sound with a volume of 1. I increased it, and I think it maxed out at 100, where I could actually hear it. But that, of course, is only after playing it multiple times in a row. I just checked again, and turning it back to 1 keeps it at high volume. Strange how things change...
The sound file plays, so I don't think there's anything wrong with the sound file itself. In fact, I tried changing the "buttonOver" sound in the GUI to my "bombsAway" sound, and that works nicely too. So something is being done in the GUI that makes the sound work. Something else is making the audio in the Sim _not_ work.
Something I noticed with a little more research is a function call alxCreateSource. I see a few other places where this is used in script. When do we need to use this function?
#3
04/20/2005 (8:06 am)
Use %client.play2d(audioName) instead of alxplay() it should prevent the repeating issues.
#4
It looks like that method uses the network, though. (It justs posts a NetEvent). This is fine for prototyping (which is where I'm at), but I'm going for minimal network use eventually.
I just tried it out (calling %client.play2d(AudioBombsAway) from the server), and nothing happens. It's in a place that I know is getting the correct client number (since I have other functions operating in the same area that issue commandToClient). I tried using both my AudioPhase description and the Audio2D description (defined both on the server and client audioProfiles).
Another anomaly I noticed while testing this is that the buttonOver sound in the tree() dialog has the same problem as my sounds. When I first hover over a button, nothing happens, but if I go on and off the button quickly I can occasionally hear the sound. This may just be something with my sound card/driver (ac97 I believe), but even if it is, I would like to fix it.
Just to clarify, I'm not getting a repeating sound. If I just use alxPlay() once, I get no sound. If I use it twice in a row, I get one sound.
04/20/2005 (9:02 am)
Thanks for the tip Anthony. It looks like that method uses the network, though. (It justs posts a NetEvent). This is fine for prototyping (which is where I'm at), but I'm going for minimal network use eventually.
I just tried it out (calling %client.play2d(AudioBombsAway) from the server), and nothing happens. It's in a place that I know is getting the correct client number (since I have other functions operating in the same area that issue commandToClient). I tried using both my AudioPhase description and the Audio2D description (defined both on the server and client audioProfiles).
Another anomaly I noticed while testing this is that the buttonOver sound in the tree() dialog has the same problem as my sounds. When I first hover over a button, nothing happens, but if I go on and off the button quickly I can occasionally hear the sound. This may just be something with my sound card/driver (ac97 I believe), but even if it is, I would like to fix it.
Just to clarify, I'm not getting a repeating sound. If I just use alxPlay() once, I get no sound. If I use it twice in a row, I get one sound.
#5
Must be the ac97 that mess things up.
I never get strange things like that with sblive cards.
All sounds working great with all mentioned ways to play the audio above.
Dont know any other ways to fix this , maybe there are other guys out there
that have ac97 cards that hopefully can help you.
04/20/2005 (2:19 pm)
Strange thing !Must be the ac97 that mess things up.
I never get strange things like that with sblive cards.
All sounds working great with all mentioned ways to play the audio above.
Dont know any other ways to fix this , maybe there are other guys out there
that have ac97 cards that hopefully can help you.
#6
This doesn't work:
Anyone have any clues?
-Josh
04/21/2005 (2:17 pm)
I've been working on playing a sound effect for the last 2 hours...This doesn't work:
new AudioDescription(AudioTest)
{
volume = 1.0;
isLooping= false;
is3D = false;
type = 1;
};
alxPlay(alxCreateSource(AudioTest, "minions.of.mirth/data/sound/Crossbow_explosion.ogg"));Anyone have any clues?
-Josh
#7
datablock AudioProfile(AudioTest)
{
filename = "...ogg";
description = AudioClose3d;
preload = true;
};
serverPlay2D(AudioTest);
or
serverPlay3D(AudioTest,%obj.getTransform());
_
04/21/2005 (2:43 pm)
This doesn't solve your problem, but I'm wondering why you don't do this...datablock AudioProfile(AudioTest)
{
filename = "...ogg";
description = AudioClose3d;
preload = true;
};
serverPlay2D(AudioTest);
or
serverPlay3D(AudioTest,%obj.getTransform());
_
#8
Button sounds and the test sound from the Audio Options also don't play...
I heard that these sounds work in the demo folder but not the starter.fps or something... I started with starter.fps... the button sounds do work in the demo here...
Edit: I installed a clean 1.3 ... the audio works in the demo folder, the starter.fps audio does not work (I am testing with the Audio Options Sliders)
04/21/2005 (2:55 pm)
Because this isn't on the server.Button sounds and the test sound from the Audio Options also don't play...
I heard that these sounds work in the demo folder but not the starter.fps or something... I started with starter.fps... the button sounds do work in the demo here...
Edit: I installed a clean 1.3 ... the audio works in the demo folder, the starter.fps audio does not work (I am testing with the Audio Options Sliders)
#9
For what it's worth...
The test sound from the Audio Options works in starter-fps and racing here.
I have Realtek AC97.
04/21/2005 (3:52 pm)
Ok, got it. For what it's worth...
The test sound from the Audio Options works in starter-fps and racing here.
I have Realtek AC97.
#10
Also, once I set this sound for the button rollover sound, the Sound Options test sound works... otherwise, it doesn't.
Bizarre.
04/21/2005 (4:50 pm)
Alright, it's quite flakey... If I set the startup wrench sound from the demo as the button rollover sound, I get sound... other sound files aren't yielding sound.Also, once I set this sound for the button rollover sound, the Sound Options test sound works... otherwise, it doesn't.
Bizarre.
#11
and work with %client.play2d(profileName);
new AudioProfile(){}; are for client side only, like button mouse over sounds
04/21/2005 (5:15 pm)
Datablock AudioProfile(){}; are for sound transmitted across the network.and work with %client.play2d(profileName);
new AudioProfile(){}; are for client side only, like button mouse over sounds
#12
04/21/2005 (5:48 pm)
As long as the first sound I play is stereo, other sounds, including mono, work. If I play a mono sound first there's no sound.
#13
Changing:
to
Causes the mono sound to play (improperly of course) and other sounds to work... otherwise, playing a stereo sound as t he first sound seems to work... though, doesn't give a warm fuzzy.
Hrrmmmmm.
-Josh
04/22/2005 (9:36 am)
In audioBuffer.cc, bool AudioBuffer::readOgg(ResourceObject *obj)Changing:
if(vi->channels == 1) {
format = AL_FORMAT_MONO16;
size = 2 * samples;
} else {
format = AL_FORMAT_STEREO16;
size = 4 * samples;
}to
if(vi->channels == 1) {
format = AL_FORMAT_STEREO16;
size = 2 * samples;
} else {
format = AL_FORMAT_STEREO16;
size = 4 * samples;
}Causes the mono sound to play (improperly of course) and other sounds to work... otherwise, playing a stereo sound as t he first sound seems to work... though, doesn't give a warm fuzzy.
Hrrmmmmm.
-Josh
#14
I got sound + the newest OpenAL SDK working (at least on Win32) by doing this:
from audioBuffer.cc:
alIsBuffer() returns true when malBuffer is 0 (which is what it is initialized to)... so I chaged this to -1
Also, it appears that the "DirectSound3D" device is being used by default. This device seems to have problems... so I tell OpenAL to use DirectSound in OpenALInit():
04/22/2005 (2:01 pm)
I snagged the latest OpenAL SDK from CVS... and compiled against it... no sound at all... This wasn't surprising as the newer OpenAL dll's don't work either... I got sound + the newest OpenAL SDK working (at least on Win32) by doing this:
from audioBuffer.cc:
ALuint AudioBuffer::getALBuffer()
{
if (!alcGetCurrentContext())
return 0;
// clear the error state
alGetError();
if (alIsBuffer(malBuffer))
return malBuffer;
*** SNIP ***alIsBuffer() returns true when malBuffer is 0 (which is what it is initialized to)... so I chaged this to -1
AudioBuffer::AudioBuffer(StringTableEntry filename)
{
AssertFatal(StringTable->lookup(filename), "AudioBuffer:: filename is not a string table entry");
mFilename = filename;
mLoading = false;
malBuffer = -1;
}
AudioBuffer::~AudioBuffer()
{
if( malBuffer != -1 ) {
alDeleteBuffers( 1, &malBuffer );
}
}Also, it appears that the "DirectSound3D" device is being used by default. This device seems to have problems... so I tell OpenAL to use DirectSound in OpenALInit():
#ifdef TORQUE_OS_WIN32 mDevice = (ALCdevice *)alcOpenDevice((ALubyte*)"DirectSound"); #endif #ifdef TORQUE_OS_MAC mDevice = (ALCdevice *)alcOpenDevice((ALubyte*)NULL); #endif
#15
The sounds would play fine on a local client.
But not work if I joined a server as a remote client.(dedicated server running on same machine).
I found it will work only if I change the location of my 'audioDescriptions' from server side to client side.
After I did that all the sounds work.
It seems the server sends the 'audioFormats' down to clients but not the 'audio Descriptions'.
or Maybe it could be because Channel assignment variable is not defined on the server.
I didn't try changing them I just moved them client side.
// Channel assignments (channel 0 is unused in-game).
$GuiAudioType = 1;
$SimAudioType = 2;
$MessageAudioType = 3;
Hope this helps.
07/25/2005 (7:52 am)
I'm not sure if this is the same bug you had, but I just spent all day trying to get sounds playing on my remote client.The sounds would play fine on a local client.
But not work if I joined a server as a remote client.(dedicated server running on same machine).
I found it will work only if I change the location of my 'audioDescriptions' from server side to client side.
After I did that all the sounds work.
It seems the server sends the 'audioFormats' down to clients but not the 'audio Descriptions'.
or Maybe it could be because Channel assignment variable is not defined on the server.
I didn't try changing them I just moved them client side.
// Channel assignments (channel 0 is unused in-game).
$GuiAudioType = 1;
$SimAudioType = 2;
$MessageAudioType = 3;
Hope this helps.
#16
I downloaded the new openAl32.dll and everything works without any problems.
Lovely fix thanks alot !
07/25/2005 (3:10 pm)
@Josh I downloaded the new openAl32.dll and everything works without any problems.
Lovely fix thanks alot !
Torque 3D Owner Billy L
I would suggest check where you activate the script to play the sound.
And dbl check the soundfile.
Some info :
max volume setting is 1
Normalize the sound file to 0 db to get max volume.
-Billy