QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: SirCrow on September 25, 2018, 01:09:58 pm

Title: Looping a _SND* File?
Post by: SirCrow on September 25, 2018, 01:09:58 pm
Sorry for seeming so ignorant, but can a brief sound file (.mp3) be made to loop rather than play once and stop?
Title: Re: Looping a _SND* File?
Post by: FellippeHeitor on September 25, 2018, 01:11:33 pm
Yes! http://qb64.org/wiki/SNDLOOP
Title: Re: Looping a _SND* File?
Post by: SirCrow on September 25, 2018, 10:15:23 pm
Yes! http://qb64.org/wiki/SNDLOOP

Thanks.  Is it normal that there's a brief silent gap during the sound loop?  Can this be avoided?
Title: Re: Looping a _SND* File?
Post by: FellippeHeitor on September 25, 2018, 10:19:26 pm
Are you sure your file is a perfectly loopable sound?
Title: Re: Looping a _SND* File?
Post by: TerryRitchie on September 26, 2018, 12:07:04 am
Use Audacity to cut out the silence at the end.
Title: Re: Looping a _SND* File?
Post by: Petr on September 26, 2018, 10:08:36 am
Quote
Use Audacity to cut out the silence at the end.

You need it not. Use QB64  statements:

Code: QB64: [Select]
  1. music& = _SNDOPEN("song.mp3")
  2. vol = 0
  3. _SNDVOL music&, vol
  4. _SNDLOOP music&
  5.  
  6. 'let say, volume up and volume down duration is 5 seconds:
  7. up = 1 / 50
  8.  
  9.     LOCATE 1, 1: PRINT "Volume: "; INT(vol * 100); "step:"; up; " Song position: "; _SNDGETPOS(music&), "Song lenght: "; _SNDLEN(music&)
  10.     IF _SNDGETPOS(music&) < 5.5 THEN
  11.         IF start = 0 THEN start = TIMER
  12.         IF TIMER > start + .1 THEN vol = vol + up: start = TIMER
  13.     END IF
  14.  
  15.     IF _SNDGETPOS(music&) > _SNDLEN(music&) - 5.5 THEN
  16.         IF start = 0 THEN start = TIMER
  17.         IF TIMER > start + .1 THEN vol = vol - up: start = TIMER
  18.     END IF
  19.     _SNDVOL music&, vol
  20.     IF vol < 0 THEN vol = 0: IF vol > 1 THEN vol = 1
  21.  
Title: Re: Looping a _SND* File?
Post by: TerryRitchie on September 26, 2018, 12:54:16 pm
I'm all for using code whenever possible and practical. However, it sounds like he simply wants it to loop without the pause embedded in the music itself.

Using a coding a approach means having to monitor it constantly. Removing the dead space completely means no monitoring:

_SNDLOOP music&

Fire and forget.
Title: Re: Looping a _SND* File?
Post by: Petr on September 26, 2018, 01:20:39 pm
Yes it is true. I see that I have understood the problem described again wrongly. Well, if sndloop wants no pause and the MP3 file has a gap at the end, say 3 minutes lenght and at the end pause 1 second, it can also be solved with one line.

IF _SNDLENGHT (musicloop)> 179 THEN _SNDSETPOS (musicloop), 0. But of course, everyone will do it on their own.
Title: Re: Looping a _SND* File?
Post by: SirCrow on September 30, 2018, 10:11:30 am
I didn't think there was any silence at the end, but I'll check to make sure.  Thanks.