1/*******************************************************************************************
2*
3* raylib [audio] example - Using raudio module as standalone module
4*
5* NOTE: This example does not require any graphic device, it can run directly on console.
6*
7* DEPENDENCIES:
8* mini_al.h - Audio device management lib (https://github.com/dr-soft/mini_al)
9* stb_vorbis.h - Ogg audio files loading (http://www.nothings.org/stb_vorbis/)
10* dr_mp3.h - MP3 audio file loading (https://github.com/mackron/dr_libs)
11* dr_flac.h - FLAC audio file loading (https://github.com/mackron/dr_libs)
12* jar_xm.h - XM module file loading
13* jar_mod.h - MOD audio file loading
14*
15* COMPILATION:
16* gcc -o raudio_standalone.exe raudio_standalone.c ..\..\src\raudio.c /
17* -I..\..\src -I..\..\src\external -L. -Wall -std=c99 -DRAUDIO_STANDALONE /
18* -DSUPPORT_FILEFORMAT_WAV -DSUPPORT_FILEFORMAT_OGG -DSUPPORT_FILEFORMAT_MP3
19*
20* LICENSE: zlib/libpng
21*
22* This example is licensed under an unmodified zlib/libpng license, which is an OSI-certified,
23* BSD-like license that allows static linking with closed source software:
24*
25* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5)
26*
27* This software is provided "as-is", without any express or implied warranty. In no event
28* will the authors be held liable for any damages arising from the use of this software.
29*
30* Permission is granted to anyone to use this software for any purpose, including commercial
31* applications, and to alter it and redistribute it freely, subject to the following restrictions:
32*
33* 1. The origin of this software must not be misrepresented; you must not claim that you
34* wrote the original software. If you use this software in a product, an acknowledgment
35* in the product documentation would be appreciated but is not required.
36*
37* 2. Altered source versions must be plainly marked as such, and must not be misrepresented
38* as being the original software.
39*
40* 3. This notice may not be removed or altered from any source distribution.
41*
42********************************************************************************************/
43
44#include "raudio.h" // raylib audio library
45
46#include <stdio.h> // Required for: printf()
47
48#if defined(_WIN32)
49 #include <conio.h> // Windows only, no stardard library
50#else
51
52// Provide kbhit() function in non-Windows platforms
53#include <stdio.h>
54#include <termios.h>
55#include <unistd.h>
56#include <fcntl.h>
57
58// Check if a key has been pressed
59static int kbhit(void)
60{
61 struct termios oldt, newt;
62 int ch;
63 int oldf;
64
65 tcgetattr(STDIN_FILENO, &oldt);
66 newt = oldt;
67 newt.c_lflag &= ~(ICANON | ECHO);
68 tcsetattr(STDIN_FILENO, TCSANOW, &newt);
69 oldf = fcntl(STDIN_FILENO, F_GETFL, 0);
70 fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK);
71
72 ch = getchar();
73
74 tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
75 fcntl(STDIN_FILENO, F_SETFL, oldf);
76
77 if (ch != EOF)
78 {
79 ungetc(ch, stdin);
80 return 1;
81 }
82
83 return 0;
84}
85
86// Get pressed character
87static char getch() { return getchar(); }
88
89#endif
90
91#define KEY_ESCAPE 27
92
93int main()
94{
95 // Initialization
96 //--------------------------------------------------------------------------------------
97 static unsigned char key = 0;
98
99 InitAudioDevice();
100
101 Sound fxWav = LoadSound("resources/audio/weird.wav"); // Load WAV audio file
102 Sound fxOgg = LoadSound("resources/audio/tanatana.ogg"); // Load OGG audio file
103
104 Music music = LoadMusicStream("resources/audio/guitar_noodling.ogg");
105 PlayMusicStream(music);
106
107 printf("\nPress s or d to play sounds...\n");
108 //--------------------------------------------------------------------------------------
109
110 // Main loop
111 while (key != KEY_ESCAPE)
112 {
113 if (kbhit()) key = getch();
114
115 if (key == 's')
116 {
117 PlaySound(fxWav);
118 key = 0;
119 }
120
121 if (key == 'd')
122 {
123 PlaySound(fxOgg);
124 key = 0;
125 }
126
127 UpdateMusicStream(music);
128 }
129
130 // De-Initialization
131 //--------------------------------------------------------------------------------------
132 UnloadSound(fxWav); // Unload sound data
133 UnloadSound(fxOgg); // Unload sound data
134
135 UnloadMusicStream(music); // Unload music stream data
136
137 CloseAudioDevice();
138 //--------------------------------------------------------------------------------------
139
140 return 0;
141}
142