Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules. |
6th September 2015, 02:15 | #1 | Link |
Retried Guesser
Join Date: Jun 2012
Posts: 1,373
|
Audio Spectrum Analyzer [avisynth gone wrong]
Do you need an 18 band audio spectrum analyzer (or analyser)? Of course you do.
What is it worth to you? Oh, nothing, huh? Well okay, here you go. No plugins needed, just vanilla Avisynth... (It's just for fun, and to demonstrate SuperEQ) (Only tested on Avisynth 2.60 at the moment; AVS+ has a problem) (EDIT April 2016 - fixed! But SuperEQ is not supported on AVS+ ?) Code:
V=ColorBarsHD ## any video A=V ## any audio Z=Analyzer18(V, A) \ .ChangeFPS(V) ## return to original framerate Overlay(V, Z, \ x=V.Width/2-Z.Width/2, \ y=V.Height-Z.Height, \ opacity=1.0, \ mode="blend") AudioDub(A) ConvertAudioTo16bit ## optional, rq'd for VirtualDub return Last # http://forum.doom9.org/showthread.php?t=172569 ################################## ### 18 Band Audio Spectrum Analyzer ## ## @ updatefps - set according to available compute power; default 5 ## ## @ return YV12, 640x334, fps=(updatefps) ## function Analyzer18(clip V, clip A, int "updatefps") { updatefps = Default(updatefps, 5) BlankClip(V, width=640, height=480, pixel_type="YV12") AudioDub(A) ConvertToMono ConvertAudioToFloat ## 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 B01=SuperEQ( 0,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99) B02=SuperEQ(-99, 0,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99) B03=SuperEQ(-99,-99, 0,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99) B04=SuperEQ(-99,-99,-99, 0,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99) B05=SuperEQ(-99,-99,-99,-99, 0,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99) B06=SuperEQ(-99,-99,-99,-99,-99, 0,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99) B07=SuperEQ(-99,-99,-99,-99,-99,-99, 0,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99) B08=SuperEQ(-99,-99,-99,-99,-99,-99,-99, 0,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99) B09=SuperEQ(-99,-99,-99,-99,-99,-99,-99,-99, 0,-99,-99,-99,-99,-99,-99,-99,-99,-99) B10=SuperEQ(-99,-99,-99,-99,-99,-99,-99,-99,-99, 0,-99,-99,-99,-99,-99,-99,-99,-99) B11=SuperEQ(-99,-99,-99,-99,-99,-99,-99,-99,-99,-99, 0,-99,-99,-99,-99,-99,-99,-99) B12=SuperEQ(-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99, 0,-99,-99,-99,-99,-99,-99) B13=SuperEQ(-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99, 0,-99,-99,-99,-99,-99) B14=SuperEQ(-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99, 0,-99,-99,-99,-99) B15=SuperEQ(-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99, 0,-99,-99,-99) B16=SuperEQ(-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99, 0,-99,-99) B17=SuperEQ(-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99, 0,-99) B18=SuperEQ(-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99, 0) MergeChannels(B01, B02, B03, B04, B05, B06, B07, B08, B09, B10, B11, B12, B13, B14, B15, B16, B17, B18) ChangeFPS(updatefps) Histogram("audiolevels") ## the magic happens Crop(0, 0, 640, 326) ## crop off some crud AddBorders(0, 8, 0, 0) ## top border yy = Height-8 cc = color_yellow Subtitle("0 - 65", x=16, y=yy, font_angle=90, text_color=cc) Subtitle("65 - 93", x=48, y=yy, font_angle=90, text_color=cc) Subtitle("93 - 131", x=78, y=yy, font_angle=90, text_color=cc) Subtitle("131 -185", x=108, y=yy, font_angle=90, text_color=cc) Subtitle("185 -262", x=142, y=yy, font_angle=90, text_color=cc) Subtitle("262 -370", x=172, y=yy, font_angle=90, text_color=cc) Subtitle("370 -523", x=206, y=yy, font_angle=90, text_color=cc) Subtitle("523 -740", x=238, y=yy, font_angle=90, text_color=cc) Subtitle("740 -1047", x=268, y=yy, font_angle=90, text_color=cc) Subtitle("1047-1480", x=300, y=yy, font_angle=90, text_color=cc) Subtitle("1480-2093", x=332, y=yy, font_angle=90, text_color=cc) Subtitle("2093-2960", x=366, y=yy, font_angle=90, text_color=cc) Subtitle("2960-4186", x=396, y=yy, font_angle=90, text_color=cc) Subtitle("4186-5920", x=426, y=yy, font_angle=90, text_color=cc) Subtitle("5920-8372", x=456, y=yy, font_angle=90, text_color=cc) Subtitle("8372-11k8", x=490, y=yy, font_angle=90, text_color=cc) Subtitle("11k8-16k7", x=526, y=yy, font_angle=90, text_color=cc) Subtitle("16k7-22ką", x=558, y=yy, font_angle=90, text_color=cc) return Last } Last edited by raffriff42; 17th March 2017 at 00:08. Reason: (fixed image link) |
4th January 2022, 00:52 | #2 | Link |
SuperVirus
Join Date: Jun 2012
Location: Antarctic Japan
Posts: 1,351
|
TL;DR — There should exist a plugin or an internal filter for the audio spectrum analyzer. :-/
---------- Using SuperEQ + Histogram("AudioLevels") is an idea that I had when I finally moved to Avisynth 2.58 — i.o.w., in 2010. But until yesterday I had not given it a try simply because I don't like the colors green and blue in the volume bars... I suppose it should not be terribly-complicated to give to the users the options to change the colors, to choose whether to display or not the numeric values, to hide or not the volume bars, whatever. But I can be wrong, of course. For the notes (1): SuperEQ is slow, and using it 18 times in the same script makes everything incredibly slow. :-/ For the notes (2): I also heavily modified your analog VU meter .avsi code ( https://forum.doom9.org/showthread.php?t=175370 ) so that it could function as a "pure" peakmeter+RMSmeter emulator. The trick worked. What didn't work well, of course, was the SuperEQ step. The output is even slower than the workaround with Histogram("AudioLevels"). CONCLUSION: There should exist a plugin or an internal filter for the audio spectrum analyzer. Last edited by filler56789; 4th January 2022 at 07:31. |
4th January 2022, 01:47 | #3 | Link | |
Registered User
Join Date: Jan 2018
Posts: 2,156
|
Quote:
|
|
4th January 2022, 08:09 | #4 | Link |
SuperVirus
Join Date: Jun 2012
Location: Antarctic Japan
Posts: 1,351
|
Yes. BUT please NOTICE, this is a quick-and-dirty modification,
it can be and should be cleaned /improved. Code:
### Digital Audio Peak Meter ## requires MinMaxAudio ## http://wilbertdijkhof.com/ ## http://forum.doom9.org/showthread.php?t=127530 global g_vu_lite = ScriptDir + "\peakmeter-8001.png" ### = a 40x606 BLACK RECTANGLE. global g_vu_dark = ScriptDir + "\peakmeter-8002.png" ################################## ## ## @ C - source of audio, framerate and duration (and nothing else) ## (call GetChannel(n) to meter a single channel) ## @ name - a short name; required - MUST be a valid AviSynth variable name, or "" (empty) ## (suggest "L" for left channel, "R" for right, etc) ## @ dark - default false, if true, show white-on-dark-background style meter ## ## @ showpeak - always true ## @ shownums - default false; if true, show digital readout of peak level (like Histogram) ## ## NOTE - all options except 'name' apply to all meters in the script (due to reuse of global variables) ## ## ## function Peak_Meter(clip C, string name, bool "dark", \ bool "showpeak", bool "shownums") { showpeak = Default(showpeak, true) global vu_dark = Default(dark, false) global vu_nums = Default(shownums, false) I = ImageSource(vu_dark ? g_vu_dark : g_vu_lite) frnum = C.FrameRateNumerator frnum = (C.FrameRate<22.0) ? 3 * frnum \ : (C.FrameRate<33.0) ? 2 * frnum \ : frnum I = I.Trim(0, length=1) \ .Loop(C.FrameCount) \ .ChangeFPS(frnum, C.FrameRateDenominator) \ .AudioDub(C) Assert(IsClip(I), \ "Peak_Meter: internal error 10") # # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ F_pre = \ face_prerender(I, name, vu_dark, showpeak, 0) \ + face_prerender(I, name, vu_dark, showpeak, 1) \ + face_prerender(I, name, vu_dark, showpeak, 2) \ + face_prerender(I, name, vu_dark, showpeak, 3) \ + face_prerender(I, name, vu_dark, showpeak, 4) \ + face_prerender(I, name, vu_dark, showpeak, 5) \ + face_prerender(I, name, vu_dark, showpeak, 6) \ + face_prerender(I, name, vu_dark, showpeak, 7) \ + face_prerender(I, name, vu_dark, showpeak, 8) \ + face_prerender(I, name, vu_dark, showpeak, 9) \ + face_prerender(I, name, vu_dark, showpeak, 10) \ + face_prerender(I, name, vu_dark, showpeak, 11) \ + face_prerender(I, name, vu_dark, showpeak, 12) \ + face_prerender(I, name, vu_dark, showpeak, 13) \ + face_prerender(I, name, vu_dark, showpeak, 14) \ + face_prerender(I, name, vu_dark, showpeak, 15) \ + face_prerender(I, name, vu_dark, showpeak, 16) \ + face_prerender(I, name, vu_dark, showpeak, 17) \ + face_prerender(I, name, vu_dark, showpeak, 18) \ + face_prerender(I, name, vu_dark, showpeak, 19) \ + face_prerender(I, name, vu_dark, showpeak, 20) # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ Assert(IsClip(F_pre), \ "Peak_Meter: internal error 30") Eval("global " + name + "_F_pre = F_pre") #return Eval("L_F_pre") ScriptClip(I, """ ## backgound "faceplate" with prerendered peak LED's <<<<<<<<<<<<<<<<<<<<<<< # amap = AudioMax # amap = Max(-10.5, amap) ##### -1.99, -3.99, -5.99 amax = AudioMax amax = Max(-96.0, amax) # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ B = (amax>(-1.00)) ? """ + name + """_F_pre.Trim(20, length=1) \ : (amax>(-2.00)) ? """ + name + """_F_pre.Trim(19, length=1) \ : (amax>(-3.00)) ? """ + name + """_F_pre.Trim(18, length=1) \ : (amax>(-4.00)) ? """ + name + """_F_pre.Trim(17, length=1) \ : (amax>(-5.00)) ? """ + name + """_F_pre.Trim(16, length=1) \ : (amax>(-6.00)) ? """ + name + """_F_pre.Trim(15, length=1) \ : (amax>(-7.00)) ? """ + name + """_F_pre.Trim(14, length=1) \ : (amax>(-8.00)) ? """ + name + """_F_pre.Trim(13, length=1) \ : (amax>(-9.00)) ? """ + name + """_F_pre.Trim(12, length=1) \ : (amax>(-10.00)) ? """ + name + """_F_pre.Trim(11, length=1) \ : (amax>(-11.00)) ? """ + name + """_F_pre.Trim(10, length=1) \ : (amax>(-12.00)) ? """ + name + """_F_pre.Trim(9, length=1) \ : (amax>(-13.00)) ? """ + name + """_F_pre.Trim(8, length=1) \ : (amax>(-14.00)) ? """ + name + """_F_pre.Trim(7, length=1) \ : (amax>(-15.00)) ? """ + name + """_F_pre.Trim(6, length=1) \ : (amax>(-16.00)) ? """ + name + """_F_pre.Trim(5, length=1) \ : (amax>(-17.00)) ? """ + name + """_F_pre.Trim(4, length=1) \ : (amax>(-18.00)) ? """ + name + """_F_pre.Trim(3, length=1) \ : (amax>(-19.00)) ? """ + name + """_F_pre.Trim(2, length=1) \ : (amax>(-20.00)) ? """ + name + """_F_pre.Trim(1, length=1) \ : """ + name + """_F_pre.Trim(0, length=1) # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ # B.Loop(FrameCount) Assert(IsClip, \ "Peak_Meter: internal error 50") ## numeric readout §§§§§§§§§§§§§§ SHOW LEVEL NUMBERS §§§§§§§§§§§§§§§§§§§ cnul = $ff000000 ## transparent color ### ###"Digital-7 Mono" (!vu_nums) ? Last \ : Subtitle(String(amax, "%0.1f"), size=26, font="Droid Sans Mono", \ text_color=$ffffff, halo_color=cnul, \ align=3, x=116.5, y=220) """) Assert(IsClip, \ "Peak_Meter: internal error 90") (FrameRateNumerator==C.FrameRateNumerator) ? Last \ : ChangeFPS(C) return Last.Trim(0, length=C.FrameCount) } # ################################## ### 1-frame clip showing the "faceplate" with selected number of peak LED's lit ## ## @ showpeak - always TRUE (to support FALSE, need to create faceplate images without bezels) ## function face_prerender(clip C, string name, bool dark, \ bool showpeak, int peak) { ctxt = $000000 ## text $707070 cnul = $ff000000 ## transparent color c_hi_2 = $ffffff c_hi_1 = $00e0ff c_mid2 = $fefe00 c_mid1 = $ddee00 c_low2 = $ffc500 c_low1 = $dfb300 c_low0 = $bfa100 c_off = $101010 ## LED off #279;141 --> 303;212 pksz = 24.0 ## LED size !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! = 16.0 fcir = "g" ## Marlett filled square = "g" ######### LED positions ###################################### x1 = 19.5 x2 = x1 x3 = x1 x4 = x1 x5 = x1 x6 = x1 x7 = x1 x8 = x1 x9 = x1 x10 = x1 x11 = x1 x12 = x1 x13 = x1 x14 = x1 x15 = x1 x16 = x1 x17 = x1 x18 = x1 x19 = x1 x20 = x1 # y20 = 29.5 y19 = y20 + (1 * 30) y18 = y20 + (2 * 30) y17 = y20 + (3 * 30) y16 = y20 + (4 * 30) y15 = y20 + (5 * 30) y14 = y20 + (6 * 30) y13 = y20 + (7 * 30) y12 = y20 + (8 * 30) y11 = y20 + (9 * 30) y10 = y20 + (10 * 30) y9 = y20 + (11 * 30) y8 = y20 + (12 * 30) y7 = y20 + (13 * 30) y6 = y20 + (14 * 30) y5 = y20 + (15 * 30) y4 = y20 + (16 * 30) y3 = y20 + (17 * 30) y2 = y20 + (18 * 30) y1 = y20 + (19 * 30) C ##### # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ ##### LEDs (peak indicators) ### ## new colors: credd, c_low1, c_low2, c_mid1, c_mid2, c_hi_1, c_hi_2 (peak<1) ? Last \ : Subtitle(fcir, font="Marlett", size=pksz, \ text_color=c_hi_2, halo_color=cnul, \ x=x1, y=y1, align=5) (peak<2) ? Last \ : Subtitle(fcir, font="Marlett", size=pksz, \ text_color=c_hi_2, halo_color=cnul, \ x=x2, y=y2, align=5) (peak<3) ? Last \ : Subtitle(fcir, font="Marlett", size=pksz, \ text_color=c_hi_2, halo_color=cnul, \ x=x3, y=y3, align=5) (peak<4) ? Last \ : Subtitle(fcir, font="Marlett", size=pksz, \ text_color=c_hi_2, halo_color=cnul, \ x=x4, y=y4, align=5) (peak<5) ? Last \ : Subtitle(fcir, font="Marlett", size=pksz, \ text_color=c_hi_2, halo_color=cnul, \ x=x5, y=y5, align=5) (peak<6) ? Last \ : Subtitle(fcir, font="Marlett", size=pksz, \ text_color=c_hi_2, halo_color=cnul, \ x=x6, y=y6, align=5) (peak<7) ? Last \ : Subtitle(fcir, font="Marlett", size=pksz, \ text_color=c_hi_2, halo_color=cnul, \ x=x7, y=y7, align=5) (peak<8) ? Last \ : Subtitle(fcir, font="Marlett", size=pksz, \ text_color=c_hi_2, halo_color=cnul, \ x=x8, y=y8, align=5) (peak<9) ? Last \ : Subtitle(fcir, font="Marlett", size=pksz, \ text_color=c_hi_2, halo_color=cnul, \ x=x9, y=y9, align=5) (peak<10) ? Last \ : Subtitle(fcir, font="Marlett", size=pksz, \ text_color=c_hi_2, halo_color=cnul, \ x=x10, y=y10, align=5) (peak<11) ? Last \ : Subtitle(fcir, font="Marlett", size=pksz, \ text_color=c_hi_2, halo_color=cnul, \ x=x11, y=y11, align=5) (peak<12) ? Last \ : Subtitle(fcir, font="Marlett", size=pksz, \ text_color=c_hi_2, halo_color=cnul, \ x=x12, y=y12, align=5) (peak<13) ? Last \ : Subtitle(fcir, font="Marlett", size=pksz, \ text_color=c_hi_2, halo_color=cnul, \ x=x13, y=y13, align=5) (peak<14) ? Last \ : Subtitle(fcir, font="Marlett", size=pksz, \ text_color=c_hi_2, halo_color=cnul, \ x=x14, y=y14, align=5) (peak<15) ? Last \ : Subtitle(fcir, font="Marlett", size=pksz, \ text_color=c_hi_2, halo_color=cnul, \ x=x15, y=y15, align=5) (peak<16) ? Last \ : Subtitle(fcir, font="Marlett", size=pksz, \ text_color=c_hi_2, halo_color=cnul, \ x=x16, y=y16, align=5) (peak<17) ? Last \ : Subtitle(fcir, font="Marlett", size=pksz, \ text_color=c_hi_2, halo_color=cnul, \ x=x17, y=y17, align=5) (peak<18) ? Last \ : Subtitle(fcir, font="Marlett", size=pksz, \ text_color=c_hi_2, halo_color=cnul, \ x=x18, y=y18, align=5) (peak<19) ? Last \ : Subtitle(fcir, font="Marlett", size=pksz, \ text_color=c_hi_2, halo_color=cnul, \ x=x19, y=y19, align=5) (peak<20) ? Last \ : Subtitle(fcir, font="Marlett", size=pksz, \ text_color=c_hi_2, halo_color=cnul, \ x=x20, y=y20, align=5) return Trim(0, length=1) } ################################## ### Like Subtitle, but with alpha information ## All arguments are identical to Subtitle, except: ## @ C - must be RGB32 ## @ halo_width - if < 1, halo is disabled; ## if >= 1, same as standard Subtitle halo. ## (default = 1) ## ## @ returns RGB32 subtitle with mask channel ## function subtitle_alpha(clip C, string text, float "x", float "y", \ int "first_frame", int "last_frame", \ string "font", int "size", \ int "text_color", int "halo_color", \ int "align", int "spc", int "lsp", \ float "font_width", float "font_angle", \ bool "interlaced", int "halo_width") { Assert(C.IsRGB32, \ "subtitle_alpha: source clip must be RGB32") text_color = Default(text_color, $ffff00) halo_color = Default(halo_color, $0) halo_width = Default(halo_width, 1) text_alpha = text_color.BitRShiftU(24).BitAnd($ff) halo_alpha = halo_color.BitRShiftU(24).BitAnd($ff) R = C.Subtitle(text, x, y, first_frame, last_frame, \ font, size, text_color, halo_color, align, \ spc, lsp, font_width, font_angle, interlaced) text_color = MakeRGBA(text_alpha, text_alpha, text_alpha, $0) halo_color = MakeRGBA(halo_alpha, halo_alpha, halo_alpha, $0) M = C.BlankClip(pixel_type="YV12") \ .Subtitle(text, x, y, first_frame, last_frame, \ font, size, $ffffff, (halo_width<1 ? $0 : $ffffff), align, \ spc, lsp, font_width, font_angle, interlaced) \ .ColorYUV(levels="TV->PC") return MergeARGB(M, R, R, R) } ####################################### ### given 'R', 'G', 'B', 'A' return an Avisynth color ## function MakeRGBA(int r, int g, int b, int a) { r = Min(Max(0, r), 255) g = Min(Max(0, g), 255) b = Min(Max(0, b), 255) a = Min(Max(0, a), 255) return a.BitLShift(24) \ .BitOr(r.BitLShift(16)) \ .BitOr(g.BitLShift(8)) \ .BitOr(b) } ####################################### ### "slip" (advance or delay) a clip in time. ## Adds head or tail padding; clip is normally Trimmed later. ## ## @ C - clip to be advanced or delayed ## @ offset - if positive, clip is advanced; ## if negative, clip is delayed ## function Slip(clip C, int offset) { lenTrim = (offset > 0) ? offset : 0 lenPad = (offset < 0) ? -offset : 0 C = (lenPad==0) ? C \ : C.Trim(0, -1).Loop(lenPad) + C.Trim(0, C.Framecount-lenPad) C = (lenTrim==0) ? C \ : C.Trim(lenTrim, 0) + C.Trim(C.Framecount-lenTrim, -1).Loop(lenTrim) return C } ####################################### ### given Avisynth color, set its transparency ## @ a - 0.0 = transparent, 1.0 = opaque. ## function transparent_color(float a, int color) { a = 255 - Min(Max(0, Round(a * 256.0)), 255) return BitOr(a.BitLShift(24), BitAnd(color, $ffffff)) } ##### |
Thread Tools | Search this Thread |
Display Modes | |
|
|