Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Music Commands - Set Music File Volume for fading

Author
Message
Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 29th Jan 2013 05:52
I'm trying to use some loops in game and trying to overcome the clicking that occurs when music files repeat.
I was setting the music file to restart playing based on a timer, but the clip gets too close together and I'd like a pause between them. When I add the pause in I get a click when the file replays.

So I thought I'd use a for loop to fade out the music file and then fade in the new music file, but apparently SetMusicFileVolume only works if it is declared before playing the music.
Is this true for everyone or am I doing something wrong?
Does anyone have code they wouldn't mind sharing that fades music in/out?

Does anyone know if there will be more music commands to come for AppGameKit? It seems a bit limited in those aspects.
Thanks!!

JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 29th Jan 2013 07:57
You are correct. The audio commands are very limited.

To stop clicking ensure that first and last samples in your audio file are at a zero-crossing point.

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL
Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 29th Jan 2013 21:02 Edited at: 29th Jan 2013 21:06
Unfortunately I'm still having issues with looping and finding more issues along the way with PlayMusic()...
I'm attaching the code and the WAV files I'm working woth for examples.
No matter what I get random clicking. It seems to happen about 80% of the time while looping. I've tried various offsets to attempt to overlap the files. It seems that as soon as the file goes silent or PlayMusic() is called I get clicking. I've also found that if a WAV file is less than 1 second then PlayMusic() refuses to play it at all... And for some reason my file, Pew2.wav only partially plays via AGK. It plays fine in WMP and other players.

If someone with more knowledge than me would take a look at this, I'd really appreciate it. I really need sound bite looping to be seamless otherwise I'll have to make sound files that are unnecessarily large.


EDIT: forgot to mention. This is happening in Win7 only, this looper seems fine on Android...

Attachments

Login to view attachments
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 29th Jan 2013 22:54
I think you may have file type issues.

*.wav files are loaded and played as Sound (LoadSound, PlaySound) and you can have multiple sounds playing at the same time.

*.mp3 files are loaded and played as Music (LoadMusic, PlayMusic) and you can only play one music at a time.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 30th Jan 2013 00:14
Good catch! I made the change, but the popping still occurs on every call to PlaySound().
The files now play OK. They play all the way through and the file that is < 1 sec plays fine.
But the popping is there on every call!

I've tested this on both of my Windows machines to be sure. Lots of popping.

I tested this new code on my Nexus 7 and the WAV file becomes extremely distorted on the repeat plays. Horribly distorted!

Can someone else run this code (don't forget to change LoadMusic and PlayMusic to LoadSound and PlaySound) and test it?

I know there were issues with sound files before, but I thought they were resolved. Is this not the case?

Thanks!

JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 30th Jan 2013 00:55
I've looked at your wav files, and they will always click, because they all start off the zero-crossing point. The ends are okay - the beginnings need a few milliseconds of silence inserted.

In general, it's better to have all sound files start at zero, if only for a millisecond.

Load the wav files into Audacity (or any sound editor) and insert a tiny bit of silence at the front.

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL
nz0
AGK Developer
17
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 30th Jan 2013 01:26
I've had to get around this by just using mp3 for music and writing the music to not be "loopable"... Well, not ignoring looping, but writing a bridge/gap into the loop point so the small delay isn't noticable in the music loop.

I'm sure I've got a global volume changer working for (mp3) music while it's playing.. but you are using wavs..

I have posted requests for enhancements to sound (pitch control etc.)

I did have a section of music that had to be finely tuned to the building of a level and the MP3 delay was just unacceptable. In the end I had to resort to the first solution I mentioned.

Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 30th Jan 2013 01:58
Sweet, thanks, Jim. Inserting silence at the start of the file seems to have done the trick. Sorry I didn't understand what you meant by
Quote: "...first and last samples in your audio file are at a zero-crossing point"

I thought you meant to have the loops intersect at the exact end of the file. Now I know!

Audacity does the trick and this little code can now be used to add delay between loops or cause them to overlap. No clicking!

I'll make it into a function for all to use later on.

Cheers!!

Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 30th Jan 2013 07:57
Here's the functions I've worked out for this plus the ability to decay the loop for fading in/out, control over the # of loops, and some functions to get data from a wav file.

Cheers!

http://www.thegamecreators.com/?m=codebase_view&i=57c786ca30f107537f78c8503b88a333

JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 30th Jan 2013 10:33
The zero-crossing point is where the waveform goes from positive to negative or vice versa. Looped sounds (say for synthesisers) are always constructed so that there is no jump in the data between the last sample and the first sample when it repeats.

The easiest way to test is to paste two sound files into Audacity one after the other and play it. If it doesn't click you're probably all right.

You're code looks very neat. Can I make a Pascal version for you to add?

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL
Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 30th Jan 2013 18:41
Certainly, Jim!

I'm going to try to do this for OGG and MP3 files too.
Unfortunately their file struct is not nearly as simple...

So if anyone knows how to do this for MP3 and OGG, please feel free to do so!

JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 30th Jan 2013 19:25
It's very complex to do that. The header structures are variable and extensible. I can make a tool to give you the precise duration, if you like - and then you can save a "map" file to load.

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL
Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 30th Jan 2013 21:55
I wouldn't mind trying it out as a side project, OGG would be more of a priority for me since I'll be using that to avoid any possible MP3 format licensing fees.

JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 30th Jan 2013 22:06
Don't know if OGG will work on iOS. It certainly doesn't in HTML5.

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL
Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 30th Jan 2013 22:58
Good to know. I wonder how MP3 licensing would work on HTML5. You don't have to pay the $2,500 licensing fee unless you distribute more that 5,000 games, with HTML5 you're not distributing them at all...

Here's the w3schools link to audio file support in HTML5:
http://www.w3schools.com/html/html5_audio.asp

Looks like OGG is supported, just not in IE9 (14% of browsers) and Safari (4% of browsers).

Whether OGG works via AppGameKit in iOS would be nice to know too.
It doesn't look like the AppGameKit sound commands support OGG yet either, so extending this code to OGG might be a bit useless for now. Tabling it.

Login to post a reply

Server time is: 2024-11-24 08:21:38
Your offset time is: 2024-11-24 08:21:38