Author Topic: Looping a _SND* File?  (Read 3790 times)

0 Members and 1 Guest are viewing this topic.

Offline SirCrow

  • Forum Regular
  • Posts: 144
    • View Profile
Looping a _SND* File?
« 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?
I may not always finish what I've started....

FellippeHeitor

  • Guest
Re: Looping a _SND* File?
« Reply #1 on: September 25, 2018, 01:11:33 pm »

Offline SirCrow

  • Forum Regular
  • Posts: 144
    • View Profile
Re: Looping a _SND* File?
« Reply #2 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?
I may not always finish what I've started....

FellippeHeitor

  • Guest
Re: Looping a _SND* File?
« Reply #3 on: September 25, 2018, 10:19:26 pm »
Are you sure your file is a perfectly loopable sound?

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
    • View Profile
Re: Looping a _SND* File?
« Reply #4 on: September 26, 2018, 12:07:04 am »
Use Audacity to cut out the silence at the end.
In order to understand recursion, one must first understand recursion.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Looping a _SND* File?
« Reply #5 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.  

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
    • View Profile
Re: Looping a _SND* File?
« Reply #6 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.
In order to understand recursion, one must first understand recursion.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Looping a _SND* File?
« Reply #7 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.

Offline SirCrow

  • Forum Regular
  • Posts: 144
    • View Profile
Re: Looping a _SND* File?
« Reply #8 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.
I may not always finish what I've started....