HaxeFlixel / flixel

Free, cross-platform 2D game engine powered by Haxe and OpenFL
https://haxeflixel.com/
MIT License
1.98k stars 439 forks source link

FlxSound chipmunk problem #524

Closed xraven13 closed 10 years ago

xraven13 commented 11 years ago

Hey !

When I play sound on windows target it's playing few times faster then usual, experimental version of Flixel. On Flash it all runs okay. Any idea what could be causing this ? File is .mp3 format.

Thx :)

--- Want to back this issue? **[Place a bounty on it!](https://www.bountysource.com/issues/1022017-flxsound-chipmunk-problem?utm_campaign=plugin&utm_content=tracker%2F254189&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F254189&utm_medium=issues&utm_source=github).
Gama11 commented 11 years ago

Pretty sure you should use .wav instead.

Native targets / mobile: .wav Flash: .mp3 HTML5 currently lacks sound support.

AndreiRegiani commented 11 years ago

But is it appropriated to use .wav format for music files (2 minutes+)??? My file went from 500kb to 5mb.

There's still other problem with audio, there's no way to preload them, so the first time it plays it freezes the game to load (~1 second) for each sound. I suggest to implement this Sound Manager to the framework: https://gist.github.com/skrivener/5941426

Beeblerox commented 11 years ago

You should use mp3 for music. Maybe the problem is in music bitrate? Can you try to experiment with it?

xraven13 commented 11 years ago

Ok, tested it.

I was using music with bitrate 96kbps, when I use 320kbps then it's ok.

But there is a other problem, each time I play some sound effect looped music restarts ?

2013/7/20 Zaphod notifications@github.com

You should use mp3 for music. Maybe the problem is in music bitrate? Can you try to experiment with it?

— Reply to this email directly or view it on GitHubhttps://github.com/HaxeFlixel/flixel/issues/524#issuecomment-21296908 .

sergey-miryanov commented 11 years ago

AFAIK, you need to use FlxG.sound.play to play sound effect, not FlxG.sound.playMusic.

xraven13 commented 11 years ago

I was doing it this way for both cases :

var flxSound:FlxSound = new FlxSound(); flxSound.loadEmbedded( sound, isLooped); flxSound.volume = vol; flxSound.play();

2013/7/29 Sergey Miryanov notifications@github.com

AFAIK, you need to use FlxG.sound.play to play sound effect, not FlxG.sound.playMusic.

— Reply to this email directly or view it on GitHubhttps://github.com/HaxeFlixel/flixel/issues/524#issuecomment-21716698 .

Gama11 commented 11 years ago

@xraven13 Any reason you're chosing this rather complicated approach instead of just calling FlxG.sound.play()? I myself only create an instance of FlxSound like that if I need advanced control over the sound.

xraven13 commented 11 years ago

It doesn't matter, it's still a bug. And yes, sometimes I need this function.

This only happens on windows target, on flash it works fine.

So to repeat problems are :

2013/7/29 Gama11 notifications@github.com

@xraven13 https://github.com/xraven13 Any reason you're chosing this rather complicated approach instead of just using FlxG.sound.play()? I myself only create an instance of FlxSound like that if I need advanced control over the sound.

— Reply to this email directly or view it on GitHubhttps://github.com/HaxeFlixel/flixel/issues/524#issuecomment-21716928 .

Gama11 commented 11 years ago

@xraven13 Couldn't reproduce this bug, I've been using the Project Jumper demo and the jumping sound in Player.hx. No difference between using FlxG.sound.play() and creating a new instance of FlxSound.

How do you play the music? FlxG.sound.playMusic()? Please provide more details / code. The sound files themselves might also be relevant, in case you can share them.

What I did hoewer notice is a crash when closing the game in both neko and windows when playing a looped soundeffect.

xraven13 commented 11 years ago

Yes, I also get the crash.

As I posted above, this is the code for both music and sound :

var flxSound:FlxSound = new FlxSound(); flxSound.loadEmbedded( sound, isLooped); flxSound.volume = vol; flxSound.play();

Though now I made my own classes , I have special sound class, and sound manager that keeps the sounds organized, it recycles them. I still have the same problem there, I plan to post it on HaxeFlixel forums, though I think they should be "fixed" by some real programmer because it doesn't look really nice. If you want I can post it here, so you guys can tweak it and add to Flixel later. I have functions that mute all music, pause them, recycle them, fade them etc.

2013/7/29 Gama11 notifications@github.com

@xraven13 https://github.com/xraven13 Couldn't reproduce this bug, I've been using the Project Jumperhttps://github.com/HaxeFlixel/flixel-demos/tree/master/Platformers/Project%20Jumperdemo and the jumping sound in Player.hxhttps://github.com/HaxeFlixel/flixel-demos/blob/master/Platformers/Project%20Jumper/source/com/chipacabra/jumper/Player.hx. No difference between using FlxG.sound.play() and creating a new instance of FlxSound.

How do you play the music? FlxG.sound.playMusic()? Please provide more details / code. The sound files themselves might also be relevant, in case you can share them.

What I did hoewer notice is a crash when closing the game in both neko and windows when playing a looped soundeffect.

— Reply to this email directly or view it on GitHubhttps://github.com/HaxeFlixel/flixel/issues/524#issuecomment-21721557 .

sergey-miryanov commented 11 years ago

Try to change format of you sound assets - .wav files for sound effects and .mp3 for music.

Look there commen from @Beeblerox https://github.com/HaxeFlixel/flixel/issues/276#issuecomment-18703554

xraven13 commented 11 years ago

Is there any plan from Haxe team to fix this ? Is it even possible ?

JoySoundManager : http://pastebin.com/yGhjhTAt JoySound : http://pastebin.com/SSt4k0TC

Enjoy :)

2013/7/29 Sergey Miryanov notifications@github.com

Try to change format of you sound assets - .wav files for sound effects and .mp3 for music.

276https://github.com/HaxeFlixel/flixel/issues/276#issuecomment-18703554

— Reply to this email directly or view it on GitHubhttps://github.com/HaxeFlixel/flixel/issues/524#issuecomment-21722027 .

AndreiRegiani commented 11 years ago

Did some tests with official FlxG.sound and " @xraven13 's SoundManager Joy classes ", on iPhone 5:

1) On both implementations: the first time the sound is played it freezes the game for a some mile seconds, then the same sound can be played normally. This outputs on Xcode log (as first time playing): "AudioStreamBasicDescription: 2 ch, 44100 Hz, 'lpcm' (0x00000029) 32-bit little-endian float, deinterleaved" Don't we just need to preload the sounds before playing?

2) Using 320kbps solved music playing faster or crashing.

3) Had this same problem with FlxG.sound: "music restarts each time sfx plays".

Gama11 commented 11 years ago

@AndreiRegiani Do those issues only appear on iOS for you, or also on other targets?

AndreiRegiani commented 11 years ago

More testing:

--- Note: Seems it necessary to delete the exports/***/ folder and recompile the project for changed audio files be updated on the binary (??).

AndreiRegiani commented 11 years ago

Update: using music .mp3 with 128 bit-rate, .wav for all effects worked for me without above issues on Mac and iOS.

AndreiRegiani commented 11 years ago

A summary for the dev-team: Everything works fine when using .mp3 at correct bit-rate (for me was 128kbps, but 320kbps worked for @xraven13) .mp3 for music only, and .wav for all sounds effects.

Not following these recommendations, cause these issues:

ghost commented 11 years ago

@AndreiRegiani https://github.com/HaxeFlixel/flixel/issues/524#issuecomment-21759634 About Issue 3: "wav" and "ogg" files are embedded as "sound" while "mp3" files are embedded as "music". And as the docs say, music gets streamed, not loaded. In this case, using "mp3" as music will cause it to stream from disk. Also, loading a huge music directly into memory is not a good idea. I hope these rules work fine on mobile platforms. It wouldn't be nice to have an app crash because of high memory usage.

Reference: http://www.openfl.org/archive/developer/documentation/key-concepts/assets/