raylib/ports/audio/audio_sound_loading
Licence This example has its own licence, rather than Odin's: raylib/ports/LICENSE
These are ported Raylib examples, and as such, they are subject to Raylib's license.
Copyright (c) 2013-2024 Ramon Santamaria (@raysan5)
The rest of the licence
This software is provided "as-is", without any express or implied warranty. In no event
will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you
wrote the original software. If you use this software in a product, an acknowledgment
in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented
as being the original software.
3. This notice may not be removed or altered from any source distribution.
Code
audio_sound_loading.odin ¶72 linesSource
1/*******************************************************************************************
2*
3* raylib [audio] example - sound loading
4*
5* Example complexity rating: [★☆☆☆] 1/4
6*
7* Example originally created with raylib 1.1, last time updated with raylib 3.5
8*
9* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
10* BSD-like license that allows static linking with closed source software
11*
12* Copyright (c) 2014-2025 Ramon Santamaria (@raysan5)
13*
14********************************************************************************************/
15
16package raylib_examples
17
18import rl "vendor:raylib"
19
20//------------------------------------------------------------------------------------
21// Program main entry point
22//------------------------------------------------------------------------------------
23main :: proc() {
24 // Initialization
25 //--------------------------------------------------------------------------------------
26 SCREEN_WIDTH :: 800
27 SCREEN_HEIGHT :: 450
28
29 rl.InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "raylib [audio] example - sound loading")
30
31 rl.InitAudioDevice() // Initialize audio device
32
33 fx_wav := rl.LoadSound("resources/spring.wav") // Load WAV audio file
34 fx_ogg := rl.LoadSound("resources/target.ogg") // Load OGG audio file
35
36 rl.SetTargetFPS(60) // Set our game to run at 60 frames-per-second
37 //--------------------------------------------------------------------------------------
38
39 // Main game loop
40 for !rl.WindowShouldClose() { // Detect window close button or ESC key
41 // Update
42 //----------------------------------------------------------------------------------
43 if rl.IsKeyPressed(.SPACE) {
44 rl.PlaySound(fx_wav) // Play WAV sound
45 }
46 if rl.IsKeyPressed(.ENTER) {
47 rl.PlaySound(fx_ogg) // Play OGG sound
48 }
49 //----------------------------------------------------------------------------------
50
51 // Draw
52 //----------------------------------------------------------------------------------
53 rl.BeginDrawing()
54
55 rl.ClearBackground(rl.RAYWHITE)
56
57 rl.DrawText("Press SPACE to PLAY the WAV sound!", 200, 180, 20, rl.LIGHTGRAY)
58 rl.DrawText("Press ENTER to PLAY the OGG sound!", 200, 220, 20, rl.LIGHTGRAY)
59
60 rl.EndDrawing()
61 //----------------------------------------------------------------------------------
62 }
63
64 // De-Initialization
65 //--------------------------------------------------------------------------------------
66 rl.UnloadSound(fx_wav) // Unload sound data
67 rl.UnloadSound(fx_ogg) // Unload sound data
68
69 rl.CloseAudioDevice() // Close audio device
70 rl.CloseWindow() // Close window and OpenGL context
71 //--------------------------------------------------------------------------------------
72}