GLBasic forum

Main forum => Bug Reports => Topic started by: nicoatek on 2012-Sep-07

Title: MUSIC NOT LOOPING PROPERLY
Post by: nicoatek on 2012-Sep-07
Hi, there!

In my current project, I' ve got a short background music that should loop seamlessly.
This works great on my Android platform, but not on my windows XP.

With WAV files, the music loops with a little noise.
With MP3 files, start of the music seems to be cropped and so, don' loops properly.

Is somebody got this problem too?
And is this a bug?

Thanks for any solution.
Title: Re: MUSIC NOT LOOPING PROPERLY
Post by: MrTAToad on 2012-Sep-07
I haven't come across it cropping the music, although there is a slight delay when it restarts.
Title: Re: MUSIC NOT LOOPING PROPERLY
Post by: nicoatek on 2012-Sep-07
My MP3 problem should be due to the exporter from my sequencer.
But this short latency...
Hope it will be solved in a next update, or maybe there is a trick for this.
Title: Re: MUSIC NOT LOOPING PROPERLY
Post by: matchy on 2012-Sep-07
nicoatek, what are you using to export a mp3 file? I need something like a wav to mp3 lib.
Title: Re: MUSIC NOT LOOPING PROPERLY
Post by: nicoatek on 2012-Sep-07
I use the export from Fruity Loops Producer (my music tool).
But the mp3 result is surely in VBR (Variable Bit Rate) which seems to be wrong with GLBasic.

I think it will work with Audacity and its MP3 exporter, but the short latency produce a kind of noise each time my loop restart as for WAV files.

If no solutions, i should have to write an entire song for the Widows version (which i am not good at).
Title: Re: MUSIC NOT LOOPING PROPERLY
Post by: r0ber7 on 2012-Sep-07
Here's an idea. It's not very elegant but could work.
- Using Audacity, cut the first few seconds from your music mp3, and save that as a wav. You will have two files: a wav with the first few seconds of the music, and an mp3 with the rest.

In your program, when you start to play music:
- Start the wav with PLAYSOUND
- If SOUNDPLAYING = FALSE, start the mp3 with PLAYMUSIC (no loop).
- Once MUSICPLAYING = FALSE, start the wav again.
- Repeat.

Instead of using SOUNDPLAYING / MUSICPLAYING you could also use a timer check for the length of the sounds. I have no idea if this would work, but it may work, even though it's a dirty workaround.
Title: Re: MUSIC NOT LOOPING PROPERLY
Post by: matchy on 2012-Sep-07
Oh I thought you meant your own exporter.  :-[ Fruityloops is cool anyhow...I use that. :good: For a test, try playing the song in wav format!
Title: Re: Music not looping properly
Post by: spacefractal on 2012-Sep-07
Annoying big letter subject (avoid that), but small thing  =D.

Its more a limit in GlBasic rutines, rather than a bug. Something that could been improvements very much in a future glbasic release (and sad we cant do a real bass.dll deal from un4seen me see). Howover looping is a area that is quite bad, which is also missing totally for soundfx (I have short seamless soundfx loops, that cant been looped correctly due the same issue).

I still hope if adpcm is supported throught sound and music, then its would been much better and more loopable support. Nots sure we would see its fixed soon. its not a top priotity really.


Title: Re: MUSIC NOT LOOPING PROPERLY
Post by: nicoatek on 2012-Sep-07
Anyway, I've wrote a couple of functions that minimize the delay.

Code (glbasic) Select

GLOBAL waveLoops[] AS WAVELOOP

TYPE WAVELOOP
waveid
state
length
chn
mil
ENDTYPE

FUNCTION wlAdd: id, l
LOCAL wl AS WAVELOOP
wl.waveid = id
wl.length = l
wl.state = 0
wl.chn = 0
wl.mil = 0
DIMPUSH waveLoops[], wl
RETURN LEN(waveLoops) - 1
ENDFUNCTION

FUNCTION wlPlay: id
waveLoops[id].state = 1
waveLoops[id].chn = PLAYSOUND(waveLoops[id].waveid, 0, 1)
waveLoops[id].mil = GETTIMERALL() + waveLoops[id].length
ENDFUNCTION

FUNCTION wlUpdate:
LOCAL mil
FOREACH wl IN waveLoops[]
IF wl.state = 1
mil = GETTIMERALL()
IF mil >= wl.mil
wl.chn = PLAYSOUND(wl.waveid, 0, 1)
wl.mil = GETTIMERALL() + wl.length
ENDIF
ENDIF
NEXT
ENDFUNCTION


- wlAdd function for adding a previously loaded wave file to the list (you need to specify the length in milliseconds)
- wlPlay to start the loop
- wlUpdate must be called continuously in the main program loop

Needs to add wlPause, wlStop, wlIsPlaying, and some volume and panning functions.

Thanks for replies!
Title: Re: MUSIC NOT LOOPING PROPERLY
Post by: Wampus on 2012-Sep-08
The gap or delay between a song ending and restarting can be obscured by beginning and ending the song with off-rhythm sounds and/or enough silence between sounds to disguise the gap. For example, the main theme for PowFish (http://www.powfish.com/) doesn't loop seamlessly yet no one is going to notice the gap unless they're listening carefully.
Title: Re: MUSIC NOT LOOPING PROPERLY
Post by: matchy on 2012-Sep-08
Very cool song play delay snippet nicoatek!  :good:
Title: Re: MUSIC NOT LOOPING PROPERLY
Post by: spacefractal on 2012-Sep-08
Its still not seamless and you still hear sound cutters when looping (but best workaround for now). I do similar like this.

Real 100% seamless playback would still been prefered.

It's not a bug, just limit.