View previous topic :: View next topic |
Author |
Message |
Xenocritus Cheater
Reputation: 0
Joined: 27 Dec 2020 Posts: 25
|
Posted: Sat Feb 13, 2021 5:15 pm Post subject: MP3 interruption when restarting/looping songs |
|
|
Hi,
I think I'm near to achieve the correct loop game music (Thanks to @mgr.inz.Player, @Corroder and Aylin). However, my problem now is that once the song loops, there is a short interruption. Interruption is just very few millisecs, but enough to break the music flow...
How can I solve it? I have tryed without closing media or just giving a time of 1 in the Timer, but the cut is always there. I tryed with a coninual alarm to verify...
Code: | function PlayLoop(path, start1, finish1)
start1=tonumber(start1)
finish1=tonumber(finish1)
if not initializeMP3Player() then return end
--MP3PlayerSendCommand('close MediaFile')
-- MP3PlayerSendCommand( string.format('open "%s" type mpegvideo alias MediaFile',path) )
MP3PlayerSendCommand('play MediaFile from '..start1..' to '..finish1..' notify')
end
----##############################
local pth=[[C:\myFolder\alarm.mp3]] --MP3 file path?
if progressTimer then progressTimer.destroy() progressTimer=nil end
progressTimer = createTimer(nil,false)
progressTimer.Interval = 1
progressTimer.OnTimer = function ()
sglength = tonumber(lengthMP3())
postime = tonumber(positionMP3())
if postime>=sglength then
sngposition=1000
snglength = tonumber(lengthMP3())
--PlayLoop(pth, sngposition, snglength)
progressTimer.Enabled=true
end
end
|
Thanks again!
|
|
Back to top |
|
 |
ByTransient Expert Cheater
Reputation: 5
Joined: 05 Sep 2020 Posts: 240
|
Posted: Sat Feb 13, 2021 9:50 pm Post subject: |
|
|
It works fine for me.
Some situations, you have to reconsider.
1) Is there any gap at the end of the music you use?
2) Is there a gap in the music, corresponding to the newly appointed start time?
I made an edit in the code below, it can help you trim the end of the ending.
You won't have to wait for the original ending of the music, instead you will set a finale.
It's like constantly listening to a part in the middle of Music.
-----------------------------------------------------------
Code: | function PlayLoop(path, start1, finish1)
start1=tonumber(start1)
finish1=tonumber(finish1)
if not initializeMP3Player() then return end
--MP3PlayerSendCommand('close MediaFile')
MP3PlayerSendCommand( string.format('open "%s" type mpegvideo alias MediaFile',path) )
MP3PlayerSendCommand('play MediaFile from '..start1..' to '..finish1..' notify')
end
------------------------------------------------------------------
sglength = tonumber(lengthMP3()) -->>Place this code in the first play button.
progressTimer.OnTimer = function ()
--sglength = tonumber(lengthMP3())
postime = tonumber(positionMP3())
if postime>=sglength then --Next Play
sngposition=1000 -- or 999
--New sglength
sglength = 1499 -->>If the original music length is 1500, trim by 1 millisecond. And set the new expiry time.
PlayLoop(pth, sngposition, snglength)
progressTimer.Enabled=true
end
end |
|
|
Back to top |
|
 |
Xenocritus Cheater
Reputation: 0
Joined: 27 Dec 2020 Posts: 25
|
Posted: Sun Feb 14, 2021 3:08 am Post subject: |
|
|
Hi. I already checked all that with no different result.
You can see here the file I've been using. It is just a continual alarm, you can check it but I think you will noticed the interruption using this file.
https://filebin.net/kpeqjjxeymygxll3
So, even with multiple manipulations like yours, it is still NOT working as expected.
Thanks in advance.
|
|
Back to top |
|
 |
ByTransient Expert Cheater
Reputation: 5
Joined: 05 Sep 2020 Posts: 240
|
Posted: Sun Feb 14, 2021 8:36 am Post subject: |
|
|
This code will allow you to soften the beginning and end of the song.
If you find the right interval (Start and end milliseconds) it will provide a fluid and seamless loop.
Here is a sample section from the file you provided;
Code: | local volcount=800
local postime = tonumber(positionMP3())
local counter=false
function VolumeCounter()
if postime > 9480 then
volcount=tonumber(volcount) - 100
print("volcount: "..volcount)
volumeMP3(tonumber(volcount)) end
if counter==true then
volcount=tonumber(volcount) + 100
print("volcount: "..volcount)
volumeMP3(tonumber(volcount))
end
if volcount==800 then
counter=false
end
if volcount==0 then
volcount=100
end
end
progressTimer.OnTimer = function ()
postime = tonumber(positionMP3())
VolumeCounter()
lbl1.caption=postime.." / "..sglength
if postime==sglength then
sngposition=2750
sglength = 10280
PlayLoop(pth, sngposition, sglength)
counter=true
progressTimer.Enabled=true
end
end
btn1.OnClick=function()
startMp3()
--playMP3(path1)
sglength = tonumber(lengthMP3()-2709)
PlayLoop(path1, postime, sglength)
volumeMP3(800)
progressTimer.Enabled=true
end |
|
|
Back to top |
|
 |
Xenocritus Cheater
Reputation: 0
Joined: 27 Dec 2020 Posts: 25
|
Posted: Mon Feb 15, 2021 1:15 am Post subject: |
|
|
Hi, sorry but that seems to be a Fade In / Fade Out effect.
That's totally different for what I'm looking for.
I'm looking for continual Loop without interruption.
For the moment, the nearest solution I have is to have 2 MP3 streams and overlap them alternating, but IMO this is not a very clean solution....
|
|
Back to top |
|
 |
Corroder Grandmaster Cheater Supreme
Reputation: 75
Joined: 10 Apr 2015 Posts: 1668
|
Posted: Mon Feb 15, 2021 5:14 am Post subject: |
|
|
Then try other alarm mp3 song sound file which not have interruption.
_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL |
|
Back to top |
|
 |
Xenocritus Cheater
Reputation: 0
Joined: 27 Dec 2020 Posts: 25
|
Posted: Mon Feb 15, 2021 6:53 am Post subject: |
|
|
But.. the songs have no interruption. That file was a simple example to show the problem.
I'm using digitally orchestrated music, which has a loop point. I can loop them inside Audacity or other software with no "interruption".
So this is whay I attached that alarm, because the sound is continuos, but when you try to reposition, you notice the interruption.
|
|
Back to top |
|
 |
ByTransient Expert Cheater
Reputation: 5
Joined: 05 Sep 2020 Posts: 240
|
Posted: Mon Feb 15, 2021 6:58 am Post subject: |
|
|
There is a sound accent mismatch at the beginning and end of the file.
My advice is to reset the volume at the start and quickly (+ 200 = 800) to bring the volume back to normal.
This will soften the initial braking.
Otherwise, focus on the detail, as @Corroder reminds you.
|
|
Back to top |
|
 |
Xenocritus Cheater
Reputation: 0
Joined: 27 Dec 2020 Posts: 25
|
Posted: Mon Feb 15, 2021 4:58 pm Post subject: |
|
|
I think you don't really understand the goal... isn't it?
I will try my aproach anyway with 2 Streams, don't see any other solution for the moment.
Most loops like this one, are 10 or 15 secs sound repeated all time. Same for video game music. This is the effect I'm looking for.
https://www.youtube.com/watch?v=wzjWIxXBs_s
|
|
Back to top |
|
 |
|