Can Not Play Multiple Sounds [XAudio2]

This forum is currently in read-only mode.
From the Asset Store
2D fighting template based in the game that defined the fighting games genre.
  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Try Audiere plugin for sound and music - it's less confusing to use.

    Audiere Sound

  • Xaudio isn't designed to use wav for music. Try mp3 instead.

  • 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.

  • 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.

  • 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.

  • 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.

    I'm glad it helped and was amusing at the same time - that's entertainment

    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.

    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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)