Audio playing issues (Solved)
by Mike Lilligreen · in Torque 2D Beginner · 02/24/2013 (9:38 pm) · 7 replies
I have been working on an AudioBasicsToy and ironically it is raising more problems than I hoped it would solve for others.
You can download a zip copy of my modules repo from here: github.com/t2Dtutorials/T2D-Modules
Here is a short summary of bugs from my playtesting:
Background Music
Pressing play - stop - play - stop with the default title music = no issues, Audio ID goes up as expected
Pressing play - stop - play - stop with the win music = Audio ID assigned is a huge negative number
Pressing play - pause - pause with title music = alxUnpause is not working
Pressing play - pause - pause with win music = alxPause not working, probably due to the negative ID
Pressing play - pause - play - pause = sounds ok but console is reporting an OpenAL error
Sound Effects
Pausing the background music and playing the sound effects demo causes the background music to unpause when the sound effect is played. Background music controls no longer work after that.
If I understand things correctly, AudioAsset is a combination of the old AudioDescription and AudioProfile? Only there seems to be a few properties missing, for example setting the type (there seems to be a hint of types in the openal.cs file in the Sandbox). Or can I separate the music and effects channels with the VolumeChannel field in AudioAsset?
I'm guessing most, if not all, of these bugs are from my own doing so thanks in advance for helping point out any mistakes I have made in my script.
You can download a zip copy of my modules repo from here: github.com/t2Dtutorials/T2D-Modules
Here is a short summary of bugs from my playtesting:
Background Music
Pressing play - stop - play - stop with the default title music = no issues, Audio ID goes up as expected
Pressing play - stop - play - stop with the win music = Audio ID assigned is a huge negative number
Pressing play - pause - pause with title music = alxUnpause is not working
Pressing play - pause - pause with win music = alxPause not working, probably due to the negative ID
Pressing play - pause - play - pause = sounds ok but console is reporting an OpenAL error
Sound Effects
Pausing the background music and playing the sound effects demo causes the background music to unpause when the sound effect is played. Background music controls no longer work after that.
If I understand things correctly, AudioAsset is a combination of the old AudioDescription and AudioProfile? Only there seems to be a few properties missing, for example setting the type (there seems to be a hint of types in the openal.cs file in the Sandbox). Or can I separate the music and effects channels with the VolumeChannel field in AudioAsset?
I'm guessing most, if not all, of these bugs are from my own doing so thanks in advance for helping point out any mistakes I have made in my script.
About the author
#2
Having an AudioAsset with just the fields of AssetName, AssetAutoUnload, and AudioFile returns a nice integer handle of 1 , 2 , 3 , etc. (when using alxPlay)
Having an AudioAsset with the above 3 fields plus Looping="true" returns a negative integer for a handle. The source description for the audio handle states this handle should only be positive.
Having an AudioAsset with the field Streaming="true" returns a positive integer, but it is a huge number like 10378613.
The field VolumeChannel kept the low positive integer assignments 2, 3, 4, etc.
02/27/2013 (4:11 am)
I've done some more testing. The issue with the negative audio handle is coming from the AudioAsset.Having an AudioAsset with just the fields of AssetName, AssetAutoUnload, and AudioFile returns a nice integer handle of 1 , 2 , 3 , etc. (when using alxPlay)
Having an AudioAsset with the above 3 fields plus Looping="true" returns a negative integer for a handle. The source description for the audio handle states this handle should only be positive.
Having an AudioAsset with the field Streaming="true" returns a positive integer, but it is a huge number like 10378613.
The field VolumeChannel kept the low positive integer assignments 2, 3, 4, etc.
#3
EDIT
They did not. Or rather, some of the work in progress did. I'll drop a pull request....
02/27/2013 (10:55 am)
That's interesting. I thought I had that nailed down because the issues you describe were all symptoms of problems that I fixed back in November/December. I'll check that those changes actually made it in....EDIT
They did not. Or rather, some of the work in progress did. I'll drop a pull request....
#4
The menu music pauses and resumes correctly. If you set the asset Looping="1" you get a negative number for the handle because when a sound is set to loop the handle has a specific bit set to tell the system it is looping. I tested this with the title music asset and it seems to work as expected.
The sound effect does not pause, but I haven't fiddled with adding a pause button for the sound effects.
Hopefully Melv and Mitch will get a look at these changes soon and get them into the engine. In the mean time, I can email you the specific files if you like - just drop me a line.
02/27/2013 (1:42 pm)
I pulled down the audio toy and tested with the sound updates I mentioned.The menu music pauses and resumes correctly. If you set the asset Looping="1" you get a negative number for the handle because when a sound is set to loop the handle has a specific bit set to tell the system it is looping. I tested this with the title music asset and it seems to work as expected.
The sound effect does not pause, but I haven't fiddled with adding a pause button for the sound effects.
Hopefully Melv and Mitch will get a look at these changes soon and get them into the engine. In the mean time, I can email you the specific files if you like - just drop me a line.
#5
The reference descriptions in audioFunctions.cc should probably be updated as well, if negative integer handles are required for looping.
There's also the audioDatablock files in the audio folder, are they still needed or are they now obsolete?
02/27/2013 (2:14 pm)
Thanks for submitting an update that fixes these issues, much appreciated. I saw the pull request, I can grab the files from your Github repo.The reference descriptions in audioFunctions.cc should probably be updated as well, if negative integer handles are required for looping.
Quote:ConsoleFunction(alxPause, bool, 2, 2, "( handle ) Use the alxPause function to pause a currently playing sound as specified by handle.n"
"@param handle The ID (a non-negative integer) corresponding to a previously set up sound source.n"
"@return No return value.n"
"@sa alxIsPlaying, alxPlay, alxStopAll")
There's also the audioDatablock files in the audio folder, are they still needed or are they now obsolete?
#6
As for the audioDatablock source files, I don't know - they might be referenced in the audioAsset sources but I doubt it. They are probably superfluous now.
02/27/2013 (7:08 pm)
<shrug> I suppose it couldn't hurt.... As for the audioDatablock source files, I don't know - they might be referenced in the audioAsset sources but I doubt it. They are probably superfluous now.
#7
02/28/2013 (5:39 am)
I tested the changes and everything works now as well. Thanks again.
Torque Owner Richard Ranft
Roostertail Games
I wrenched on this for almost two weeks to get it to behave because it would work fine on my dev rig but QA would report issues that I couldn't reproduce.
On another note, yes you can separate music and effects to different channels using the VolumeChannel field, but it only allows you to control the volume of up to 32 sound channels (0 - 31). It does not affect play, stop, pause or anything else. And since one should be using audio handles to stop, pause or unpause sounds, this makes sense.
alxPlay() should return a "handle" that you would then use to stop, pause or unpause a single audio buffer (created by alxPlay() and identified by said handle). alxStopAll() stops everything, of course. I didn't implement alxPauseAll() though this would have been useful in some cases. alxStop() invalidates the buffer handle, so in this case alxPlay() should be called again and the new handle kept for reference. alxPause() does not invalidate the handle, and alxUnPause(handle) should resume playback of the sound referenced by the handle. alxPlay() is supposed to do this for paused buffers and return the same handle, but honestly I haven't looked at it in months.