SRTDELAY.BAS optimized, UDT passed to sub

by (no login)

 
DECLARE SUB DELAY (srt$, lag&)

TYPE srttime
hr AS LONG
mn AS LONG
sc AS LONG
msc AS LONG
END TYPE

DECLARE SUB milisec (var() AS srttime, i, BE$, l&)

DIM SHARED subt(4) AS srttime
DIM SHARED srt(2) AS STRING
DIM SHARED srtmsc(2) AS LONG
DIM BE(4) AS STRING
DIM datBE(4) AS LONG

' FILES To PROCESS :
infile$ = "Force.srt"
outfile$ = "new.srt"

'CLS OUTPUT FILE :
KILL outfile$
OPEN outfile$ FOR APPEND AS #1
CLOSE #1

OPEN infile$ FOR INPUT AS #1
OPEN outfile$ FOR OUTPUT AS #2

' COMPUTING DATAS :

CLS

' original srt file start & end :
BE(1) = "00:01:12,087": BE(2) = "01:14:31,585"

' film speach boudaries start & end :
BE(3) = "00:01:32,285": BE(4) = "01:18:11,150"

' converto milisec :

FOR i = 1 TO 4

CALL milisec(subt(), i, BE(i), l&)

datBE(i) = l&

NEXT i

' durations :

original# = datBE(2) - datBE(1)
final# = datBE(4) - datBE(3)
amount# = final# - original#


'LINE FEED :

DO

restart:
IF NOT EOF(1) THEN
LINE INPUT #1, srt$
ELSE
EXIT DO
END IF

IF INSTR(srt$, "-->") > 0 THEN
count% = count% + 1
ELSE
PRINT #2, srt$
GOTO restart
END IF

' COMPUTE lag& :

' - convert to milisec :

c% = INSTR(srt$, "-->")
srt(1) = LEFT$(srt$, c% - 2)
srt(2) = RIGHT$(srt$, LEN(srt$) - (c% + 3))


FOR i = 1 TO 2
CALL milisec(subt(), i, srt(i), l&)
srtmsc(i) = l&
NEXT I

' - compute the lag& :

' if outside boundaries do nothing :

IF srtmsc(1) < datBE(1) OR srtmsc(1) > datBE(2) THEN
lag& = 0
PRINT #2, srt$
count% = count% - 1
GOTO restart
END IF

' lag& :

distance# = srtmsc(1) - datBE(1)

lag& = INT(distance# / original# * amount#) + (datBE(3) - datBE(1))

lag& = ABS(lag&)

CALL DELAY(srt$, lag&)

PRINT #2, srt$

LOOP

PRINT "lines processed = "; count%

CLOSE #1: CLOSE #2

END

' ///////////// END MAIN /////////////

ERRORHANDLE:
PRINT distance&
PRINT final#
PRINT srtmsc(1)
PRINT datBE(3)
PRINT lag&
PRINT amount&
PRINT srt$
PRINT INT(distance# / final#)
PRINT distance# / final#
END



'////////////////// SUB /////////////////

SUB DELAY (srt$, lag&)

'parse the string

c% = INSTR(srt$, "-->")
srt(1) = LEFT$(srt$, c% - 2)
srt(2) = RIGHT$(srt$, LEN(srt$) - (c% + 3))


FOR i = 1 TO 2
CALL milisec(subt(), i, srt(i), l&)
srtmsc(i) = l&
NEXT I

'add lag& :

FOR i = 1 TO 2
srtmsc(i) = srtmsc(i) + lag&
NEXT i

'converting back to srt time format :

FOR i = 1 TO 2

subt(i).msc = srtmsc(i) MOD 1000
srtmsc(i) = srtmsc(i) - subt(i).msc
srtmsc(i) = INT(srtmsc(i) / 1000)

subt(i).sc = srtmsc(i) MOD 60
srtmsc(i) = srtmsc(i) - subt(i).sc

subt(i).hr = INT(srtmsc(i) / 3600)
srtmsc(i) = srtmsc(i) - subt(i).hr * 3600

subt(i).mn = INT(srtmsc(i) / 60)

NEXT i

'rebuild string :

't$=string$(10-len(t$), 0)+t$

FOR i = 1 TO 2

'padding :

a$ = LTRIM$(STR$(subt(i).hr))
b$ = LTRIM$(STR$(subt(i).mn))
c$ = LTRIM$(STR$(subt(i).sc))
d$ = LTRIM$(STR$(subt(i).msc))


a$ = STRING$(2 - LEN(a$), "0") + a$
b$ = STRING$(2 - LEN(b$), "0") + b$
c$ = STRING$(2 - LEN(c$), "0") + c$
d$ = STRING$(3 - LEN(d$), "0") + d$

srt(i) = a$ + ":" + b$ + ":" + c$ + "," + d$

NEXT i

srt$ = srt(1) + " --> " + srt(2)

PRINT "srt$ SUB = "; srt$

END SUB

SUB milisec (var() AS srttime, i, BE$, l&)

subt(i).hr = VAL(LEFT$(BE$, 2))
subt(i).mn = VAL(MID$(BE$, 4, 2))
subt(i).sc = VAL(MID$(BE$, 7, 2))
subt(i).msc = VAL(MID$(BE$, 10, 3))


l& = subt(i).msc + (subt(i).sc + subt(i).mn * 60 + subt(i).hr * 3600) * 1000

END SUB

Posted on Jun 1, 2012, 11:01 AM

Respond to this message   

Return to Index

Response TitleAuthor and Date
Enhancement on Mar 2

 Copyright © 1999-2014 Network54. All rights reserved.   Terms of Use   Privacy Statement