Author Topic: MUSIC NOT LOOPING PROPERLY  (Read 3228 times)

Offline nicoatek

  • Mc. Print
  • *
  • Posts: 13
    • View Profile
MUSIC NOT LOOPING PROPERLY
« 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.

MrTAToad

  • Guest
Re: MUSIC NOT LOOPING PROPERLY
« Reply #1 on: 2012-Sep-07 »
I haven't come across it cropping the music, although there is a slight delay when it restarts.

Offline nicoatek

  • Mc. Print
  • *
  • Posts: 13
    • View Profile
Re: MUSIC NOT LOOPING PROPERLY
« Reply #2 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.

Offline matchy

  • Prof. Inline
  • *****
  • Posts: 1544
    • View Profile
Re: MUSIC NOT LOOPING PROPERLY
« Reply #3 on: 2012-Sep-07 »
nicoatek, what are you using to export a mp3 file? I need something like a wav to mp3 lib.

Offline nicoatek

  • Mc. Print
  • *
  • Posts: 13
    • View Profile
Re: MUSIC NOT LOOPING PROPERLY
« Reply #4 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).

Offline r0ber7

  • Prof. Inline
  • *****
  • Posts: 542
    • View Profile
Re: MUSIC NOT LOOPING PROPERLY
« Reply #5 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.

Offline matchy

  • Prof. Inline
  • *****
  • Posts: 1544
    • View Profile
Re: MUSIC NOT LOOPING PROPERLY
« Reply #6 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!

Online spacefractal

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 3761
    • View Profile
    • Space Fractal
Re: Music not looping properly
« Reply #7 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.


Greedy Mouse - Karma Miwa - Spot Race - CatchOut - Android Extras - is on a vacation trip, home before end of few days in jan.

Offline nicoatek

  • Mc. Print
  • *
  • Posts: 13
    • View Profile
Re: MUSIC NOT LOOPING PROPERLY
« Reply #8 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!

Offline Wampus

  • Prof. Inline
  • *****
  • Posts: 1004
    • View Profile
Re: MUSIC NOT LOOPING PROPERLY
« Reply #9 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 doesn't loop seamlessly yet no one is going to notice the gap unless they're listening carefully.

Offline matchy

  • Prof. Inline
  • *****
  • Posts: 1544
    • View Profile
Re: MUSIC NOT LOOPING PROPERLY
« Reply #10 on: 2012-Sep-08 »
Very cool song play delay snippet nicoatek!  :good:

Online spacefractal

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 3761
    • View Profile
    • Space Fractal
Re: MUSIC NOT LOOPING PROPERLY
« Reply #11 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.
Greedy Mouse - Karma Miwa - Spot Race - CatchOut - Android Extras - is on a vacation trip, home before end of few days in jan.