Complete review and update

Simplified module for Music and AudioStream
Added support for raw audio streaming (with example)
This commit is contained in:
raysan5
2016-08-02 17:32:24 +02:00
parent 58d2f70b7e
commit 68d647c1af
10 changed files with 283 additions and 127 deletions

View File

@ -76,9 +76,21 @@ typedef struct Wave {
} Wave;
// Music type (file streaming from memory)
// NOTE: Anything longer than ~10 seconds should be streamed into a mix channel...
// NOTE: Anything longer than ~10 seconds should be streamed
typedef struct Music *Music;
// Audio stream type
// NOTE: Useful to create custom audio streams not bound to a specific file
typedef struct AudioStream {
unsigned int sampleRate; // Frequency (samples per second)
unsigned int sampleSize; // Bit depth (bits per sample): 8, 16, 32 (24 not supported)
unsigned int channels; // Number of channels (1-mono, 2-stereo)
int format; // OpenAL audio format specifier
unsigned int source; // OpenAL audio source id
unsigned int buffers[2]; // OpenAL audio buffers (double buffering)
} AudioStream;
#ifdef __cplusplus
extern "C" { // Prevents name mangling of functions
#endif
@ -93,7 +105,7 @@ extern "C" { // Prevents name mangling of functions
//----------------------------------------------------------------------------------
void InitAudioDevice(void); // Initialize audio device and context
void CloseAudioDevice(void); // Close the audio device and context (and music stream)
bool IsAudioDeviceReady(void); // Check if device has been initialized successfully
bool IsAudioDeviceReady(void); // Check if audio device has been initialized successfully
Sound LoadSound(char *fileName); // Load sound to memory
Sound LoadSoundFromWave(Wave wave); // Load sound to memory from wave data
@ -120,6 +132,17 @@ void SetMusicPitch(Music music, float pitch); // Set pitch for
float GetMusicTimeLength(Music music); // Get music time length (in seconds)
float GetMusicTimePlayed(Music music); // Get current music time played (in seconds)
AudioStream InitAudioStream(unsigned int sampleRate,
unsigned int sampleSize,
unsigned int channels); // Init audio stream (to stream audio pcm data)
void UpdateAudioStream(AudioStream stream, void *data, int numSamples); // Update audio stream buffers with data
void CloseAudioStream(AudioStream stream); // Close audio stream and free memory
bool IsAudioBufferProcessed(AudioStream stream); // Check if any audio stream buffers requires refill
void PlayAudioStream(AudioStream stream); // Play audio stream
void PauseAudioStream(AudioStream stream); // Pause audio stream
void ResumeAudioStream(AudioStream stream); // Resume audio stream
void StopAudioStream(AudioStream stream); // Stop audio stream
#ifdef __cplusplus
}
#endif