Jump to content


Photo

SM2 - Enhanced audio for HTML5 Games


  • Please log in to reply
27 replies to this topic

#1 Oracizan

Oracizan

    Mutant Dreamer

  • GMC Member
  • 543 posts
  • Version:GM:Studio

Posted 04 February 2012 - 10:19 PM

SM2
A wrapper for Sound Manager 2


The title says it all. Sound Manager 2 is an audio system designed to provide javascript & HTML5 with the audio capabilities of Flash, from Schillmania. The main site, along with documentation for the main program, is here.

This extension is pure javascript/flash, so it is pretty much guaranteed to work cross-browser. Not only does it do the basics of what GM:HTML5's currently flaky audio system can do, it also provides additional functionality beyond GM's current capabilities:

Attributes

Basic:

- Plays '.ogg' and '.mp3'
- Loops sounds
- Very simple and intuitive
- Check to see if sound is playing
- Change volume of sound
- Change pan of sound

Advanced:

- The ability to pause a sound.
- The ability to mute a sound.
- The ability to change the pan/volume of a sound while it is playing.
- The ability to begin playing a sound from its middle.
- The ability to check the length of a sound.

Disadvantages:

- Inability to use sound effect (reverb, echo, etc.)
- Flashblockers will potentially render your game mute. This is a serious advantage that HTML5 has over Flash, because this is one extra 'issue' users could have with your program.

Functions

  • sm2_init(Flash_Version): Initializes the sound system. Flash_Version tells SoundManager 2 which version of Flash to use and should equal 8 or 9. Version 9 of flash allows 'multi-shot' capabilities (multiple instances of the same sound playing at once).
  • sm2_isready(): Returns an integer that tells whether the sound system has finished initializing. 0 = not ready, 1 = ready, -1 = error initializing. -1 is usually due to Flashblockers.
  • sm2_isok(): The sound system is healthy. See main Sound Manager 2 website for more details.
  • sm2_reboot(): Reboots the sound system. See main Sound Manager 2 website for more details.
  • sm2_create_sound(str_name,str_url): Loads a sound into the system. str_name is the name you will use to access it, and str_url is the name of your sound file(s). str_url should not include the file extensions, and you should include two sound files (.mp3 and .ogg) of the same name with your game.
  • sm2_delete_sound(str_name): Removes a sound from the system.
  • sm2_play_sound(str_name): Plays a sound once.
  • sm2_loop_sound(str_name): Loops a sound. (This is a hack on my part and not entirely perfect. For shorter sounds it will occasionally misstep but for long sounds like music you should be fine.)
  • sm2_stop_sound(str_name): Stops a sound that is playing.
  • sm2_pause_sound(str_name): Pauses a sound at it's current position.
  • sm2_resume_sound(str_name): Resume a paused sound from it's current position.
  • sm2_mute_sound(str_name): Mutes a sound. It is 'playing' in the background but cannot be heard.
  • sm2_unmute_sound(str_name): Unmutes a sound.
  • sm2_mute_sound(str_name): Mutes a sound. It is 'playing' in the background but cannot be heard.
  • sm2_mute_all(): Mutes all sounds.
  • sm2_unmute_all(): Unmutes all sounds.
  • sm2_pause_all(): Pauses all sounds.
  • sm2_resume_all(): Resumes all sounds.
  • sm2_stop_all(): Stops all sounds.
  • sm2_sound_isloaded(str_name): Returns whether a sound is loaded or not.
  • sm2_sound_isplaying(str_name): Returns whether a sound is playing or not.
  • sm2_sound_ismuted(str_name): Returns whether a sound is muted or not.
  • sm2_sound_ispaused(str_name): Returns whether a sound is paused or not.
  • sm2_sound_set_pan(str_name,int_pan): Sets the pan of a sound. int_pan must be between -100 (left) and 100 (right). 0 is default.
  • sm2_sound_set_volume(str_name,int_volume): Sets the volume of a sound. int_volume must be between 0 (min) and 100 (max). 100 is default.
  • sm2_sound_set_position(str_name,int_pos): Sets the position of a sound. This will determine where the sound will start playing from when next used. int_pos must be between 0 and the duration (in milliseconds) of the sound.
  • sm2_sound_get_pan(str_name): Returns the pan of a sound.
  • sm2_sound_get_volume(str_name): Returns the volume of a sound.
  • sm2_sound_get_position(str_name): Returns the position of a sound (in milliseconds).
  • sm2_sound_get_duration(str_name): Returns the duration of a sound (in milliseconds).

The download includes the .GEX extension file and a .GMZ example: Download Link.

Edited by Oracizan, 14 March 2013 - 01:48 AM.

  • 2

#2 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 20911 posts
  • Version:GM:Studio

Posted 04 February 2012 - 10:48 PM

Excellent stuff... I wondered when someone would get round to doing this! Going to give it a try and see how it goes now...
  • 0

#3 haloflooder

haloflooder

    GMC Member

  • GMC Member
  • 35 posts

Posted 06 February 2012 - 09:03 PM

Finally! I was hoping someone would make this compatible for GM HTML5. Going to use this on my latest web game now... I'll come back with some results
  • 0

#4 Smarty

Smarty

    GMC Member

  • Retired Staff
  • 7465 posts
  • Version:GM:Studio

Posted 20 February 2012 - 09:11 PM

Disadvantages:

- Inability to use sound effect (reverb, echo, etc.)
- Flashblockers will potentially render your game mute. This is a serious advantage that HTML5 has over Flash, because this is one extra 'issue' users could have with your program.

You might want to add that those working to release a mobile version of their game will have limited sound support on Android operating systems (not everyone installs Flash), and no support at all on Apple devices.
  • 0

#5 rucodemente

rucodemente

    GMC Member

  • GMC Member
  • 56 posts

Posted 22 February 2012 - 09:49 PM


Disadvantages:

- Inability to use sound effect (reverb, echo, etc.)
- Flashblockers will potentially render your game mute. This is a serious advantage that HTML5 has over Flash, because this is one extra 'issue' users could have with your program.

You might want to add that those working to release a mobile version of their game will have limited sound support on Android operating systems (not everyone installs Flash), and no support at all on Apple devices.

That's not correct at all, Smarty, SM2 uses javascript, and flash as a fallback solution (so to speak).

Obviously, it would be better if audio support in GM:HTML5 was better, which we know not only depends on YoYo but in HTML5 audio "issues".

Yet, it took them ages to solve the sound_loop and sound_isplaying bugs which was kinda frustrating and dissapointing.

Edited by rucodemente, 22 February 2012 - 09:53 PM.

  • 0

#6 alexandervrs

alexandervrs

    GMC Member

  • GMC Member
  • 657 posts
  • Version:GM:Studio

Posted 25 February 2012 - 04:44 PM

Funny how I was thinking of making an audio extension with SoundManager 2 a while ago.
I am not sure about it, but I think SoundManager 2 uses first HTML5 as a playback solution, then Flash, which if that's true then it's bad. Maybe it's the reason I stopped having the idea of turning this into an extension. I can't remember really.

If that's the case, it's bad because HTML5 audio in Chrome is very buggy at the moment with long-standing bugs since around last September. Firefox does not have seamless looping and still has some issues with sound channels as well.
Flash audio is really mature, the playback and looping is exceptional and although not available for mobile platforms it really shines for Windows and Mac.

Although, I might be wrong, should test and see for myself, and I am not sure if you can even set the fallback order yourself in Sound Manager 2.

Edited by alexandervrs, 25 February 2012 - 04:47 PM.

  • 0

#7 GameRoom

GameRoom

    GMC Member

  • GMC Member
  • 778 posts
  • Version:GM:Studio

Posted 28 February 2012 - 01:42 AM

I can't get the example to work. All of the objects and rooms appear blank, and now I don't really know how to fix it not working for my game.
  • 0

#8 GameRoom

GameRoom

    GMC Member

  • GMC Member
  • 778 posts
  • Version:GM:Studio

Posted 01 March 2012 - 10:05 PM

Okay, I found my problem and got it to work, but I noticed that the audio is even worse than the built in system. It lags, only one of any sound can play at once, and the game is mute after I export it.
  • 0

#9 Oracizan

Oracizan

    Mutant Dreamer

  • GMC Member
  • 543 posts
  • Version:GM:Studio

Posted 03 March 2012 - 07:46 PM

Okay, I found my problem and got it to work, but I noticed that the audio is even worse than the built in system. It lags, only one of any sound can play at once, and the game is mute after I export it.


How is SoundManager 2 worse than the built-in system? The built-in system only plays one sound at a time as well, and SM2 makes it simple to load multiple instances of a sound without slowing down the game. Additionally, the only lag that I notice is when you first load a sound into the system. I can't think of why the game would be mute - what do you mean by export? When you run a game, it creates a virtual server on your computer and should act just like it would on a website. I only ask because I don't understand and would like to help if possible.

Of Note: Apparently the latest update for GM:HTML5 includes a backup Flash audio solution. Interesting. I wonder how/when that kicks in? Does it detect when HTML5 is being buggy, or does it just work when HTML5 is not an option at all?
  • 0

#10 Thrage

Thrage

    GMC Member

  • New Member
  • 9 posts
  • Version:GM:HTML5

Posted 05 March 2012 - 12:02 PM

If you have transition problems, try playing the next sound at ~134 milliseconds before the first finishes, though there does still seem to be issues. It's not dead-on with loops, either, but that was mentioned.

There are a lot of good features of this extension, such as the pause/unpause features and the ability to get the position/duration of a sound, as well as continue "playing" a muted track. I can also see applications of, for example, making a screen fade out slowly at the same speed as a sound's duration plays.

While it hasn't really helped me with the issue I'm facing (slightly disconnected looping music), I do appreciate the other things it has to offer. Thank you for making this.

Also, the mute_all and unmute_all functions appear to be missing.

Edited by _178504, 05 March 2012 - 12:38 PM.

  • 0

#11 alexandervrs

alexandervrs

    GMC Member

  • GMC Member
  • 657 posts
  • Version:GM:Studio

Posted 06 March 2012 - 01:15 PM

Apparently the latest update for GM:HTML5 includes a backup Flash audio solution. Interesting. I wonder how/when that kicks in? Does it detect when HTML5 is being buggy, or does it just work when HTML5 is not an option at all?


It does? I noticed the audio sounds smoother, but I can't tell if it's the latest Chrome update fixing its issues or changes in GM.
  • 0

#12 tomasart

tomasart

    GMC Member

  • GMC Member
  • 259 posts

Posted 11 March 2012 - 03:24 PM

the sample works on the browser but not on the safary browser. can i put sound in my html5 games and play it on safary iphone?
  • 0

#13 tomasart

tomasart

    GMC Member

  • GMC Member
  • 259 posts

Posted 11 March 2012 - 03:27 PM

works on iphone 3gs browser but not on iphone 4 browser O_o , i'am stuned don't know what to do....
  • 0

#14 Oracizan

Oracizan

    Mutant Dreamer

  • GMC Member
  • 543 posts
  • Version:GM:Studio

Posted 22 March 2012 - 11:57 PM

tomasart: Okay, I am not an iPhone user and don't know much about how it works. Do you know what the difference might be between the two browsers that is causing the failure?

Smarty: One of the great things about SoundManager 2 is that it incorporates HTML5 audio as well as Flash audio. So in theory, wherever your game works, the sound should work. In theory, of course, because HTML5 audio support is not consistent across all browsers/platforms. That's when the Flash kicks in and serves as the 'saving grace' that gives your program another shot at providing audio. I'm sure that there are situations where neither HTML5 audio nor Flash will work, but I'm assuming that means that the built-in GM audio isn't going to work any better (due to the fact that they also rely on HTML5 audio and Flash).

UPDATE: The main reason I posted. It's been a while, but I added 'multi-shot' support to the extension - a feature that quite a few people have requested/asked about. If you enable Flash 9 support, your program will be able to 'overlap' sounds i.e plays multiple instances of the same sound. I don't know about everyone else, but I'm excited. :yes:
  • 0

#15 tomasart

tomasart

    GMC Member

  • GMC Member
  • 259 posts

Posted 27 March 2012 - 12:25 PM

mmm seems to be that the example now don't work for me. anyone have get it work?

no errors, simple do nothing.

Edited by tomasart, 27 March 2012 - 12:32 PM.

  • 0

#16 waxbulletgames

waxbulletgames

    GMC Member

  • New Member
  • 25 posts

Posted 25 May 2012 - 12:19 PM

HELP!!!!! CAN SOMEONE PLEASE HELP ME!!!!

OK so i tried using this tutorial and it wont work for me. when i try and load it nothing loads. (stuck at 100%). i had the idea it might be the files (java script) are empty because when i compile it says that they weren't found. i downloaded the files off of the sm2 website but the main script sm2.js is actually called sound_manager_2.js. Can someone please give me the working/correct js files or whatever is wrong?
  • 0

#17 Mornez

Mornez

    GMC Member

  • Sandbox Moderators
  • 315 posts
  • Version:GM:Studio

Posted 27 June 2012 - 04:53 PM

This thread has a lot of good information.
  • 0

#18 GameRoom

GameRoom

    GMC Member

  • GMC Member
  • 778 posts
  • Version:GM:Studio

Posted 07 July 2012 - 02:42 AM

Is this discontinued? I'd love to have sound positioning in my game, but the last time I tried it (the most recent version) the sound lagged and had bad quality.
  • 0

#19 ben0

ben0

    GMC Member

  • New Member
  • 24 posts
  • Version:GM:HTML5

Posted 10 August 2012 - 04:56 AM

i used SM2 when I was developing for ImpactJS, and using the same for GM HTML5.

however, that said, if you're going to develop for mobile, SM2 won't work well because it's mainly Flash. The HTML5 degradation works ok, but not on higher end devices. Stick to the standard audio tags on html5

Edited by ben0, 10 August 2012 - 04:56 AM.

  • 0

#20 Lotias

Lotias

    GMC Member

  • GMC Member
  • 1132 posts
  • Version:GM:Studio

Posted 14 March 2013 - 01:34 AM

Download link's dead, I really wanted to try this.
  • 0

#21 Oracizan

Oracizan

    Mutant Dreamer

  • GMC Member
  • 543 posts
  • Version:GM:Studio

Posted 14 March 2013 - 01:54 AM

Download link updated. :) Enjoy!
  • 0

#22 Poraxad

Poraxad

    GMC Member

  • New Member
  • 3 posts
  • Version:GM:Studio

Posted 14 March 2013 - 05:45 PM

Has this been tested to work in GameMaker Studio for Windows & Mac exports? Or will I be limited to browser / HTML5 exclusive games?
Thanks :)
  • 0

#23 Oracizan

Oracizan

    Mutant Dreamer

  • GMC Member
  • 543 posts
  • Version:GM:Studio

Posted 14 March 2013 - 06:53 PM

It is a javascript extension, so it will not work for Windows & Mac exports. SM2 is HTML5 only.
  • 0

#24 Mailas

Mailas

    Send in the Mail

  • GMC Member
  • 5680 posts
  • Version:GM:Studio

Posted 14 September 2013 - 04:56 PM

So does this actually work on android/iphone browsers?

I have had very little success getting sound to work properly using on HTML5 mobile browsers the native GM:S functions,

both the new audio engine and the old.

 

Since this uses javascript I'm certain it would work but does anyone know for sure if it does?


  • 0

#25 Debels

Debels

    GMC Member

  • GMC Member
  • 2641 posts
  • Version:GM:Studio

Posted 02 October 2013 - 10:23 PM

So does this actually work on android/iphone browsers?

I have had very little success getting sound to work properly using on HTML5 mobile browsers the native GM:S functions,

both the new audio engine and the old.

 

Since this uses javascript I'm certain it would work but does anyone know for sure if it does?

if it uses flash it wont work on all devices, since most don't support flash and most people are starting to avoid it.


  • 0

#26 Oracizan

Oracizan

    Mutant Dreamer

  • GMC Member
  • 543 posts
  • Version:GM:Studio

Posted 02 October 2013 - 10:55 PM

SoundManager2 allegedly uses HTML5 audio with Flash as a fallback. So a device that does not support flash may still be able to use SM2 properly.


  • 0

#27 karasique

karasique

    GMC Member

  • New Member
  • 5 posts
  • Version:Unknown

Posted 07 December 2013 - 01:12 PM

example now don't work for me. anyone have get it work?
 

ERROR: /html5game/soundmanager2_flash9.swf - loaded 0%

 

upd:

after addin *.swf files in included files, it works! But loop function doesn't work..

 

UPD2:
first time, when i press "Space" playing my sound file works, but second - no.

JavaScript console error - "Uncaught TypeError: Cannot read property 'playState' of undefined"


Edited by karasique, 07 December 2013 - 03:33 PM.

  • 0

#28 Oracizan

Oracizan

    Mutant Dreamer

  • GMC Member
  • 543 posts
  • Version:GM:Studio

Posted 07 December 2013 - 07:11 PM

Hmm. I tried the extension in the latest version of Studio, and I'm getting the same error. This was originally created for GM:HTML5, so I'm surprised that it's incompatible with Studio. When I have time (which might not be for a while), I'll take a look at the extension and see if I can update it for use with Studio.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users