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 / Seamless music loops in v2?

Author
Message
Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 16th Oct 2013 23:19
I know seamless looping MP3s have been asked for multiple times. Anyone knows if that's planned for v2? Right now you can only get seamless music using wav. However, a 1MB wav takes less than 200kB in MP3 format.

Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 24th Oct 2013 13:38
Seamless looping? You mean as in start a track, then loop back to, for example, two seconds into the track so that the intro is dropped?
bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 27th Oct 2013 23:56
no, seamless playback as in, start playing a track, play it till the end, and then play back from the start but without any breaks or stops or hickups
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 28th Oct 2013 01:59
I'ma bit confused by what you mean, to be honest. Music looping was fixed, is it still broken??
Ian Rees
AGK Developer
12
Years of Service
User Offline
Joined: 3rd May 2012
Location: Wales, UK
Posted: 28th Oct 2013 09:32
Where there is no gap at all between the end of the music and then the start after looping back.

There is still a slight gap which means it's not 'seamless'.

JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 28th Oct 2013 10:18
It's very difficult to to reliably because of the way the underlying streaming stuff works on different platforms.

-- Jim - When is there going to be a release?
JRNTexas
12
Years of Service
User Offline
Joined: 24th May 2011
Location: Austin, Texas
Posted: 28th Oct 2013 10:18 Edited at: 28th Oct 2013 10:24
I've experienced this problem many times before, in completely different environments. I have never been able to make an MP3 file that doesn't have gaps at the beginning and end. I've tried with several different, very professional applications and it has never worked. If you have a software application that will make a seamless MP3 file, I would like to know what it is(seriously)!

I've made MP3 files that have a minimum gap at the beginning and all, ALL, MP3 players hick up on the file. I have an engineering background and have worked with and patented sound software. And I believe that the company that owns the MP3 patent and the rights (everyone has to pay them to use the MP3 format), supplies all the code to read and play an MP3 file. Consequently, if one MP3 player has a problem playing a file, they ALL have the same problem.

Unless something has changed in the last few months. I don't think you can do what you are asking, in any environment. I know it doesn't sound reasonable, but what you're asking is only possible with a wav file. Again, unless something has changed in the last few months.

The only work around I can think of is play two versions of the same file and time it so that the second file starts to play just as the first one ends. I've never tried this, but theoretically, it should work.

Good luck
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 28th Oct 2013 11:27
Quote: " play two versions of the same file and time it so that the second file starts to play just as the first one ends"


Unfortunately, iOS and Android will only stream 1 file at a time. Neither mp3 nor Ogg Vorbis were designed to provide tight looping. In any case, MP3 frames have to be a certain size, so avoiding a gap would be hard. In a nut-shell - it ain't going to happen. The stream start may take quite a long time on low-end processors because the buffers will have to be decoded.

Last time this topic came up I posted an example of using relatively small WAV chunks to provide infinite music, using a ring-buffer. Because WAVs are PCM data and held in memory in the playback routines they should start very quickly.

And alternative trick would be to keep your MP3 but have a suitable bridge passage as a WAV - trigger that when the MP3 stops, and then restart the MP3. Personally I'd make it a chord or some suitable ambient sound to avoid strict timing issues.

-- Jim - When is there going to be a release?
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 28th Oct 2013 12:20
I understand the issue now. I'd go with the suggestion to make a wav sound effect and loop that to get the track, if that's possible. I have to admit though, on a good game that's engaged me, I wouldn't even notice a seconds pause while the track loops. My game has multiple tracks, all of which fade out, so I don't have that issue, but you can get a wav pretty small before the quality suffers drastically, especially on mobile devices (not mp3 small but doable - most devices have at least a couple hundred meg available to them these days).

I do agree though, I don't like the way android in general handles music, and - if it is possible - having the option to at least queue another track to play might be useful.
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 28th Oct 2013 12:50 Edited at: 28th Oct 2013 12:52
I don't regard this as an AppGameKit problem, as such. It's a problem with trying to do cross-platform things on devices that can range from i7 8 core processors to slow ARM chips. If somebody paid me, as they have in the past, to make this kind of problem work on low-end devices, I'd code my own MP3 decoder routines and pump the output to PCM.

But why bother? Music design is as important as visual design, and I would create the music with a natural pause at the track end. Trying to slam drum-beats on a pulse and have it stay in time is highly risky. If you want to have a seamless experience, then you have to be clever about the music design and the coding to handle it.

If I get time I'll compose a couple of tracks showing how to make it seem natural even if there is a slight gap. The trick is to have a cadence - a falloff - at the pause point. You make it shift to the Dominant or Dominant 7th and hold and fade. No drums etc. That way, when the start comes back it will sound intentional.

-- Jim - When is there going to be a release?
Fallout
21
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 28th Oct 2013 13:28 Edited at: 28th Oct 2013 13:29
I've not tried to set music as loopable in AppGameKit yet but when writing for the Android SDK directly I had seamless looping music. In fact I'm listening to the background music on my games right now just to double check.

The file format was OGG. Obviously I'd made the tracks loopable and stripped out any padding in the actual WAV data, but I believe the encoder plays a part in the final encoded WAV padding. I remember having very slight pauses until I removed all the padding options.
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 28th Oct 2013 14:50
From an end user point of view, no matter how you handle the music, please make sure that there is an option to turn it off. I always turn off background music when given the option.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 28th Oct 2013 15:04
OGG will not play on iOS or Windows without extra stuff.

-- Jim - When is there going to be a release?
Ian Rees
AGK Developer
12
Years of Service
User Offline
Joined: 3rd May 2012
Location: Wales, UK
Posted: 28th Oct 2013 15:41
Quote: "OGG will not play on iOS or Windows without extra stuff."


This is correct, and there are license fees when using MP3 (when more than 5000 copies are distributed).

I'm hoping to use M4A for iOS and OGG for Windows/Android. I might have to distribute the codec with the installer for Windows.

xCept
21
Years of Service
User Offline
Joined: 15th Dec 2002
Location:
Posted: 28th Oct 2013 22:09
According to the Kickstarter update that just went out, looping is fixed in V2

Quote: "Sounds

Here's a list of commands and values you'll be able to access in AppGameKit V2. We're showing you the Tier 2 style commands here.

UINT PlaySound( UINT iID, int iVol, int iLoop ); // now returns an instance ID
float GetSoundMaxRate();
float GetSoundMinRate();
int GetSoundInstancePlaying( UINT iID );
int GetSoundInstanceVolume( UINT iID );
float GetSoundInstanceRate( UINT iID );
void SetSoundInstanceVolume( UINT iID, int vol );
void SetSoundInstanceRate( UINT iID, float rate );
int GetSoundInstanceLoopCount( UINT iID );
void StopSoundInstance( UINT iID );

Music can be made to loop properly too.

In testing we have found that Windows has a higher range of playback speeds than Android when we changed the pitch of the music."
Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 28th Oct 2013 22:17
Quote: "According to the Kickstarter update that just went out, looping is fixed in V2"

Yeah, I just noticed. Great news

Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 29th Oct 2013 14:57
Just to clarify, the looping is better than before, but is still not perfect. Before I was reinitializing the music buffer when it ended and playing it again, now I just seek back to the beginning, but I couldn't get seamless looping with my test mp3 file. Maybe a specially crafted mp3 file will work seamlessly with the new method, but I can't be sure.
Fallout
21
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 29th Oct 2013 15:39 Edited at: 29th Oct 2013 15:39
I thought I'd send you a loopable MP3 Paul, so I had a quick play with some MP3 files and tried encoding in variable and constant bit rate modes, with three different padding modes and at different bit rates. All approaches generated extra padding around the audio which is visible when you reload it and therefore unloopable.

I thought perhaps MP3s encode in certain 'time chunks' so say maybe 0.25 seconds, so it'll pad out any music that doesn't fit that size. So what I did was save a track to MP3, load it up, check the length, strip the silence from start and end, then resample it back to the loaded in length. I then saved the file out again and reloaded it. MP3 had simply added more silence and made the track longer.

So I tend to agree the problem is with the MP3 format. The only real solution would be to either use music which can blend to silence and then come back in when it restarts, or time the finish of the track yourself and restart it yourself, offsetting into the track by the silence gap at the start.
Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 29th Oct 2013 16:16
If the problem is with the mp3 format then can't AppGameKit use start and stop times to loop instead of the entire length?

Fallout
21
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 29th Oct 2013 16:20
A loopmusic(iID,fStartTime,fEndTime) or similar could help the issue at least.
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 30th Oct 2013 12:08
As I've said before in this thread - you're asking the system to do what is unlikely to succeed. MP3 was never designed to behave like a PCM file in a music sequencer. Setting start and end offsets is not going to help. You need predictable results, and it's not possible by looping MP3 to millisecond precision.

Designing your music or atmosphere tracks so that a small gap is not noticeable is predictable on all platforms.

-- Jim - When is there going to be a release?
Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 30th Oct 2013 13:15
How about creating an MP3 with an overlapping loop, check the current time and then set the music to a specific time? That would allow for some flexibility.

JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 30th Oct 2013 15:35
Only one mp3 track can play at the same time, so that won't work. If I understand you correctly. Triggering a WAV at some point will.

-- Jim - When is there going to be a release?
Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 30th Oct 2013 16:19
That's not what I meant. Simply jump to an earlier part of the song once it goes past a time. I was thinking of checking the current time manually and to avoid inaccuracies you extend the song beyond the loop time, check how much past it is and manually set it to an earlier point, depending on where it currently is.

JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 30th Oct 2013 17:48
Worth a try - but I'm not optimistic.

-- Jim - When is there going to be a release?
Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 31st Oct 2013 13:16
Winamp have no problem looping one of the MP3s in my game. I am currently listening to the song Med Pack and if you don't know where it ends, you can't tell it loops.

JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 31st Oct 2013 15:24
Yeah - but Winamp is a dedicated music player. It's probably keeping some decoded buffers available for looping etc.

-- Jim - When is there going to be a release?
Naphier
13
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 31st Oct 2013 19:40
I think you'll always have a problem with seamless looping in Android.
Even games like Beat Hazard, that are music based, have pauses between tracks.
I think it's not a big problem as users likely expect this. However as a developer I can share your desire to have seamless looping of background music.
My best suggestion is that you have a small WAV loop that works as ambient music. Start playing it a little before your track ends, make sure that your track fades out smoothly (as well as back in). After you're certain that your mp3 music has started and been playing for a little bit then shut off the WAV loop. That way the user isn't left with silence and they will even think that it is part of the overall track.

Also a really great editor is Audactity. It's super basic and allows you to control the padding of an MP3 quite well. That said, you should always make sure there is some padding so that the file starts and ends at a zero crossing. Otherwise you'll likely get pops.

Hope this helps!

Login to post a reply

Server time is: 2024-05-20 04:54:54
Your offset time is: 2024-05-20 04:54:54