Some code tweaks
Audio module requires a complete formatting review....
This commit is contained in:
parent
5290390494
commit
b63ffcfa0f
3 changed files with 43 additions and 45 deletions
31
src/audio.c
31
src/audio.c
|
@ -153,7 +153,12 @@
|
||||||
// Types and Structures Definition
|
// Types and Structures Definition
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
typedef enum { MUSIC_AUDIO_OGG = 0, MUSIC_AUDIO_FLAC, MUSIC_MODULE_XM, MUSIC_MODULE_MOD } MusicContextType;
|
typedef enum {
|
||||||
|
MUSIC_AUDIO_OGG = 0,
|
||||||
|
MUSIC_AUDIO_FLAC,
|
||||||
|
MUSIC_MODULE_XM,
|
||||||
|
MUSIC_MODULE_MOD
|
||||||
|
} MusicContextType;
|
||||||
|
|
||||||
// Music type (file streaming from memory)
|
// Music type (file streaming from memory)
|
||||||
typedef struct MusicData {
|
typedef struct MusicData {
|
||||||
|
@ -179,7 +184,13 @@ typedef struct MusicData {
|
||||||
} MusicData;
|
} MusicData;
|
||||||
|
|
||||||
#if defined(AUDIO_STANDALONE)
|
#if defined(AUDIO_STANDALONE)
|
||||||
typedef enum { LOG_INFO = 0, LOG_ERROR, LOG_WARNING, LOG_DEBUG, LOG_OTHER } TraceLogType;
|
typedef enum {
|
||||||
|
LOG_INFO = 0,
|
||||||
|
LOG_ERROR,
|
||||||
|
LOG_WARNING,
|
||||||
|
LOG_DEBUG,
|
||||||
|
LOG_OTHER
|
||||||
|
} TraceLogType;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
@ -215,9 +226,8 @@ void TraceLog(int msgType, const char *text, ...); // Show trace lo
|
||||||
|
|
||||||
typedef enum { AUDIO_BUFFER_USAGE_STATIC = 0, AUDIO_BUFFER_USAGE_STREAM } AudioBufferUsage;
|
typedef enum { AUDIO_BUFFER_USAGE_STATIC = 0, AUDIO_BUFFER_USAGE_STREAM } AudioBufferUsage;
|
||||||
|
|
||||||
typedef struct AudioBuffer AudioBuffer;
|
// Audio buffer structure
|
||||||
struct AudioBuffer
|
typedef struct AudioBuffer {
|
||||||
{
|
|
||||||
mal_dsp dsp; // For format conversion.
|
mal_dsp dsp; // For format conversion.
|
||||||
float volume;
|
float volume;
|
||||||
float pitch;
|
float pitch;
|
||||||
|
@ -231,10 +241,9 @@ struct AudioBuffer
|
||||||
AudioBuffer* next;
|
AudioBuffer* next;
|
||||||
AudioBuffer* prev;
|
AudioBuffer* prev;
|
||||||
unsigned char buffer[1];
|
unsigned char buffer[1];
|
||||||
};
|
} AudioBuffer;
|
||||||
|
|
||||||
void StopAudioBuffer(AudioBuffer* audioBuffer);
|
|
||||||
|
|
||||||
|
void StopAudioBuffer(AudioBuffer *audioBuffer);
|
||||||
|
|
||||||
static mal_context context;
|
static mal_context context;
|
||||||
static mal_device device;
|
static mal_device device;
|
||||||
|
@ -400,12 +409,6 @@ void InitAudioDevice(void)
|
||||||
// Device. Using the default device. Format is floating point because it simplifies mixing.
|
// Device. Using the default device. Format is floating point because it simplifies mixing.
|
||||||
mal_device_config deviceConfig = mal_device_config_init(DEVICE_FORMAT, DEVICE_CHANNELS, DEVICE_SAMPLE_RATE, NULL, OnSendAudioDataToDevice);
|
mal_device_config deviceConfig = mal_device_config_init(DEVICE_FORMAT, DEVICE_CHANNELS, DEVICE_SAMPLE_RATE, NULL, OnSendAudioDataToDevice);
|
||||||
|
|
||||||
// Special case for PLATFORM_RPI.
|
|
||||||
//#if defined(PLATFORM_RPI)
|
|
||||||
// deviceConfig.alsa.noMMap = MAL_TRUE;
|
|
||||||
// deviceConfig.bufferSizeInFrames = 2048;
|
|
||||||
//#endif
|
|
||||||
|
|
||||||
result = mal_device_init(&context, mal_device_type_playback, NULL, &deviceConfig, NULL, &device);
|
result = mal_device_init(&context, mal_device_type_playback, NULL, &deviceConfig, NULL, &device);
|
||||||
if (result != MAL_SUCCESS)
|
if (result != MAL_SUCCESS)
|
||||||
{
|
{
|
||||||
|
|
25
src/audio.h
25
src/audio.h
|
@ -81,9 +81,11 @@ typedef struct Wave {
|
||||||
|
|
||||||
// Sound source type
|
// Sound source type
|
||||||
typedef struct Sound {
|
typedef struct Sound {
|
||||||
unsigned int source; // OpenAL audio source id
|
void *audioBuffer; // Pointer to internal data used by the audio system
|
||||||
unsigned int buffer; // OpenAL audio buffer id
|
|
||||||
int format; // OpenAL audio format specifier
|
unsigned int source; // Audio source id
|
||||||
|
unsigned int buffer; // Audio buffer id
|
||||||
|
int format; // Audio format specifier
|
||||||
} Sound;
|
} Sound;
|
||||||
|
|
||||||
// Music type (file streaming from memory)
|
// Music type (file streaming from memory)
|
||||||
|
@ -97,9 +99,11 @@ typedef struct AudioStream {
|
||||||
unsigned int sampleSize; // Bit depth (bits per sample): 8, 16, 32 (24 not supported)
|
unsigned int sampleSize; // Bit depth (bits per sample): 8, 16, 32 (24 not supported)
|
||||||
unsigned int channels; // Number of channels (1-mono, 2-stereo)
|
unsigned int channels; // Number of channels (1-mono, 2-stereo)
|
||||||
|
|
||||||
int format; // OpenAL audio format specifier
|
void *audioBuffer; // Pointer to internal data used by the audio system.
|
||||||
unsigned int source; // OpenAL audio source id
|
|
||||||
unsigned int buffers[2]; // OpenAL audio buffers (double buffering)
|
int format; // Audio format specifier
|
||||||
|
unsigned int source; // Audio source id
|
||||||
|
unsigned int buffers[2]; // Audio buffers (double buffering)
|
||||||
} AudioStream;
|
} AudioStream;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -147,12 +151,12 @@ void ResumeMusicStream(Music music); // Resume playin
|
||||||
bool IsMusicPlaying(Music music); // Check if music is playing
|
bool IsMusicPlaying(Music music); // Check if music is playing
|
||||||
void SetMusicVolume(Music music, float volume); // Set volume for music (1.0 is max level)
|
void SetMusicVolume(Music music, float volume); // Set volume for music (1.0 is max level)
|
||||||
void SetMusicPitch(Music music, float pitch); // Set pitch for a music (1.0 is base level)
|
void SetMusicPitch(Music music, float pitch); // Set pitch for a music (1.0 is base level)
|
||||||
void SetMusicLoopCount(Music music, float count); // Set music loop count (loop repeats)
|
void SetMusicLoopCount(Music music, int count); // Set music loop count (loop repeats)
|
||||||
float GetMusicTimeLength(Music music); // Get music time length (in seconds)
|
float GetMusicTimeLength(Music music); // Get music time length (in seconds)
|
||||||
float GetMusicTimePlayed(Music music); // Get current music time played (in seconds)
|
float GetMusicTimePlayed(Music music); // Get current music time played (in seconds)
|
||||||
|
|
||||||
// Raw audio stream functions
|
// AudioStream management functions
|
||||||
AudioStream InitAudioStream(unsigned int sampleRate,
|
AudioStream InitAudioStream(unsigned int sampleRate,
|
||||||
unsigned int sampleSize,
|
unsigned int sampleSize,
|
||||||
unsigned int channels); // Init audio stream (to stream raw audio pcm data)
|
unsigned int channels); // Init audio stream (to stream raw audio pcm data)
|
||||||
void UpdateAudioStream(AudioStream stream, const void *data, int samplesCount); // Update audio stream buffers with data
|
void UpdateAudioStream(AudioStream stream, const void *data, int samplesCount); // Update audio stream buffers with data
|
||||||
|
@ -161,7 +165,10 @@ bool IsAudioBufferProcessed(AudioStream stream); // Check if any
|
||||||
void PlayAudioStream(AudioStream stream); // Play audio stream
|
void PlayAudioStream(AudioStream stream); // Play audio stream
|
||||||
void PauseAudioStream(AudioStream stream); // Pause audio stream
|
void PauseAudioStream(AudioStream stream); // Pause audio stream
|
||||||
void ResumeAudioStream(AudioStream stream); // Resume audio stream
|
void ResumeAudioStream(AudioStream stream); // Resume audio stream
|
||||||
|
bool IsAudioStreamPlaying(AudioStream stream); // Check if audio stream is playing
|
||||||
void StopAudioStream(AudioStream stream); // Stop audio stream
|
void StopAudioStream(AudioStream stream); // Stop audio stream
|
||||||
|
void SetAudioStreamVolume(AudioStream stream, float volume); // Set volume for audio stream (1.0 is max level)
|
||||||
|
void SetAudioStreamPitch(AudioStream stream, float pitch); // Set pitch for audio stream (1.0 is base level)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
32
src/raylib.h
32
src/raylib.h
|
@ -470,11 +470,11 @@ typedef struct Wave {
|
||||||
|
|
||||||
// Sound source type
|
// Sound source type
|
||||||
typedef struct Sound {
|
typedef struct Sound {
|
||||||
void* audioBuffer; // A pointer to internal data used by the audio system.
|
void *audioBuffer; // Pointer to internal data used by the audio system
|
||||||
|
|
||||||
unsigned int source; // OpenAL audio source id
|
unsigned int source; // Audio source id
|
||||||
unsigned int buffer; // OpenAL audio buffer id
|
unsigned int buffer; // Audio buffer id
|
||||||
int format; // OpenAL audio format specifier
|
int format; // Audio format specifier
|
||||||
} Sound;
|
} Sound;
|
||||||
|
|
||||||
// Music type (file streaming from memory)
|
// Music type (file streaming from memory)
|
||||||
|
@ -488,11 +488,11 @@ typedef struct AudioStream {
|
||||||
unsigned int sampleSize; // Bit depth (bits per sample): 8, 16, 32 (24 not supported)
|
unsigned int sampleSize; // Bit depth (bits per sample): 8, 16, 32 (24 not supported)
|
||||||
unsigned int channels; // Number of channels (1-mono, 2-stereo)
|
unsigned int channels; // Number of channels (1-mono, 2-stereo)
|
||||||
|
|
||||||
void* audioBuffer; // A pointer to internal data used by the audio system.
|
void *audioBuffer; // Pointer to internal data used by the audio system.
|
||||||
|
|
||||||
int format; // OpenAL audio format specifier
|
int format; // Audio format specifier
|
||||||
unsigned int source; // OpenAL audio source id
|
unsigned int source; // Audio source id
|
||||||
unsigned int buffers[2]; // OpenAL audio buffers (double buffering)
|
unsigned int buffers[2]; // Audio buffers (double buffering)
|
||||||
} AudioStream;
|
} AudioStream;
|
||||||
|
|
||||||
// Head-Mounted-Display device parameters
|
// Head-Mounted-Display device parameters
|
||||||
|
@ -656,18 +656,6 @@ typedef enum {
|
||||||
HMD_SONY_PSVR
|
HMD_SONY_PSVR
|
||||||
} VrDeviceType;
|
} VrDeviceType;
|
||||||
|
|
||||||
// RRESData type
|
|
||||||
typedef enum {
|
|
||||||
RRES_TYPE_RAW = 0,
|
|
||||||
RRES_TYPE_IMAGE,
|
|
||||||
RRES_TYPE_WAVE,
|
|
||||||
RRES_TYPE_VERTEX,
|
|
||||||
RRES_TYPE_TEXT,
|
|
||||||
RRES_TYPE_FONT_IMAGE,
|
|
||||||
RRES_TYPE_FONT_CHARDATA, // CharInfo data array
|
|
||||||
RRES_TYPE_DIRECTORY
|
|
||||||
} RRESDataType;
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" { // Prevents name mangling of functions
|
extern "C" { // Prevents name mangling of functions
|
||||||
#endif
|
#endif
|
||||||
|
@ -1131,8 +1119,8 @@ RLAPI void PauseAudioStream(AudioStream stream); // Pause a
|
||||||
RLAPI void ResumeAudioStream(AudioStream stream); // Resume audio stream
|
RLAPI void ResumeAudioStream(AudioStream stream); // Resume audio stream
|
||||||
RLAPI bool IsAudioStreamPlaying(AudioStream stream); // Check if audio stream is playing
|
RLAPI bool IsAudioStreamPlaying(AudioStream stream); // Check if audio stream is playing
|
||||||
RLAPI void StopAudioStream(AudioStream stream); // Stop audio stream
|
RLAPI void StopAudioStream(AudioStream stream); // Stop audio stream
|
||||||
RLAPI void SetAudioStreamVolume(AudioStream stream, float volume); // Set volume for audio stream (1.0 is max level)
|
RLAPI void SetAudioStreamVolume(AudioStream stream, float volume); // Set volume for audio stream (1.0 is max level)
|
||||||
RLAPI void SetAudioStreamPitch(AudioStream stream, float pitch); // Set pitch for audio stream (1.0 is base level)
|
RLAPI void SetAudioStreamPitch(AudioStream stream, float pitch); // Set pitch for audio stream (1.0 is base level)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue