aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoshua Reisenauer <kd7tck@msn.com>2016-04-29 23:43:21 -0700
committerJoshua Reisenauer <kd7tck@msn.com>2016-04-29 23:43:21 -0700
commit5f1e8b827822ded6d24d71f75e1f1d0d301dbb2d (patch)
tree65c27e48d5c79cf2919c7521e6e720fc4baaf8f8 /src
parent91f1f324c0ee3bd57ed778b39fd54d97330dba32 (diff)
downloadraylib-5f1e8b827822ded6d24d71f75e1f1d0d301dbb2d.tar.gz
raylib-5f1e8b827822ded6d24d71f75e1f1d0d301dbb2d.zip
hide struct from user
Hiding the struct from user should protect from accidentally modifying the mix channel. This could cause serious errors down the road.
Diffstat (limited to 'src')
-rw-r--r--src/audio.c37
-rw-r--r--src/audio.h12
-rw-r--r--src/raylib.h12
3 files changed, 35 insertions, 26 deletions
diff --git a/src/audio.c b/src/audio.c
index ededf4ae..2c0ed3de 100644
--- a/src/audio.c
+++ b/src/audio.c
@@ -90,6 +90,16 @@ typedef struct Music {
bool chipTune; // True if chiptune is loaded
} Music;
+// Audio Context, used to create custom audio streams that are not bound to a sound file. There can be
+// no more than 4 concurrent audio contexts in use. This is due to each active context being tied to
+// a dedicated mix channel.
+typedef struct AudioContext_t {
+ unsigned short sampleRate; // default is 48000
+ unsigned char bitsPerSample; // 16 is default
+ mix_t mixChannel; // 0-3 or mixA-mixD, each mix channel can receive up to one dedicated audio stream
+ channel_t channels; // 1=mono, 2=stereo
+} AudioContext_t;
+
#if defined(AUDIO_STANDALONE)
typedef enum { INFO = 0, ERROR, WARNING, DEBUG, OTHER } TraceLogType;
#endif
@@ -97,10 +107,10 @@ typedef enum { INFO = 0, ERROR, WARNING, DEBUG, OTHER } TraceLogType;
//----------------------------------------------------------------------------------
// Global Variables Definition
//----------------------------------------------------------------------------------
-static bool mixChannelsActive_g[4]; // What mix channels are currently active
+static AudioContext_t* mixChannelsActive_g[4]; // What mix channels are currently active
static bool musicEnabled = false;
-static Music currentMusic; // Current music loaded
- // NOTE: Only one music file playing at a time
+static Music currentMusic; // Current music loaded
+ // NOTE: Only one music file playing at a time
//----------------------------------------------------------------------------------
// Module specific Functions Declaration
@@ -184,32 +194,39 @@ bool AudioDeviceReady(void)
// Audio contexts are for outputing custom audio waveforms, This will shut down any other sound sources currently playing
// The mix_t is what mix channel you want to operate on, mixA->mixD are the ones available. Each mix channel can only be used one at a time.
// exmple usage is InitAudioContext(48000, 16, mixA, stereo);
-AudioContext* InitAudioContext(unsigned short sampleRate, unsigned char bitsPerSample, mix_t mixChannel, channel_t channels)
+AudioContext InitAudioContext(unsigned short sampleRate, unsigned char bitsPerSample, mix_t mixChannel, channel_t channels)
{
if(!AudioDeviceReady()) InitAudioDevice();
else StopMusicStream();
if(!mixChannelsActive_g[mixChannel]){
- AudioContext *ac = malloc(sizeof(AudioContext));
+ AudioContext_t *ac = malloc(sizeof(AudioContext_t));
ac->sampleRate = sampleRate;
ac->bitsPerSample = bitsPerSample;
ac->mixChannel = mixChannel;
ac->channels = channels;
- mixChannelsActive_g[mixChannel] = true;
+ mixChannelsActive_g[mixChannel] = ac;
return ac;
}
return NULL;
}
// Frees buffer in audio context
-void CloseAudioContext(AudioContext *ctx)
+void CloseAudioContext(AudioContext ctx)
{
- if(ctx){
- mixChannelsActive_g[ctx->mixChannel] = false;
- free(ctx);
+ AudioContext_t *context = (AudioContext_t*)ctx;
+ if(context){
+ mixChannelsActive_g[context->mixChannel] = NULL;
+ free(context);
}
}
+// Pushes more audio data into context mix channel, if none are ever pushed then zeros are fed in
+void UpdateAudioContext(AudioContext ctx, void *data, unsigned short *dataLength)
+{
+ ;
+}
+
//----------------------------------------------------------------------------------
diff --git a/src/audio.h b/src/audio.h
index 401edc3e..cadf2bc1 100644
--- a/src/audio.h
+++ b/src/audio.h
@@ -66,12 +66,7 @@ typedef struct Wave {
// Audio Context, used to create custom audio streams that are not bound to a sound file. There can be
// no more than 4 concurrent audio contexts in use. This is due to each active context being tied to
// a dedicated mix channel.
-typedef struct AudioContext {
- unsigned short sampleRate; // default is 48000
- unsigned char bitsPerSample; // 16 is default
- mix_t mixChannel; // 0-3 or mixA-mixD, each mix channel can receive up to one dedicated audio stream
- channel_t channels; // 1=mono, 2=stereo
-} AudioContext;
+typedef void* AudioContext;
#ifdef __cplusplus
extern "C" { // Prevents name mangling of functions
@@ -92,8 +87,9 @@ bool AudioDeviceReady(void); // True if call
// Audio contexts are for outputing custom audio waveforms, This will shut down any other sound sources currently playing
// The mix_t is what mix channel you want to operate on, mixA->mixD are the ones available. Each mix channel can only be used one at a time.
// exmple usage is InitAudioContext(48000, 16, mixA, stereo);
-AudioContext* InitAudioContext(unsigned short sampleRate, unsigned char bitsPerSample, mix_t mixChannel, channel_t channels);
-void CloseAudioContext(AudioContext *ctx); // Frees audio context
+AudioContext InitAudioContext(unsigned short sampleRate, unsigned char bitsPerSample, mix_t mixChannel, channel_t channels);
+void CloseAudioContext(AudioContext ctx); // Frees audio context
+void UpdateAudioContext(AudioContext ctx, void *data, unsigned short *dataLength); // Pushes more audio data into context mix channel, if none are ever pushed then zeros are fed in
Sound LoadSound(char *fileName); // Load sound to memory
Sound LoadSoundFromWave(Wave wave); // Load sound to memory from wave data
diff --git a/src/raylib.h b/src/raylib.h
index 1721c009..5b7b34fd 100644
--- a/src/raylib.h
+++ b/src/raylib.h
@@ -451,12 +451,7 @@ typedef struct Wave {
// Audio Context, used to create custom audio streams that are not bound to a sound file. There can be
// no more than 4 concurrent audio contexts in use. This is due to each active context being tied to
// a dedicated mix channel.
-typedef struct AudioContext {
- unsigned short sampleRate; // default is 48000
- unsigned char bitsPerSample; // 16 is default
- mix_t mixChannel; // 0-3 or mixA-mixD, each mix channel can receive up to one dedicated audio stream
- channel_t channels; // 1=mono, 2=stereo
-} AudioContext;
+typedef void* AudioContext;
// Texture formats
// NOTE: Support depends on OpenGL version and platform
@@ -880,8 +875,9 @@ bool AudioDeviceReady(void); // True if call
// Audio contexts are for outputing custom audio waveforms, This will shut down any other sound sources currently playing
// The mix_t is what mix channel you want to operate on, mixA->mixD are the ones available. Each mix channel can only be used one at a time.
// exmple usage is InitAudioContext(48000, 16, mixA, stereo);
-AudioContext* InitAudioContext(unsigned short sampleRate, unsigned char bitsPerSample, mix_t mixChannel, channel_t channels);
-void CloseAudioContext(AudioContext *ctx); // Frees audio context
+AudioContext InitAudioContext(unsigned short sampleRate, unsigned char bitsPerSample, mix_t mixChannel, channel_t channels);
+void CloseAudioContext(AudioContext ctx); // Frees audio context
+void UpdateAudioContext(AudioContext ctx, void *data, unsigned short *dataLength); // Pushes more audio data into context mix channel, if none are ever pushed then zeros are fed in
Sound LoadSound(char *fileName); // Load sound to memory
Sound LoadSoundFromWave(Wave wave); // Load sound to memory from wave data