Simultaneous sounds possible?

XanMag
15 Jul 2015, 17:37I have a section in my game where a large crowd is cheering on an execution. I currently have a bunch of Run Script after one turn set up inside each other.
I know it is a STUPID way to do it, but here it is.
When I test the game, the sound that I have set to loop while the player is in this room (protest.mp3) is cut off by the next sound I want to play. Is there a way to have the original sound play the entire time and have the smaller sounds play after each turn?
I have a lot of experience working with sound mixing programs (Acoustica & Audacity) so I could create one track list instead of multiples, but then it is not synced with player turns (which is crucial here). I guess I could create multiple tracks that include the same background noise that I want, but then it will sound choppy after each turn and I don't have the patience to cut/splice it exactly as I want. Thanks for the input.
EDIT: I have been toying around with it and I can play a YouTube video with sound AND my main sound at the same time. I can open two tabs in freesound and play two .wavs at the same time too. Does that mean, within Quest, I can't play two audio files at the same time but I can play a youtube and an audio file simultaneously? Why? Thanks!
XanMag
I know it is a STUPID way to do it, but here it is.
msg ("<br/>You take a chance and slowly creep into the commons area. You look around and see a gathering of about 50-60 Dingoes near the northwest corner of the room. They appear to be surrounding a stage and seem quite worked up. On the stage are two men. One tall, fit looking man with the evilest of expressions and the other a monster of a man, one of the largest you've ever seen looks beaten and empty.<br/>")
play sound ("protest.mp3", false, true)
if (game.pov.parent = Commons) {
SetTurnTimeout (2) {
msg ("You are distracted by the speaker on stage. \"...and it brings us to this moment, Dingoes!\"")
play sound ("approval1.wav", false, false)
SetTurnTimeout (1) {
msg ("\"I am Hailu, Sarlashkar of the Dingo Nation!\"")
play sound ("cheer1.wav", false, false)
SetTurnTimeout (1) {
msg ("\"And here,\" Hailu points at the downcast man kneeling before him, \"We have Hercules Mongo!\"")
play sound ("kill him chant.mp3", false, false)
SetTurnTimeout (1) {
msg ("\"We cannot tolerate insubordination here! He must be dealt with!\" yells the Sarlashkar.")
play sound ("yes crowd.mp3", false, false)
SetTurnTimeout (1) {
msg ("\"Mongo has chosen betrayal. Betrayal is NOT an option!\" Hailu continues.")
play sound ("crowd2.wav", false, false)
SetTurnTimeout (1) {
msg ("\"Remember this Dingoes! Remember this day!\"")
SetTurnTimeout (1) {
play sound ("man cry.wav", false, false)
msg ("\"One of your own. Hercules Mongo. The strongest man here... even he cannot question Doctor Dingo and the Nation!\" At this, Hecules cowers even further on his knees and begins to whimper.")
}
}
}
}
}
}
}
}
When I test the game, the sound that I have set to loop while the player is in this room (protest.mp3) is cut off by the next sound I want to play. Is there a way to have the original sound play the entire time and have the smaller sounds play after each turn?
I have a lot of experience working with sound mixing programs (Acoustica & Audacity) so I could create one track list instead of multiples, but then it is not synced with player turns (which is crucial here). I guess I could create multiple tracks that include the same background noise that I want, but then it will sound choppy after each turn and I don't have the patience to cut/splice it exactly as I want. Thanks for the input.
EDIT: I have been toying around with it and I can play a YouTube video with sound AND my main sound at the same time. I can open two tabs in freesound and play two .wavs at the same time too. Does that mean, within Quest, I can't play two audio files at the same time but I can play a youtube and an audio file simultaneously? Why? Thanks!
XanMag
InfectedBehaviour
16 Jul 2015, 07:38I also have some experience in sound mixing. I just find, if you want it to sound perfect, You need to play the game while mixing the two mp3's. It's going to take some time till you get it spot on. When you add it to your game, Then test it if it does sound and work the way you want it to. Timing is everything with mixing sounds.
If there is another way to add sound while the main sound plays. I'd also like to know that lol.
If there is another way to add sound while the main sound plays. I'd also like to know that lol.
adammadam
16 Jul 2015, 08:35maybe you could use a couple of timer scripts to sync it together a bit better, have two audio files one with the constant background noise and one with the background noise with cheer, fade in the beginnings and fade out the ends of the audio files, so they're not choppy, it will mean the crowd cheering will quieten down for a second or whatever but better than being choppy. When the first audio file is playing also have a timer and have a flag set and unset, so it can set right when the audio file is fading out and it can unset just before it begins again. Then have the second audio file with the cheer sound set up on a timer, the timer will activate as soon as the player does whatever they do to make the crowd cheer, and then when the timer detects that the flag is on this is when it will play the sound (switch the audio files).

Pertex
16 Jul 2015, 11:02Its possible with the audio tag of html5. Have a look at the end of this thread: viewtopic.php?f=3&t=4632

XanMag
17 Jul 2015, 17:42For those that stumble on to this requesting the same thing...
Use this code (just copy-paste) to play your second sound on top of your existing sound. Obviously, you'd have to insert your own file name in place of my "laughing people.wav".
It's a "print expression" script in GUI.
Credit is totally not mine. I stole the code from Silver, edited by Jay.
I assume that'll work for everyone, right? Thanks Pertex, Silver, and Jay! You are awesome yet again!
If anyone else deserves credit for that, I'll gladly edit my post to acknowledge. Cheers!
EDIT: Weird thing... maybe someone can help me out here. Some of the sounds will play using this code and some will not?!? It does not appear related to file type (.wav, .mp3) or size of file. I've tried about 15 different sound clips and it seems about half of them work and half of them don't. I'd like to learn something here, so if anyone knows why this is happening and could help me out, I'd greatly appreciate it!! Thanks!
XanMag
Use this code (just copy-paste) to play your second sound on top of your existing sound. Obviously, you'd have to insert your own file name in place of my "laughing people.wav".
It's a "print expression" script in GUI.
"You enter the room and you hear people laughing! <audio src=\"" + GetFileURL("laughing people.wav") + "\" autoplay></audio>"
Credit is totally not mine. I stole the code from Silver, edited by Jay.

I assume that'll work for everyone, right? Thanks Pertex, Silver, and Jay! You are awesome yet again!
If anyone else deserves credit for that, I'll gladly edit my post to acknowledge. Cheers!
EDIT: Weird thing... maybe someone can help me out here. Some of the sounds will play using this code and some will not?!? It does not appear related to file type (.wav, .mp3) or size of file. I've tried about 15 different sound clips and it seems about half of them work and half of them don't. I'd like to learn something here, so if anyone knows why this is happening and could help me out, I'd greatly appreciate it!! Thanks!
XanMag

XanMag
17 Jul 2015, 19:02In addition to...
In the tutorial game that I am working on (as I figure this stuff out bit by bit), I've got a background song play as the player leaves to enter the 'complex sound room' (after leaving room, play sound). Within that room I have four smaller rooms. I've got it set up so that a player can enter a 'laughing room' and they hear people laughing AND the background music. If players leaves 'laughing room' back to the 'complex sound room', I would like for only the laughing to stop.
What code can I have to stop a sound called by this script?
If I simply use 'stop sound' it stops all sound (background music included) which I do not want. Help is appreciated!
XanMag
In the tutorial game that I am working on (as I figure this stuff out bit by bit), I've got a background song play as the player leaves to enter the 'complex sound room' (after leaving room, play sound). Within that room I have four smaller rooms. I've got it set up so that a player can enter a 'laughing room' and they hear people laughing AND the background music. If players leaves 'laughing room' back to the 'complex sound room', I would like for only the laughing to stop.
What code can I have to stop a sound called by this script?
"You enter the room and you hear people laughing! <audio src=\"" + GetFileURL("laughing people.wav") + "\" autoplay></audio>"
If I simply use 'stop sound' it stops all sound (background music included) which I do not want. Help is appreciated!
XanMag

jaynabonne
18 Jul 2015, 17:29Following the lead of this page: http://stackoverflow.com/questions/1483 ... p-function
if you give the <audio> tag an Id, then you can refer to it in JavaScript. So change your line to something like this;
That gives the audio tag an id of "laughing". Then you should be able to do something like this (untested!):
In case it's helpful, the pure JS for that is just
You need the [0] because the jQuery selection returns an array, and the "stop" method is on the DOM element itself, not the jQuery result.
On another note, since you're playing the audio inline in the text, if you ever clear the screen, the audio elements will go away as well (and I imagine the sound would stop). Not that you want to, but in case you ever run into that...
if you give the <audio> tag an Id, then you can refer to it in JavaScript. So change your line to something like this;
"You enter the room and you hear people laughing! <audio id=\"laughing\" src=\"" + GetFileURL("laughing people.wav") + "\" autoplay></audio>"
That gives the audio tag an id of "laughing". Then you should be able to do something like this (untested!):
JS.eval("$('#laughing')[0].stop()")
In case it's helpful, the pure JS for that is just
$('#laughing')[0].stop()
You need the [0] because the jQuery selection returns an array, and the "stop" method is on the DOM element itself, not the jQuery result.
On another note, since you're playing the audio inline in the text, if you ever clear the screen, the audio elements will go away as well (and I imagine the sound would stop). Not that you want to, but in case you ever run into that...

XanMag
19 Jul 2015, 01:21I will test it soon and let you know how it works. Thanks again.

XanMag
24 Jul 2015, 01:19I tried your method (below), Jay, and the result is identical. The laughing does not stop when exiting the laughing room.
When I enter the room:
and when I exit the room:
I tinkered with the code and they just keep laughing at me!!!
Also, I am still unsure why some of the secondary clips play just fine while others do not?!? I can't make sense of that bit.
When I enter the room:
msg ("You enter the room and you hear people laughing! <audio id=\"laughing\" src=\"" + GetFileURL("laughing people.wav") + "\" autoplay></audio>")
and when I exit the room:
eval ("$('#laughing')[0].stop()")
I tinkered with the code and they just keep laughing at me!!!

Also, I am still unsure why some of the secondary clips play just fine while others do not?!? I can't make sense of that bit.

jaynabonne
24 Jul 2015, 06:40Would you be able to either post or email me a copy of the game? (Though I guess sounds would be a problem - though I could substitute my own.)
One thing to try: when running the game, choose "HTML Tools" at the top and then click on Console and see if there are any errors.
I'll see if I can work up my own sample, if I am not able to get yours.
One thing to try: when running the game, choose "HTML Tools" at the top and then click on Console and see if there are any errors.
I'll see if I can work up my own sample, if I am not able to get yours.

XanMag
26 Jul 2015, 13:33jaynabonne wrote:Would you be able to either post or email me a copy of the game? (Though I guess sounds would be a problem - though I could substitute my own.)
One thing to try: when running the game, choose "HTML Tools" at the top and then click on Console and see if there are any errors.
I'll see if I can work up my own sample, if I am not able to get yours.
I have sent you the two game files with my audio problems. If you want to start here and comment on my stupidity, I will eagerly anticipate your criticism! The code below is the function I call when entering the room. I believe everything is coded correctly, but some of those sounds just aren't playing and I have no idea why.
<function name="execution"><
Thanks in advance.

jaynabonne
26 Jul 2015, 14:53It turns out that there is no "stop" as such - you have to use "pause" instead. So my bad there.
I went into more detail in an email response about how the <audio> tags get duplicated when you re-enter the same room, and that a way to do that might be to output all the sounds up front (not autplayed) and then just "play" the desired one on room entry and "pause" it on exit.
Another thing to note (which just registered in my brain): if you do play, pause and then play again, the sound will resume where it left off (it was just paused) instead of starting over from the beginning. If that is undesired, then you can just do this (untested):
I went into more detail in an email response about how the <audio> tags get duplicated when you re-enter the same room, and that a way to do that might be to output all the sounds up front (not autplayed) and then just "play" the desired one on room entry and "pause" it on exit.
Another thing to note (which just registered in my brain): if you do play, pause and then play again, the sound will resume where it left off (it was just paused) instead of starting over from the beginning. If that is undesired, then you can just do this (untested):
eval ("$('#laughing')[0].pause()")
eval ("$('#laughing')[0].currentTime=0")
Silver
02 Aug 2015, 06:39I came across further issues with the sound solution iirc that I can't fully remember. It's to do with what formats are compatible with the different browsers. Oh yeah that's it - if you play MP3 using html5 it won't trigger the sounds in an offline game as chromium doesnt have the license for it. The outcome was I used MP3 if Quest was triggering the sound (background looping sound - it will play this as it uses net framework iirc) but for foreground sounds triggered using html5 I'd convert the files to ogg vorbis which had the most compatibility across browsers including chromium for offline play. You have to add the .ogg file extension to the list of files the game will use.
Silver
02 Aug 2015, 06:53And don't use .wav format. It is approximately ten times the size of compressed audio and you will hit a ceiling in terms of game size (the maximum size is pretty generous, but .wav audio will soon burn it up).
Silver
03 Aug 2015, 07:26I just used this page which has a compatibility chart if you scroll down a bit.
https://developer.mozilla.org/en-US/doc ... ia_formats
https://developer.mozilla.org/en-US/doc ... ia_formats

XanMag
09 Aug 2015, 13:25Silver wrote:You have to add the .ogg file extension to the list of files the game will use.
I assume to do that I do the following - I stumbled upon Alex's post and he said "As of Quest 5.6 you can update the publishfileextensions attribute on the game element to set which file extensions are included, so you can just add *.ogg to this." I added the *.ogg to the publishfileextensions attribute and the .ogg files didn't play again. And I have updated to Quest561.
Also, should I go back through and convert all sounds files I have in my game to .ogg files? I have converted all of my .mp3 and .wav files in this sound sequence to .ogg.
Thanks.
XanMag
Silver
15 Aug 2015, 10:22If you're using Quest to trigger the sound which I would advise doing for looping sounds (atmospherics) it has to be MP3. Because it uses .net framework to handle the audio and doesn't use chromium or any other browser for the sound. Ogg isn't compatible doing it that way. It's only when you're using the html5 code to trigger single shot sounds (doors opening, floorboards creaking etc) that you need the audio to be .ogg as chromium won't play MP3 and .ogg is compatible with all modern browsers apart from Explorer and Safari needs a plugin.
It's complicated. Took me weeks to work all that out.
On top of that audio doesn't always work perfectly. Sometimes a loop sound will trigger but fail to loop or other sounds won't play first time but will play the second. I don't know the reason for that. I thought about trying to fetch the sound at an earlier point to load it into the cache using getfileurl (or whatever) but havent experimented with that yet.
It's complicated. Took me weeks to work all that out.
On top of that audio doesn't always work perfectly. Sometimes a loop sound will trigger but fail to loop or other sounds won't play first time but will play the second. I don't know the reason for that. I thought about trying to fetch the sound at an earlier point to load it into the cache using getfileurl (or whatever) but havent experimented with that yet.

XanMag
17 Aug 2015, 19:26So... Xanadu walks into a room... Cue background crowd sound - (MP3, ogg, other?)
Turn script cues additional sounds - chanting, voices, beheading, etc - while background sound is playing - (MP3, ogg, other?)
All sounds stop when room is exited.
I haven't messed with it recently as I'm currently working on my ending - trying to save this blasted sound issue for last. I'm just trying to get a head forward before I tackle it again.
Or... And as a last resort, I could scrap the whole sound bit but I think it'll make the climax a bit stale without the sound. Let me know. Thanks silver. Thanks all.
Turn script cues additional sounds - chanting, voices, beheading, etc - while background sound is playing - (MP3, ogg, other?)
All sounds stop when room is exited.
I haven't messed with it recently as I'm currently working on my ending - trying to save this blasted sound issue for last. I'm just trying to get a head forward before I tackle it again.
Or... And as a last resort, I could scrap the whole sound bit but I think it'll make the climax a bit stale without the sound. Let me know. Thanks silver. Thanks all.
Silver
25 Aug 2015, 16:26Background sound (looping) do the vanilla way using quest command and MP3.
Foreground sounds trigger using html5 code in msg tags and use ogg format.
Foreground sounds trigger using html5 code in msg tags and use ogg format.