Improve Audio Spectrum demo

- Draw fake reflections for spectrum bars.
- Increase the bars' height to better make use of the window space.
- Use Compatibility rendering method for greater performance
  and compatibility.
- Update screenshot and icon.
- Remove a stray `.import` file.
This commit is contained in:
Hugo Locurcio
2023-02-26 18:09:32 +01:00
parent e03d6abbc8
commit 6df3667072
9 changed files with 22 additions and 27 deletions

View File

@@ -4,10 +4,10 @@ This is a demo showing how a spectrum analyzer can be built using Godot.
Language: GDScript
Renderer: GLES 2
Renderer: Compatibility
Check out this demo on the asset library: https://godotengine.org/asset-library/asset/528
## Screenshots
![Screenshot](screenshots/spectrum.png)
![Screenshot](screenshots/spectrum.webp)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 162 B

After

Width:  |  Height:  |  Size: 3.8 KiB

View File

@@ -16,9 +16,9 @@ dest_files=["res://.godot/imported/icon.png-487276ed1e3a0c39cad0279d744ee560.cte
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/bptc_ldr=0
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false

View File

@@ -1,21 +0,0 @@
[remap]
importer="wav"
type="AudioStreamSample"
path="res://.godot/imported/maldita.wav-82d9f1ad42df5bdfaeda0654a708cb7a.sample"
[deps]
source_file="res://maldita.wav"
dest_files=["res://.godot/imported/maldita.wav-82d9f1ad42df5bdfaeda0654a708cb7a.sample"]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=true
edit/normalize=true
edit/loop=false
compress/mode=0

View File

@@ -25,6 +25,8 @@ window/stretch/aspect="expand"
[rendering]
renderer/rendering_method="gl_compatibility"
renderer/rendering_method.mobile="gl_compatibility"
environment/defaults/default_clear_color=Color(0.12549, 0.12549, 0.12549, 1)
quality/driver/driver_name="GLES2"
vram_compression/import_etc=true

Binary file not shown.

Before

Width:  |  Height:  |  Size: 630 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

@@ -4,7 +4,7 @@ const VU_COUNT = 16
const FREQ_MAX = 11050.0
const WIDTH = 800
const HEIGHT = 200
const HEIGHT = 250
const MIN_DB = 60
@@ -30,6 +30,20 @@ func _draw():
2.0,
true
)
# Draw a reflection of the bars with lower opacity.
draw_rect(
Rect2(w * i, HEIGHT, w - 2, height),
Color.from_hsv(float(VU_COUNT * 0.6 + i * 0.5) / VU_COUNT, 0.5, 0.6) * Color(1, 1, 1, 0.125)
)
draw_line(
Vector2(w * i, HEIGHT + height),
Vector2(w * i + w - 2, HEIGHT + height),
Color.from_hsv(float(VU_COUNT * 0.6 + i * 0.5) / VU_COUNT, 0.5, 1.0) * Color(1, 1, 1, 0.125),
2.0,
true
)
prev_hz = hz

View File

@@ -4,7 +4,7 @@
[ext_resource type="AudioStream" uid="uid://dl3ppges2sw77" path="res://maldita.ogg" id="2"]
[node name="ShowSpectrum" type="Node2D"]
position = Vector2(136, 224)
position = Vector2(136, 80)
script = ExtResource("1")
[node name="Player" type="AudioStreamPlayer" parent="."]
@@ -12,5 +12,5 @@ stream = ExtResource("2")
autoplay = true
[node name="Camera2D" type="Camera2D" parent="."]
position = Vector2(0, 144)
offset = Vector2(440, 100)
current = true