Decoupling audio module from raylib
Now audio module can be used as standalone module
This commit is contained in:
parent
067b884f39
commit
f7acee9221
2 changed files with 111 additions and 2 deletions
|
@ -8,7 +8,7 @@
|
||||||
* OpenAL Soft - Audio device management lib (http://kcat.strangesoft.net/openal.html)
|
* OpenAL Soft - Audio device management lib (http://kcat.strangesoft.net/openal.html)
|
||||||
* stb_vorbis - Ogg audio files loading (http://www.nothings.org/stb_vorbis/)
|
* stb_vorbis - Ogg audio files loading (http://www.nothings.org/stb_vorbis/)
|
||||||
*
|
*
|
||||||
* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com)
|
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
||||||
*
|
*
|
||||||
* This software is provided "as-is", without any express or implied warranty. In no event
|
* 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.
|
* will the authors be held liable for any damages arising from the use of this software.
|
||||||
|
@ -27,7 +27,13 @@
|
||||||
*
|
*
|
||||||
**********************************************************************************************/
|
**********************************************************************************************/
|
||||||
|
|
||||||
|
//#define AUDIO_STANDALONE // NOTE: To use the audio module as standalone lib, just uncomment this line
|
||||||
|
|
||||||
|
#if defined(AUDIO_STANDALONE)
|
||||||
|
#include "audio.h"
|
||||||
|
#else
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "AL/al.h" // OpenAL basic header
|
#include "AL/al.h" // OpenAL basic header
|
||||||
#include "AL/alc.h" // OpenAL context header (like OpenGL, OpenAL requires a context to work)
|
#include "AL/alc.h" // OpenAL context header (like OpenGL, OpenAL requires a context to work)
|
||||||
|
|
103
src/audio.h
Normal file
103
src/audio.h
Normal file
|
@ -0,0 +1,103 @@
|
||||||
|
/**********************************************************************************************
|
||||||
|
*
|
||||||
|
* raylib.audio
|
||||||
|
*
|
||||||
|
* Basic functions to manage Audio: InitAudioDevice, LoadAudioFiles, PlayAudioFiles
|
||||||
|
*
|
||||||
|
* Uses external lib:
|
||||||
|
* OpenAL Soft - Audio device management lib (http://kcat.strangesoft.net/openal.html)
|
||||||
|
* stb_vorbis - Ogg audio files loading (http://www.nothings.org/stb_vorbis/)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
**********************************************************************************************/
|
||||||
|
|
||||||
|
#ifndef AUDIO_H
|
||||||
|
#define AUDIO_H
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Defines and Macros
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
//...
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Types and Structures Definition
|
||||||
|
// NOTE: Below types are required for CAMERA_STANDALONE usage
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
#ifndef __cplusplus
|
||||||
|
// Boolean type
|
||||||
|
typedef enum { false, true } bool;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Sound source type
|
||||||
|
typedef struct Sound {
|
||||||
|
unsigned int source;
|
||||||
|
unsigned int buffer;
|
||||||
|
} Sound;
|
||||||
|
|
||||||
|
// Wave type, defines audio wave data
|
||||||
|
typedef struct Wave {
|
||||||
|
void *data; // Buffer data pointer
|
||||||
|
unsigned int dataSize; // Data size in bytes
|
||||||
|
unsigned int sampleRate;
|
||||||
|
short bitsPerSample;
|
||||||
|
short channels;
|
||||||
|
} Wave;
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" { // Prevents name mangling of functions
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Global Variables Definition
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
//...
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Module Functions Declaration
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
void InitAudioDevice(void); // Initialize audio device and context
|
||||||
|
void CloseAudioDevice(void); // Close the audio device and context (and music stream)
|
||||||
|
|
||||||
|
Sound LoadSound(char *fileName); // Load sound to memory
|
||||||
|
Sound LoadSoundFromWave(Wave wave); // Load sound to memory from wave data
|
||||||
|
Sound LoadSoundFromRES(const char *rresName, int resId); // Load sound to memory from rRES file (raylib Resource)
|
||||||
|
void UnloadSound(Sound sound); // Unload sound
|
||||||
|
void PlaySound(Sound sound); // Play a sound
|
||||||
|
void PauseSound(Sound sound); // Pause a sound
|
||||||
|
void StopSound(Sound sound); // Stop playing a sound
|
||||||
|
bool SoundIsPlaying(Sound sound); // Check if a sound is currently playing
|
||||||
|
void SetSoundVolume(Sound sound, float volume); // Set volume for a sound (1.0 is max level)
|
||||||
|
void SetSoundPitch(Sound sound, float pitch); // Set pitch for a sound (1.0 is base level)
|
||||||
|
|
||||||
|
void PlayMusicStream(char *fileName); // Start music playing (open stream)
|
||||||
|
void UpdateMusicStream(void); // Updates buffers for music streaming
|
||||||
|
void StopMusicStream(void); // Stop music playing (close stream)
|
||||||
|
void PauseMusicStream(void); // Pause music playing
|
||||||
|
void ResumeMusicStream(void); // Resume playing paused music
|
||||||
|
bool MusicIsPlaying(void); // Check if music is playing
|
||||||
|
void SetMusicVolume(float volume); // Set volume for music (1.0 is max level)
|
||||||
|
float GetMusicTimeLength(void); // Get current music time length (in seconds)
|
||||||
|
float GetMusicTimePlayed(void); // Get current music time played (in seconds)
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // AUDIO_H
|
Loading…
Add table
Add a link
Reference in a new issue