Add README files to audio demos

This commit is contained in:
Aaron Franke 2020-03-09 03:48:22 -04:00
parent da280ec220
commit 8cdddc87ce
No known key found for this signature in database
GPG Key ID: 40A1750B977E56BF
21 changed files with 171 additions and 26 deletions

18
audio/bpm_sync/README.md Normal file
View File

@ -0,0 +1,18 @@
# Audio BPM Sync
A demo of how to sync the audio playback with the time for a consistent BPM.
Language: GDScript
Renderer: GLES 2
## How does it work?
For the sound clock, it uses methods in
[`AudioServer`](https://docs.godotengine.org/en/latest/classes/class_audioserver.html)
to sync the audio playback.
For the system clock, it uses `OS.get_ticks_usec()`.
## Screenshots
![Screenshot](screenshots/bpm.png)

View File

@ -7,10 +7,12 @@ var playing = false
const COMPENSATE_FRAMES = 2
const COMPENSATE_HZ = 60.0
const SYNC_SOURCE_SYSTEM_CLOCK = 0
const SYNC_SOURCE_SOUND_CLOCK = 1
enum SyncSource {
SYSTEM_CLOCK,
SOUND_CLOCK,
}
var sync_source = SYNC_SOURCE_SYSTEM_CLOCK
var sync_source = SyncSource.SYSTEM_CLOCK
# Used by system clock.
var time_begin
@ -25,16 +27,16 @@ func strsec(secs):
func _process(_delta):
if (!playing or !$Player.playing):
if !playing or !$Player.playing:
return
var time = 0.0
if (sync_source == SYNC_SOURCE_SYSTEM_CLOCK):
if sync_source == SyncSource.SYSTEM_CLOCK:
# Obtain from ticks.
time = (OS.get_ticks_usec() - time_begin) / 1000000.0
# Compensate.
time -= time_delay
elif (sync_source == SYNC_SOURCE_SOUND_CLOCK):
elif sync_source == SyncSource.SOUND_CLOCK:
time = $Player.get_playback_position() + AudioServer.get_time_since_last_mix() - AudioServer.get_output_latency() + (1 / COMPENSATE_HZ) * COMPENSATE_FRAMES
var beat = int(time * BPM / 60.0)
@ -44,7 +46,7 @@ func _process(_delta):
func _on_PlaySystem_pressed():
sync_source = SYNC_SOURCE_SYSTEM_CLOCK
sync_source = SyncSource.SYSTEM_CLOCK
time_begin = OS.get_ticks_usec()
time_delay = AudioServer.get_time_to_next_mix() + AudioServer.get_output_latency()
playing = true
@ -52,6 +54,6 @@ func _on_PlaySystem_pressed():
func _on_PlaySound_pressed():
sync_source = SYNC_SOURCE_SOUND_CLOCK
sync_source = SyncSource.SOUND_CLOCK
playing = true
$Player.play()

BIN
audio/bpm_sync/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 921 B

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://icon.png"
dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

View File

@ -17,6 +17,7 @@ _global_script_class_icons={
config/name="BPM Sync Demo"
run/main_scene="res://bpm_sync.tscn"
config/icon="res://icon.png"
[rendering]

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

@ -1,36 +1,37 @@
extends Control
onready var itemList = get_node("ItemList")
onready var item_list = get_node("ItemList")
func _ready():
for item in AudioServer.get_device_list():
itemList.add_item(item)
item_list.add_item(item)
var device = AudioServer.get_device()
for i in range(itemList.get_item_count()):
if device == itemList.get_item_text(i):
itemList.select(i)
for i in range(item_list.get_item_count()):
if device == item_list.get_item_text(i):
item_list.select(i)
break
func _process(_delta):
var speakerMode = "Stereo"
var speaker_mode_text = "Stereo"
var speaker_mode = AudioServer.get_speaker_mode()
if AudioServer.get_speaker_mode() == AudioServer.SPEAKER_SURROUND_31:
speakerMode = "Surround 3.1"
elif AudioServer.get_speaker_mode() == AudioServer.SPEAKER_SURROUND_51:
speakerMode = "Surround 5.1"
elif AudioServer.get_speaker_mode() == AudioServer.SPEAKER_SURROUND_71:
speakerMode = "Surround 7.1"
if speaker_mode == AudioServer.SPEAKER_SURROUND_31:
speaker_mode_text = "Surround 3.1"
elif speaker_mode == AudioServer.SPEAKER_SURROUND_51:
speaker_mode_text = "Surround 5.1"
elif speaker_mode == AudioServer.SPEAKER_SURROUND_71:
speaker_mode_text = "Surround 7.1"
$DeviceInfo.text = "Current Device: " + AudioServer.get_device() + "\n"
$DeviceInfo.text += "Speaker Mode: " + speakerMode
$DeviceInfo.text += "Speaker Mode: " + speaker_mode_text
func _on_Button_button_down():
for item in itemList.get_selected_items():
var device = itemList.get_item_text(item)
for item in item_list.get_selected_items():
var device = item_list.get_item_text(item)
AudioServer.set_device(device)

View File

@ -0,0 +1,18 @@
# Audio Device Changer
This is a demo showing how the audio output device can be changed from Godot.
Language: GDScript
Renderer: GLES 2
## How does it work?
It uses the `set_device()` method in
[`AudioServer`](https://docs.godotengine.org/en/latest/classes/class_audioserver.html)
to change the audio device.
The list of devices is populated using `get_device_list()`.
## Screenshots
![Screenshot](screenshots/device_changer.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

16
audio/generator/README.md Normal file
View File

@ -0,0 +1,16 @@
# Audio Generator
This is a demo showing how one can generate and
play audio samples from GDScript.
It plays a simple 440 Hz sine wave at 22050 Hz.
Language: GDScript
Renderer: GLES 2
## How does it work?
It uses the `push_frame()` method on an [`AudioStreamGeneratorPlayback`](https://docs.godotengine.org/en/latest/classes/class_audiostreamgeneratorplayback.html)
object, which is inside of an
[`AudioStreamPlayer`](https://docs.godotengine.org/en/latest/classes/class_audiostreamplayer.html)
node, to generate audio frame-by-frame based on `pulse_hz`.

View File

@ -10,10 +10,10 @@ func _fill_buffer():
var increment = pulse_hz / sample_hz
var to_fill = playback.get_frames_available()
while (to_fill > 0):
while to_fill > 0:
playback.push_frame(Vector2.ONE * sin(phase * TAU)) # Audio frames are stereo.
phase = fmod(phase + increment, 1.0)
to_fill -= 1;
to_fill -= 1
func _process(_delta):

View File

@ -0,0 +1,8 @@
# Audio Mic Record
This is an example showing how one can record audio from
the microphone and later play it back or save it to a file.
Language: GDScript
Renderer: GLES 2

View File

@ -15,7 +15,7 @@ _global_script_class_icons={
[application]
config/name="Mic Record Demo"
config/name="Audio Mic Record Demo"
run/main_scene="res://MicRecord.tscn"
config/icon="res://icon.png"

12
audio/spectrum/README.md Normal file
View File

@ -0,0 +1,12 @@
# Audio Spectrum
This is a demo showing how a spectrum analyzer
can be built using Godot.
Language: GDScript
Renderer: GLES 2
## Screenshots
![Screenshot](screenshots/spectrum.png)

BIN
audio/spectrum/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 398 B

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://icon.png"
dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

View File

@ -17,6 +17,7 @@ _global_script_class_icons={
config/name="Audio Spectrum Demo"
run/main_scene="res://show_spectrum.tscn"
config/icon="res://icon.png"
[rendering]

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB