- UID
- 3
- 积分
- 8169
- 帖子
- 259
- 主题
- 68
- 论坛币
- 5016
- 威望
- 54
- EP值
- 2533
- MP值
- 20
- 阅读权限
- 200
- 注册时间
- 2011-8-3
- 在线时间
- 1097 小时
- 最后登录
- 2022-10-8
|
預覽:http://pan.baidu.com/s/1hqqY9CC#dir/path=%2FSaiyakuFX_Preview
關於頻譜算法 表示我是參考needlessED2 和 paniponiED
看著看著 算法就出來了。。。- from tcaxPy import *
-
- from util.tcAudio import *
- SPECHEIGHT = 60
- def tcaxPy_Init():
-
- # some common pre-defined global values
-
- global fontSize # as name implies
-
- global resX # horizontal resolution
-
- global resY # vertical resolution
-
- global marginX # horizontal margin
-
- global marginY # vertical margin
-
- global spacing # space between texts
-
- global frameDur # milliseconds per frame
-
- global lineNum # number of lines
-
- global textNum # textNum[i], number of texts in ith line
-
- global _BT # _BT[i], start time of a line
-
- global _ET # _ET[i], end time of a line
-
- global _KT # _KT[i][j], karaoke time of a syllable
-
- global _SK # _SK[i][j], elapsed karaoke time before reaching a certain syllable
-
- global _TXT # _TXT[i][j], as name implies
-
- global _L # _L[i], total width of a line
-
- global _W # _W[i][j], width of a text
-
- global _H # _H[i][j], height of a text
-
- global _A # _A[i][j], advance of a text, usually larger than width
-
- global _AD # _AD[i][j], distance between the current text to the first text of the line
-
- fontSize = GetVal(val_FontSize)
-
- resX = GetVal(val_ResolutionX)
-
- resY = GetVal(val_ResolutionY)
-
- marginX = GetVal(val_OffsetX)
-
- marginY = GetVal(val_OffsetY)
-
- spacing = GetVal(val_Spacing)
-
- frameDur = 1000 / GetVal(val_FXFPS)
-
- lineNum = GetVal(val_nLines)
-
- textNum = GetVal(val_nTexts)
-
- _BT = GetVal(val_BegTime)
-
- _ET = GetVal(val_EndTime)
-
- _KT = GetVal(val_KarTime)
-
- _SK = GetVal(val_KarTimeDiff)
-
- _TXT = GetVal(val_Text)
-
- _L = GetVal(val_TextLength)
-
- _W = GetVal(val_TextWidth)
-
- _H = GetVal(val_TextHeight)
-
- _A = GetVal(val_TextAdvance)
-
- _AD = GetVal(val_TextAdvanceDiff)
-
- def Spectrum(fft): # convert fft data to graph
-
- bars = []
-
- b0 = 0
-
- for x in range(BANDS):
-
- peak = 0 # peak of a certain bar
-
- b1 = pow(2, x * 10.0 / (BANDS - 1))
-
- if b1 > 1023:
-
- b1 = 1023
-
- if b1 <= b0:
-
- b1 = b0 + 1 # make sure it uses at least 1 FFT bin
-
- while b0 < b1:
-
- if peak < fft[1 + b0]:
-
- peak = fft[1 + b0]
-
- b0 += 1
-
- y = int(sqrt(peak) * 3 * SPECHEIGHT - 4) # scale it (sqrt to make low values more visible)
-
- if y > SPECHEIGHT:
-
- y = SPECHEIGHT # cap it
-
- bars.append(y)
-
- return bars
-
- def tcaxPy_User():
-
- file_name = GetVal(val_OutFile) + '.ass'
-
- ass_header = GetVal(val_AssHeader)
-
- ASS_FILE = CreateAssFile(file_name, ass_header)
-
- tcAudioInit()
-
- channel = tcAudioOpen('h.mp3')
-
- freq = tcAudioGetFreq(channel) # usually 44100 Hz
-
- duration = tcAudioGetDuration(channel)
-
- num = int(duration * freq / 2048)
- F = []
- for k in range(num):
- fft = tcAudioGetFFT(channel, 2048)
- F.append(fft)
-
- for i in range(lineNum):
- initPosX = (resX - _L[i]) / 2 + marginX # if marginX = 0, then it's just on the middle
-
- initPosY = 720- marginY
- SPECWIDTH = _L[i] +50
- global BANDS
- BANDS = int(SPECWIDTH/5)
- for a in range(num):
- ASS_BUF = []
- bars = Spectrum(F[a])
- bar_width = SPECWIDTH/BANDS
- count = len(bars)
- P = []
- for b in range(count):
-
- start = a * 100 * 2048 / freq
-
- end = (a + 1) * 100 * 2048 / freq
-
- x = (1280 - SPECWIDTH) / 2 + bar_width * b+25
-
- y = initPosY-20
- if b < count -1:
- if bars[b]>bars[b+1] :
- if bars[b]>30:
- bars[b] = 30
- if b%2 == 0:
- P.append((x,y+bars[b]))
- else:
- P.append((x,y-bars[b]))
-
- if P != [] and start > _BT[i] and end <_ET[i]+10:
- sb = '{\p1}m '+str(int((1280 - SPECWIDTH) / 2))+' '+str(int(y))+' l '+str(int((1280 - SPECWIDTH) / 2)+25)+' '+str(int(y)) +' '+' '.join('l '+str(int(p[0]))+' '+str(int(p[1])) for p in P)+' l '+str(int((1280 - SPECWIDTH) / 2+_L[i])+50)+' '+str(int(y))
- TP = P[::-1]
- sb = sb+' l '+str(int((1280 - SPECWIDTH) / 2+_L[i])+50)+' '+str(int(y-1)) +' ' +' '.join('l '+ str(int(tp[0]))+' '+str(int(tp[1])-1) for tp in TP)+' l '+str(int((1280 - SPECWIDTH) / 2)+25)+' '+str(int(y-1)) +' l '+str(int((1280 - SPECWIDTH) / 2))+' '+str(int(y-1))
- ass_main(ASS_BUF, SubL(start, end, 1, Pix_Style), an(7) +alpha(0)+color1('000000')+bord(1)+color3('000000') +shad(1)+color4('FFFFFF') + pos(0, 0) , sb)
- WriteAssFile(ASS_FILE, ASS_BUF)
- for j in range(textNum[i]):
- COLOR =["7A90FF","49D297","CDAF50"]
-
- CLR1 = color1("FFFFFF")+color3("000000") + alpha1(0)
- ASS_BUF = []
-
- if _TXT[i][j] == '' or _TXT[i][j] == ' ' or _TXT[i][j] == ' ':
-
- continue
-
- posX = initPosX + _AD[i][j] + _A[i][j] / 2
-
- posY = initPosY - 19
- ass_main(ASS_BUF, SubL(_BT[i]+_SK[i][j]+_KT[i][j], _ET[i]+j*5, 200),fad(0,200)+ an(5) + pos(posX, posY) + CLR1+bord(1.8)+shad(1.5) ,_TXT[i][j] )
-
- ass_main(ASS_BUF, SubL(_BT[i]+_SK[i][j]-10, _BT[i]+_SK[i][j]+_KT[i][j], 200), an(5) + pos(posX, posY)+t(0,15,fsc(135,135)) +t(100,_KT[i][j]*10,fsc(100,100))+bord(1.8)+ CLR1 , _TXT[i][j])
- if i>9:
- if j == 0:
- nposX = posX - 40
- else:
- nposX = initPosX + _AD[i][j-1] + _A[i][j-1] / 2
- for q in range(3):
- C = COLOR[q]
- CLR2 = color1(C)
- POS = Bezier3( _KT[i][j],nposX,posY,posX, posY,posX+randint(-50,50), posY+randint(-75,75),posX+randint(-50,50), posY+randint(-75,75))
- for w in range(_KT[i][j]):
- ass_main(ASS_BUF, SubL(_BT[i]+_SK[i][j]-20+w*1, _BT[i]+_SK[i][j]-20+(w+1)*1,151), an(5)+bord(0)+frz(60)+shad(0)+color3(C)+color1("00FFFF")+blur(0.8) + pos(POS[w][0], POS[w][1])+fs(10), "★")
- ass_main(ASS_BUF, SubL(_BT[i]+_SK[i][j]-20+w*1, _BT[i]+_SK[i][j]-20+50+(w+1)*1,150-w), fad(50,300)+an(5)+blur(1.8)+bord(0)+shad(0)+CLR2 +t(fsc(int(280),int(50*100/_KT[i][j])))+ pos(POS[w][0], POS[w][1])+fs(5), "■")
- WriteAssFile(ASS_FILE, ASS_BUF) # write the buffer in memory to the file
-
- Progress(i,j)
- tcAudioFin()
-
- FinAssFile(ASS_FILE)
复制代码 |
-
1
查看全部评分
-
|