Update raudio_standalone.c

This commit is contained in:
raysan5 2020-07-31 12:31:40 +02:00
parent 7eb6cb470b
commit 168948d91d

View file

@ -49,13 +49,73 @@
#if defined(_WIN32)
#include <conio.h> // Windows only, no stardard library
#else
// Required for kbhit() function in non-Windows platforms
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
#include <fcntl.h>
#endif
// Provide kbhit() function in non-Windows platforms
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
#include <fcntl.h>
#define KEY_ESCAPE 27
//----------------------------------------------------------------------------------
// Module Functions Declaration
//----------------------------------------------------------------------------------
#if !defined(_WIN32)
static int kbhit(void); // Check if a key has been pressed
static char getch(); // Get pressed character
#endif
//------------------------------------------------------------------------------------
// Program main entry point
//------------------------------------------------------------------------------------
int main(int argc, char *argv[])
{
// Initialization
//--------------------------------------------------------------------------------------
static unsigned char key = 0;
InitAudioDevice();
Sound fxWav = LoadSound("resources/audio/weird.wav"); // Load WAV audio file
Sound fxOgg = LoadSound("resources/audio/target.ogg"); // Load OGG audio file
Music music = LoadMusicStream("resources/audio/country.mp3");
PlayMusicStream(music);
printf("\nPress s or d to play sounds, ESC to stop...\n");
//--------------------------------------------------------------------------------------
// Main loop
while (key != KEY_ESCAPE)
{
if (kbhit()) key = getch();
if ((key == 's') || (key == 'S')) PlaySound(fxWav);
if ((key == 'd') || (key == 'D')) PlaySound(fxOgg);
key = 0;
UpdateMusicStream(music);
}
// De-Initialization
//--------------------------------------------------------------------------------------
UnloadSound(fxWav); // Unload sound data
UnloadSound(fxOgg); // Unload sound data
UnloadMusicStream(music); // Unload music stream data
CloseAudioDevice();
//--------------------------------------------------------------------------------------
return 0;
}
//----------------------------------------------------------------------------------
// Module Functions Definition
//----------------------------------------------------------------------------------
#if !defined(_WIN32)
// Check if a key has been pressed
static int kbhit(void)
{
@ -86,57 +146,4 @@ static int kbhit(void)
// Get pressed character
static char getch() { return getchar(); }
#endif
#define KEY_ESCAPE 27
int main()
{
// Initialization
//--------------------------------------------------------------------------------------
static unsigned char key = 0;
InitAudioDevice();
Sound fxWav = LoadSound("resources/audio/weird.wav"); // Load WAV audio file
Sound fxOgg = LoadSound("resources/audio/target.ogg"); // Load OGG audio file
Music music = LoadMusicStream("resources/audio/country.mp3");
PlayMusicStream(music);
printf("\nPress s or d to play sounds, ESC to stop...\n");
//--------------------------------------------------------------------------------------
// Main loop
while (key != KEY_ESCAPE)
{
if (kbhit()) key = getch();
if (key == 's')
{
PlaySound(fxWav);
key = 0;
}
if (key == 'd')
{
PlaySound(fxOgg);
key = 0;
}
UpdateMusicStream(music);
}
// De-Initialization
//--------------------------------------------------------------------------------------
UnloadSound(fxWav); // Unload sound data
UnloadSound(fxOgg); // Unload sound data
UnloadMusicStream(music); // Unload music stream data
CloseAudioDevice();
//--------------------------------------------------------------------------------------
return 0;
}