diff --git a/examples/audio/audio_sound_loading.png b/examples/audio/audio_sound_loading.png new file mode 100644 index 0000000..24071ce Binary files /dev/null and b/examples/audio/audio_sound_loading.png differ diff --git a/examples/audio/audio_sound_loading.rb b/examples/audio/audio_sound_loading.rb new file mode 100644 index 0000000..1075949 --- /dev/null +++ b/examples/audio/audio_sound_loading.rb @@ -0,0 +1,60 @@ +# ****************************************************************************************** +# +# raylib [audio] example - Sound loading and playing +# +# Example originally created with raylib 1.1, last time updated with raylib 3.5 +# +# Example ported to Ruby by Wilson Silva (@wilsonsilva). Works with Raylib 4.5 +# +# Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, +# BSD-like license that allows static linking with closed source software +# +# Copyright (c) 2014-2023 Ramon Santamaria (@raysan5) +# +# ****************************************************************************************** + +require 'bundler/setup' +require 'raylib' + +# Initialization +# -------------------------------------------------------------------------------------- +SCREEN_WIDTH = 800 +SCREEN_HEIGHT = 450 + +Raylib.init_window(SCREEN_WIDTH, SCREEN_HEIGHT, "raylib [audio] example - sound loading and playing") + +Raylib.init_audio_device + +fx_wav = Raylib.load_sound(File.join(__dir__, "resources/sound.wav")) # Load WAV audio file +fx_ogg = Raylib.load_sound(File.join(__dir__, "resources/target.ogg")) # Load OGG audio file + +Raylib.set_target_fps(60) +# -------------------------------------------------------------------------------------- + +# Main game loop +until Raylib.window_should_close # Detect window close button or ESC key + # Update + # ---------------------------------------------------------------------------------- + Raylib.play_sound(fx_wav) if Raylib.is_key_pressed(Raylib::KEY_SPACE) # Play WAV sound + Raylib.play_sound(fx_ogg) if Raylib.is_key_pressed(Raylib::KEY_ENTER) # Play OGG sound + # ---------------------------------------------------------------------------------- + + # Draw + # ---------------------------------------------------------------------------------- + Raylib.begin_drawing + Raylib.clear_background(Raylib::RAYWHITE) + Raylib.draw_text("Press SPACE to PLAY the WAV sound!", 200, 180, 20, Raylib::LIGHTGRAY) + Raylib.draw_text("Press ENTER to PLAY the OGG sound!", 200, 220, 20, Raylib::LIGHTGRAY) + Raylib.end_drawing + # ---------------------------------------------------------------------------------- +end + +# De-Initialization +# -------------------------------------------------------------------------------------- +Raylib.unload_sound(fx_wav) # Unload sound data +Raylib.unload_sound(fx_ogg) # Unload sound data + +Raylib.close_audio_device # Close audio device + +Raylib.close_window # Close window and OpenGL context +# -------------------------------------------------------------------------------------- diff --git a/examples/audio/resources/LICENSE.md b/examples/audio/resources/LICENSE.md index 501dd5c..8f989d6 100644 --- a/examples/audio/resources/LICENSE.md +++ b/examples/audio/resources/LICENSE.md @@ -1,5 +1,7 @@ | resource | author | licence | notes | | :------------------- | :---------: | :------ | :---- | | country.mp3 | [@emegeme](https://github.com/emegeme) | [CC0](https://creativecommons.org/publicdomain/zero/1.0/) | Originally created for "DART that TARGET" game | +| target.ogg | [@emegeme](https://github.com/emegeme) | [CC0](https://creativecommons.org/publicdomain/zero/1.0/) | Originally created for "DART that TARGET" game | | coin.wav | [@raysan5](https://github.com/raysan5) | [CC0](https://creativecommons.org/publicdomain/zero/1.0/) | Made with [rFXGen](https://raylibtech.itch.io/rfxgen) | +| sound.wav | [@raysan5](https://github.com/raysan5) | [CC0](https://creativecommons.org/publicdomain/zero/1.0/) | Made with [rFXGen](https://raylibtech.itch.io/rfxgen) | | mini1111.xm | [tPORt](https://modarchive.org/index.php?request=view_by_moduleid&query=51891) | [Mod Archive Distribution license](https://modarchive.org/index.php?terms-upload) | - | diff --git a/examples/audio/resources/sound.wav b/examples/audio/resources/sound.wav new file mode 100644 index 0000000..b5d01c9 Binary files /dev/null and b/examples/audio/resources/sound.wav differ diff --git a/examples/audio/resources/target.flac b/examples/audio/resources/target.flac new file mode 100644 index 0000000..5fad22c Binary files /dev/null and b/examples/audio/resources/target.flac differ