Can Not Play Multiple Sounds [XAudio2]

For questions about using Classic.

Post » Tue Jun 21, 2011 7:13 am

I did some reading (yes, I are a college student) and found that to keep sounds with an EXE file is to add them in resources. This worked for my background music:

+ System: Start of layout
-> XAudio2: Load resource "Skillet - Hero (instrumental).wav" to channel 1 (Loop)
-> XAudio2: Play music "Skillet - Hero (instrumental).wav"

That plays the music. However, it seems I get a conflict when I use this for a laser:

+ MouseKeyboard: On key Space pressed
-> System: Create object Bullet on layer 1 at (0, 0) from Hero 's image point 1
-> XAudio2: Load resource "imphenzia_soundtrack_laser36.wav" to channel 1 (No loop)
-> XAudio2: Play music "imphenzia_soundtrack_laser36.wav"

That and three other laser sounds. Same as above just with different files.

Now, all four laser sounds will play together but not the music. Disable those four lasers, and music plays. Music plays but if laser sounds enabled and a shot is fired, music ends.

I have tried changing each to channel 2 and leave the other 1, but nothing changes.

I like to get these sounds working while music is playing, and then get explosion sounds and such in there.

Any thoughts?

Thank you.
B
5
S
1
G
1
Posts: 157
Reputation: 1,219

Post » Tue Jun 21, 2011 7:31 am

Try Audiere plugin for sound and music - it's less confusing to use.

Audiere Sound
ImageImageImageImage
B
140
S
58
G
36
Posts: 2,547
Reputation: 31,170

Post » Tue Jun 21, 2011 8:33 am

Xaudio isn't designed to use wav for music. Try mp3 instead.
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Wed Jun 22, 2011 7:01 am

I will try that other plugin out today and let you know. Thanks. Right now, with XAudio2, it plays the sounds or the music. Not both at the same time. The sound effects kill the music off. I will see if Audiere can make them all play together.
B
5
S
1
G
1
Posts: 157
Reputation: 1,219

Post » Wed Jun 22, 2011 1:30 pm

Using XAudio2 isn't as complicated as it is stated.

XAudio uses 2 independant architectures, distinguished by the keywords 'sound' and 'music'.

'music' is used to play a file (either from disk or resource). The file format should preferably be mp3, but wav and wma are also playable. It is only playing one file at a time, doesn't know about channels and hasn't much options to alter anything while playing.

'sound' is a bunch of sound channels that can be played simultaneously, with many options to change the behavior of audio while playing. Preferable sound format is ogg vorbis, but wav is also supported. It is used by loading a sound file to a channel (binding it to that channel) and from there on give orders to the channel (not the sound). As soon as a sound file on a channel is fully played (which never happens if the channel is looped, or the position always set to somewhere before the end of the sound) it is released from the channel and any try to play it again will produce nothing but silence.

In your example you mixed both architectures, and that might have caused your problems. To play a sound loaded to a channel, you don't use the action 'play music' but 'play channel':

+ System: Start of layout
-> XAudio2: Load resource "Skillet - Hero (instrumental).wav" to channel 1 (Loop)
-> XAudio2: Play channel 1

or

+ System: Start of layout
-> XAudio2: Play music from resource "Skillet - Hero (instrumental).wav"

If you decide to use the first way, then channel 1 is bound to "Skillet - Hero (instrumental).wav", if you later on load another sound to the same channel, it replaces "Skillet - Hero (instrumental).wav". To avoid that, use another channel:

+ System: Start of layout
-> XAudio2: Load resource "Skillet - Hero (instrumental).wav" to channel 1 (Loop)
-> XAudio2: Play channel 1

+ MouseKeyboard: On key Space pressed
-> System: Create object Bullet on layer 1 at (0, 0) from Hero 's image point 1
-> XAudio2: Load resource "imphenzia_soundtrack_laser36.wav" to channel 2 (No loop)
-> XAudio2: Play channel 2

As you can see it isn't very complicated, if you just keep in mind what architecture you are using, and how it is intended to work.

EDIT: Made a mistake.
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Thu Jun 23, 2011 1:30 am

tulamide, thank you for clearing that up with me. It works well now. I also found these two comments of yours quite pleasing:

"As you can see it isn't very complicated..."
"EDIT: Made a mistake."

Was entertaining to me.

newt, I tried MP3 but they do not play. I converted to WAV to play and will definitely learn more as time goes on. I tried the way even as tulamide has shown above, but MP3 not play. An issue i can deal with later.

shinkan, will still keep this plugin in mind. Never know when it may come in handy.
B
5
S
1
G
1
Posts: 157
Reputation: 1,219

Post » Thu Jun 23, 2011 6:42 pm

[quote="GSPforChrist":2c2w2t2s]tulamide, thank you for clearing that up with me. It works well now. I also found these two comments of yours quite pleasing:

"As you can see it isn't very complicated..."
"EDIT: Made a mistake."

Was entertaining to me.[/quote:2c2w2t2s]
:D
I'm glad it helped and was amusing at the same time - that's entertainment :lol:

[quote="GSPforChrist":2c2w2t2s]newt, I tried MP3 but they do not play. I converted to WAV to play and will definitely learn more as time goes on. I tried the way even as tulamide has shown above, but MP3 not play. An issue i can deal with later.[/quote:2c2w2t2s]
mp3 should work, when using 'music'-actions.
Try this in a fresh cap that you saved to the same folder where your 'some.mp3' is stored:
+ Start of layout
-> Play music from file AppPath & "some.mp3"

If it works try the same file as resource.

Another thing could be that some formats may not be recognized. You could create some mp3 files with joint stereo, normal stereo, mono, vbr and fixed bitrate.
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 1 guest