From 91f1f324c0ee3bd57ed778b39fd54d97330dba32 Mon Sep 17 00:00:00 2001 From: Joshua Reisenauer Date: Fri, 29 Apr 2016 23:00:12 -0700 Subject: First stage of audio API update Look over changes and give feedback please. --- src/raylib.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/raylib.h') diff --git a/src/raylib.h b/src/raylib.h index 699fbbdb..1721c009 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -265,6 +265,8 @@ typedef enum { false, true } bool; #endif #endif +typedef enum { silence, mono, stereo } channel_t; +typedef enum { mixA, mixB, mixC, mixD } mix_t; // Used for mixing/muxing up to four diferent audio streams // byte type typedef unsigned char byte; @@ -446,6 +448,16 @@ typedef struct Wave { short channels; } 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; + // Texture formats // NOTE: Support depends on OpenGL version and platform typedef enum { @@ -863,6 +875,13 @@ void DrawPhysicObjectInfo(PhysicObject *pObj, Vector2 position, int fontSize); //------------------------------------------------------------------------------------ void InitAudioDevice(void); // Initialize audio device and context void CloseAudioDevice(void); // Close the audio device and context (and music stream) +bool AudioDeviceReady(void); // True if call to InitAudioDevice() was successful and CloseAudioDevice() has not been called yet + +// 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 Sound LoadSound(char *fileName); // Load sound to memory Sound LoadSoundFromWave(Wave wave); // Load sound to memory from wave data -- cgit v1.2.3 From 5f1e8b827822ded6d24d71f75e1f1d0d301dbb2d Mon Sep 17 00:00:00 2001 From: Joshua Reisenauer Date: Fri, 29 Apr 2016 23:43:21 -0700 Subject: 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. --- src/raylib.h | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'src/raylib.h') 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 -- cgit v1.2.3 From a1038f61b60ad21c936af783facc91fe01607be3 Mon Sep 17 00:00:00 2001 From: Joshua Reisenauer Date: Sat, 30 Apr 2016 15:41:46 -0700 Subject: BPS type added to ensure consistency --- src/raylib.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/raylib.h') diff --git a/src/raylib.h b/src/raylib.h index 5b7b34fd..83f58a51 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -265,8 +265,9 @@ typedef enum { false, true } bool; #endif #endif -typedef enum { silence, mono, stereo } channel_t; -typedef enum { mixA, mixB, mixC, mixD } mix_t; // Used for mixing/muxing up to four diferent audio streams +typedef enum { silence, mono, stereo } channel_t; // number of audio sources per sample +typedef enum { mixA, mixB, mixC, mixD } mix_t; // Used for mixing/muxing up to four diferent audio samples +typedef enum { eightBPS, sixteenBPS } BPS; // Either 8 or 16 bit quality samples // byte type typedef unsigned char byte; @@ -875,7 +876,7 @@ 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); +AudioContext InitAudioContext(unsigned short sampleRate, BPS 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 -- cgit v1.2.3 From 34e5fcf47e99deecc9954fd848130c61119e2e93 Mon Sep 17 00:00:00 2001 From: Joshua Reisenauer Date: Sat, 30 Apr 2016 16:05:43 -0700 Subject: removed enums --- src/raylib.h | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'src/raylib.h') diff --git a/src/raylib.h b/src/raylib.h index 83f58a51..8390d176 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -265,9 +265,6 @@ typedef enum { false, true } bool; #endif #endif -typedef enum { silence, mono, stereo } channel_t; // number of audio sources per sample -typedef enum { mixA, mixB, mixC, mixD } mix_t; // Used for mixing/muxing up to four diferent audio samples -typedef enum { eightBPS, sixteenBPS } BPS; // Either 8 or 16 bit quality samples // byte type typedef unsigned char byte; @@ -871,13 +868,13 @@ void DrawPhysicObjectInfo(PhysicObject *pObj, Vector2 position, int fontSize); //------------------------------------------------------------------------------------ void InitAudioDevice(void); // Initialize audio device and context void CloseAudioDevice(void); // Close the audio device and context (and music stream) -bool AudioDeviceReady(void); // True if call to InitAudioDevice() was successful and CloseAudioDevice() has not been called yet +bool IsAudioDeviceReady(void); // True if call to InitAudioDevice() was successful and CloseAudioDevice() has not been called yet // 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, BPS bitsPerSample, mix_t mixChannel, channel_t channels); -void CloseAudioContext(AudioContext ctx); // Frees audio context +// The mixChannel is what mix channel you want to operate on, 0-3 are the ones available. Each mix channel can only be used one at a time. +// exmple usage is InitAudioContext(48000, 16, 0, 2); // stereo, mixchannel 1, 16bit, 48khz +AudioContext InitAudioContext(unsigned short sampleRate, unsigned char bitsPerSample, unsigned char mixChannel, unsigned char 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 -- cgit v1.2.3