MUSIC NOT LOOPING PROPERLY

Previous topic - Next topic

nicoatek

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.

MrTAToad

I haven't come across it cropping the music, although there is a slight delay when it restarts.

nicoatek

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.

matchy

nicoatek, what are you using to export a mp3 file? I need something like a wav to mp3 lib.

nicoatek

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).

r0ber7

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.

matchy

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!

spacefractal

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.


Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

nicoatek

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!

Wampus

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 doesn't loop seamlessly yet no one is going to notice the gap unless they're listening carefully.

matchy

Very cool song play delay snippet nicoatek!  :good:

spacefractal

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.
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/