- UID
- 3
- 积分
- 8169
- 帖子
- 259
- 主题
- 68
- 论坛币
- 5016
- 威望
- 54
- EP值
- 2533
- MP值
- 20
- 阅读权限
- 200
- 注册时间
- 2011-8-3
- 在线时间
- 1097 小时
- 最后登录
- 2022-10-8
|
嘛 ASS生成太大了 用處不大
只是結合這個 也比較好理解 頻譜是怎麼一回事
有興趣的可以寫一些 自己的頻譜
思路上建議不用拘泥于傳統頻譜 水波式的發散頻譜 或者是某種圖形 四周的點作為波形點 不規則拉升- from tcaxPy import *
-
- from util.tcAudio import *
- SPECHEIGHT = 127 #頻譜高度
- SPECWIDTH = 300 #頻譜寬度(太寬了很卡 測試可以更小一點 到500 我就crash沒壓出來。。。)
- BANDS = 300 #柱狀條數(波形頻譜和寬度一樣)
- 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)
- hStr1 = "{\p1}m 0 0 l 0 -70 l 1 0 l 0 70 l 0 0"
- hStr2 = "{\p1}m 0 0 l 0 -50 l 1 0 l 0 50 l 0 0"
- for i in range(num):
-
- ASS_BUF = []
-
- fft = tcAudioGetFFT(channel, 2048)
-
- bars = Spectrum(fft)
-
- bar_width = int(SPECWIDTH / BANDS)
-
- count = len(bars)
-
- for j in range(count):
-
- start = i * 100 * 2048 / freq
-
- end = (i + 1) * 100 * 2048 / freq
-
- x = (1280 - SPECWIDTH) / 2 + bar_width * j
-
- y = 500
-
- FSC = fsc((bar_width) * 100, bars[j] * 2)
-
- CLR1 = color1("FFBD00") + alpha1(0)
-
- CLR2 = color1("FFFFFF") + alpha1(119)
- ass_main(ASS_BUF, SubL(start, end, 0, Pix_Style), an(7) +blur(0.8) + pos(x, y) + FSC + CLR1, hStr1)
- ass_main(ASS_BUF, SubL(start, end, 1, Pix_Style), an(7) +blur(0.8) + pos(x, y) + FSC + CLR2, hStr2)
- WriteAssFile(ASS_FILE, ASS_BUF) # write the buffer in memory to the file
-
- progress(i + 1, num)
-
- tcAudioFin()
-
- FinAssFile(ASS_FILE)
复制代码 |
-
1
查看全部评分
-
|