1
Programs / Re: Next one Music Visualizer
« on: March 19, 2022, 05:59:34 am »That's an amazing effect. I ran a mp3 song through it and noticed the amplitude of the terrain suddenly increased significantly while the sound remained relatively the same. Must have been picking up something subtle in the encoding...
Yes, this is because it is used to visualize the line every 8192th audio sample. Then the line is moved one step closer in the Z axis (it has a higher coordinate number, the nearest visible one is -1, 0 is no longer invisible and 1 is basically in front of the monitor). For a finer display, I had each sample drawn, it's this source code, the edit is on line 39. Still, not every sample will be rendered now. Why?
In order to render virtually every sound sample, you must first determine in how many frames per second the program will run.
Suppose you set 50 frames per second for smooth graphics. For sound, this means 44100 (SNDRATE) / 50 samples per second, that is 882 samples. But that also means overwriting 882 values in memory 50 times per second.
In this program, this is solved by not tracking exactly where you ended up rendering. Simply take the current position of the sound and load more samples from it. Therefore, it can easily happen that some samples simply fall out before the whole thing is rendered.
Under line 61, the program solves normal 2D graphics for blinking background circles.
This source code try use "every" sample:
Code: QB64: [Select]
- 'sky texture
- Texture2 = NewImage(255, 255, 32)
- Dest Texture2
- 'earth texture
- Texture = NewImage(255, 255, 32)
- Dest Texture
- Dest 0
- SND = SndOpen("bb.mp3") ' <----------------- insert here your sound file name!
- VOL = 10
- SndVol SND, VOL / 20
- L = MemSound(SND, 1)
- R = MemSound(SND, 2)
- DW = DesktopWidth
- DH = DesktopHeight
- HT = CopyImage(Texture, 33)
- HT2 = CopyImage(Texture2, 33)
- FreeImage Texture
- FullScreen
- SndPlay SND
- ShiftIt = 89
- ShiftIt = ShiftIt - 1
- Depth = 0
- Depth = Depth + 2 ' This is byte counter and now use all samples not every 8192th as in previous case (first source code in this thread)
- ra = ra + 1
- ra = 0
- HX = -45 + X
- HX2 = HX + 1
- HZ = -89 + Z
- HZ2 = HZ + 1
- HY1 = -3 + M3D(X, Z): HY2 = -3 + M3D(X + 1, Z): HY3 = -3 + M3D(X, Z + 1): HY4 = -3 + M3D(X + 1, Z + 1)
- HY11 = 3 - M2D(X, Z): HY12 = 3 - M2D(X + 1, Z): HY13 = 3 - M2D(X, Z + 1): HY14 = 3 - M2D(X + 1, Z + 1)
- Next X, Z
- '----------------------------------------------------------------------------------------------------------- CIRCLES --------------------------------------------------------------
- FillCache = 0
- IntensityLeft = 0
- IntensityRight = 0
- FillCache = FillCache + 2
- IL = IntensityLeft / 2 ' recalc values as decimal
- IR = IntensityRight / 2
- CLL = 0
- IL = IL - 4.41
- CLL = CLL + 1
- MAX CLL, 10
- CLR = 0
- IR = IR - 4.41
- CLR = CLR + 1
- MAX CLR, 10
- IL = 0
- IR = 0
- Rc = 0: Gc = 255: Bc = 0
- Rc = 255: Gc = 255: Bc = 0
- Rc = 255: Gc = 0: Bc = 0
- Display
- Limit 50
- Position = SndGetPos(SND) * SndRate * 2
- ' CX = center x coordinate
- ' CY = center y coordinate
- ' R = radius
- ' C = fill color
- RadiusError = -Radius
- X = Radius
- Y = 0
- While X > Y
- RadiusError = RadiusError + Y * 2 + 1
- X = X - 1
- RadiusError = RadiusError - X * 2
- Y = Y + 1
Due to the adjustment, I also had to adjust the rendering of the circles. This brought a noticeable increase in speed (not so many shades are used anymore, only about 5 for the color intensity of the circle)