Browse Source

Some code tweaks

Audio module requires a complete formatting review....
pull/424/head
Ray 7 years ago
parent
commit
b63ffcfa0f
3 changed files with 43 additions and 45 deletions
  1. +17
    -14
      src/audio.c
  2. +16
    -9
      src/audio.h
  3. +10
    -22
      src/raylib.h

+ 17
- 14
src/audio.c View File

@ -153,7 +153,12 @@
// 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)
typedef struct MusicData {
@ -179,7 +184,13 @@ typedef struct MusicData {
} MusicData;
#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
//----------------------------------------------------------------------------------
@ -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 struct AudioBuffer AudioBuffer;
struct AudioBuffer
{
// Audio buffer structure
typedef struct AudioBuffer {
mal_dsp dsp; // For format conversion.
float volume;
float pitch;
@ -231,10 +241,9 @@ struct AudioBuffer
AudioBuffer* next;
AudioBuffer* prev;
unsigned char buffer[1];
};
void StopAudioBuffer(AudioBuffer* audioBuffer);
} AudioBuffer;
void StopAudioBuffer(AudioBuffer *audioBuffer);
static mal_context context;
static mal_device device;
@ -400,12 +409,6 @@ void InitAudioDevice(void)
// 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);
// 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);
if (result != MAL_SUCCESS)
{

+ 16
- 9
src/audio.h View File

@ -81,9 +81,11 @@ typedef struct Wave {
// Sound source type
typedef struct Sound {
unsigned int source; // OpenAL audio source id
unsigned int buffer; // OpenAL audio buffer id
int format; // OpenAL audio format specifier
void *audioBuffer; // Pointer to internal data used by the audio system
unsigned int source; // Audio source id
unsigned int buffer; // Audio buffer id
int format; // Audio format specifier
} Sound;
// 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 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)
void *audioBuffer; // Pointer to internal data used by the audio system.
int format; // Audio format specifier
unsigned int source; // Audio source id
unsigned int buffers[2]; // Audio buffers (double buffering)
} AudioStream;
#ifdef __cplusplus
@ -147,12 +151,12 @@ void ResumeMusicStream(Music music); // Resume playin
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 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 GetMusicTimePlayed(Music music); // Get current music time played (in seconds)
// Raw audio stream functions
AudioStream InitAudioStream(unsigned int sampleRate,
// AudioStream management functions
AudioStream InitAudioStream(unsigned int sampleRate,
unsigned int sampleSize,
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
@ -161,7 +165,10 @@ bool IsAudioBufferProcessed(AudioStream stream); // Check if any
void PlayAudioStream(AudioStream stream); // Play audio stream
void PauseAudioStream(AudioStream stream); // Pause 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 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
}

+ 10
- 22
src/raylib.h View File

@ -470,11 +470,11 @@ typedef struct Wave {
// Sound source type
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 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;
// 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 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
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;
// Head-Mounted-Display device parameters
@ -656,18 +656,6 @@ typedef enum {
HMD_SONY_PSVR
} 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
extern "C" { // Prevents name mangling of functions
#endif
@ -1131,8 +1119,8 @@ RLAPI void PauseAudioStream(AudioStream stream); // Pause a
RLAPI void ResumeAudioStream(AudioStream stream); // Resume audio stream
RLAPI bool IsAudioStreamPlaying(AudioStream stream); // Check if audio stream is playing
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 SetAudioStreamPitch(AudioStream stream, float pitch); // Set pitch for audio stream (1.0 is base 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)
#ifdef __cplusplus
}

Loading…
Cancel
Save