Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Playing sound with flash.media.Sound.loadPCMFromByteArray generates clicks #2144

Closed
delahee opened this issue Mar 6, 2019 · 12 comments
Closed

Comments

@delahee
Copy link

delahee commented Mar 6, 2019

Hello !

I tried multiple entry points for sound playing api, so far it works realllly well.

One minor hiccups is loadPCMFromByteArray, when I load a file and play it with this API on windows - debug, there is a "click" on sound startup ( I guess some buffers or setup is not okay )
Other entry points like :

new lime.media.AudioSource( lime.media.AudioBuffer.fromBytes( ))
flash.media.Sound.fromFile()
new lime.media.AudioSource( lime.utils.Assets.getAudioBuffer())
flash.media.Sound.fromAudioBuffer( lime.media.AudioBuffer.fromBytes( ))

Do work flawlessly withut glitch/click though so it's really a loadPCMFromByteArray thing.

I'll change my sound path but you may want to have a look at loadPCMFromByteArray
Thanks a lot.

ps : I use openfl for lime-switch stuff

Keep me posted if you want a full reproducible example with source, I'll upload something
Bye and thanks a lot for the awesome work.

gallop_loop.zip

@jgranick
Copy link
Member

jgranick commented Mar 6, 2019

Thanks for letting us know 😄

You said it works if you use AudioBuffer, does your code look at all like this code from loadPCMFromByteArray?

https://github.com/openfl/openfl/blob/develop/src/openfl/media/Sound.hx#L500-L504

@delahee
Copy link
Author

delahee commented Mar 6, 2019 via email

@jgranick
Copy link
Member

jgranick commented Mar 6, 2019

Okay! Thank you 😄

Using your description, I reproduced the problem. Flash has the same problem!

Turns out, the loadPCMFromByteArray method does not expect the WAV file container. When try copying the bytes for your sound to position 736 (which appears to be the offset to the initial data), the click goes away.

Use the loadCompressedDataFromByteArray method and we'll use AudioBuffer.fromFile internally to decode the file and advance automatically around the file headers 😉

@jgranick jgranick closed this as completed Mar 6, 2019
@delahee
Copy link
Author

delahee commented Mar 6, 2019 via email

@delahee
Copy link
Author

delahee commented Mar 6, 2019 via email

@jgranick
Copy link
Member

jgranick commented Mar 6, 2019

I did just add some code to handle the number of samples specified. Perhaps we were adding a click at the end of the file, not before, or weren't handling the offset properly. Does Flash respect the position of the incoming byte object?

@delahee
Copy link
Author

delahee commented Mar 6, 2019 via email

@jgranick
Copy link
Member

jgranick commented Mar 6, 2019

I just made some commits that I think may help 😄

@delahee
Copy link
Author

delahee commented Mar 6, 2019 via email

@delahee
Copy link
Author

delahee commented Mar 7, 2019

Okay I confirm that the bug was caused by position not taken into account. I am testing the fix right now.

@delahee
Copy link
Author

delahee commented Mar 7, 2019

Something else I just discovered, on cpp target haxe.io.input does not advance bytearray position, which was the cause of the bug on my side. I'll investigate.

@delahee
Copy link
Author

delahee commented Mar 7, 2019

And okay I fixed my wav reader to retain byteinput pos rather than byte array pos ( and retrieved your fix ) and everything works.
Thank you very much :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants