/* SPLITWAVE - extract parts of wavefiles using COPYWAVE */ IF ARG(1) = '' THEN DO SAY "usage: SPLITWAVE [options] wavefile start [split [split]] end" SAY "Positions are given in seconds or minutes:seconds or hours:minutes:seconds." SAY "If they are preceeded with + it counts relative to the previous one." SAY "The Last Position may be * whitch means up to the end of the source file." SAY "The destination files are named automatically wavefile01, wavefile02, ..." SAY "options: /r or /rmp2 round split points to full MP2/MP3 frames" SAY " or /rmp3 (1152 samples)." SAY " /rmp1 round split points to full MP1 frames (384 samples)." SAY " /rf or /rframes round split points to full CD frames (588 samples)." SAY " /rstart round absolute starting position also." SAY " /rend round last part also." SAY " /r+ always round up." SAY " /r- always round down." SAY " /f or /frames positions are given in CD frames." SAY " /s or /samples positions are given in samples." SAY " /n# start with destination file number # instead of 01." SAY " /n auto detect Track number." SAY " /b$ change basename for destination files to $." EXIT -1 END /* defaults */ round = 1 rounddir = 1 rstart = 0 rend = 0 filenum = 1 fname = '' parts = 0 unit = 44100 dest = '' /* scan command line */ params = ARG(1) DO WHILE params \= '' IF LEFT(params,1) = '"' THEN PARSE VAR params '"'param'"'params ELSE PARSE VAR params param params params = STRIP(params, 'l') IF param = '' THEN ITERATE IF LEFT(param,1) = '/' THEN DO /* option */ option = TRANSLATE(SUBSTR(param,2)) SELECT WHEN option = 'R' | option = 'RMP2' | option = 'RMP3' THEN round = 1152 WHEN option = 'RMP1' THEN round = 384 WHEN option = 'RF' | option = 'RFRAMES' THEN round = 588 WHEN option = 'RS' | option = 'RSTART' THEN rstart = 1 WHEN option = 'RE' | option = 'REND' THEN rend = 1 WHEN option = 'R+' THEN rounddir = 0 WHEN option = 'R-' THEN rounddir = 2 WHEN option = 'F' | option = 'FRAMES' THEN unit = 588 WHEN option = 'S' | option = 'SAMPLES' THEN unit = 1 WHEN LEFT(option,1) = 'N' THEN filenum = SUBSTR(option,2) WHEN LEFT(option,1) = 'B' THEN dest = SUBSTR(param,3) OTHERWISE SAY "Unknown option "param"." EXIT 15 END ITERATE END IF fname = '' THEN DO fname = param ITERATE END IF param = '*' THEN param = 202*60*44100/unit /* nearly the limit for WAV */ PARSE VAR param sg1':'sg2':'sg3 IF sg3 \= '' THEN sg2 = 60 * sg2 + sg3 IF sg2 \= '' THEN sg1 = 60 * sg1 + sg2 sg1 = sg1 * unit IF parts > 0 THEN DO j = parts - 1 IF LEFT(param, 1) = '+' THEN sg1 = sg1 + pos.j IF sg1 <= pos.j THEN DO SAY "Length of part "parts" is negative." EXIT 5 END END pos.parts = sg1 parts = parts + 1 END IF fname = '' THEN DO SAY "Filename expected" EXIT 14 END IF parts < 2 THEN DO SAY "At least a start and a end position is required." EXIT 13 END parts = parts - 1 /* round */ IF rstart THEN pos.0 = DoRound(pos.0) DO i = 1 TO parts - \rend pos.i = DoRound(pos.i - pos.0) + pos.0 END /* dname */ IF dest = '' THEN dest = fname dest = FILESPEC('n', dest) p = LASTPOS('.',dest) IF p = 0 THEN p = LENGTH(dest) +1 /* auto track number */ IF filenum = '' THEN DO PARSE VALUE GetTitleInfo(fname, "CDT-Track") WITH filenum'-' IF filenum = '' THEN filenum = 1 END /* doit! */ DO i = 1 TO parts j = i - 1 '@COPYWAVE 'PCTesc(fname) PCTesc(INSERT(RIGHT(filenum,2,'0'),dest,p-1))' /ss:'pos.j' /es:'pos.i IF rc \= 0 THEN DO SAY "COPYWAVE returned bad status: "rc EXIT 2 END filenum = filenum + 1 END EXIT 0 DoRound: PROCEDURE EXPOSE round rounddir rem = ARG(1) // round RETURN ARG(1) - rem + round * (2*rem > rounddir * (round-1)) GetTitleInfo: PROCEDURE rc = SysGetEA(ARG(1), ARG(2), ea) IF rc \= 0 THEN RETURN '' RETURN SUBSTR(ea, 11) PCTesc: PROCEDURE tmp = ARG(1) p = POS('%', tmp) DO WHILE p \= 0 tmp = INSERT('%', tmp, p) p = POS('%', tmp, p+2) END RETURN '"'tmp'"'