Skip to content

Commit

Permalink
rename items based on feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffM2501 committed Aug 2, 2023
1 parent d25c662 commit 6a6373b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
20 changes: 12 additions & 8 deletions src/raudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,6 @@ Sound LoadSoundFromWave(Wave wave)
sound.stream.sampleSize = 32;
sound.stream.channels = AUDIO_DEVICE_CHANNELS;
sound.stream.buffer = audioBuffer;
sound.noFree = false;
}

return sound;
Expand All @@ -921,25 +920,24 @@ Sound LoadSoundFromWave(Wave wave)
// Clone sound from existing sound data, clone does not own wave data
// Wave data must
// NOTE: Wave data must be unallocated manually and will be shared across all clones
Sound CloneSound(Sound sourceSound)
Sound LoadSoundAlias(Sound source)
{
Sound sound = { 0 };

if (sourceSound.stream.buffer->data != NULL)
if (source.stream.buffer->data != NULL)
{
AudioBuffer* audioBuffer = LoadAudioBuffer(AUDIO_DEVICE_FORMAT, AUDIO_DEVICE_CHANNELS, AUDIO.System.device.sampleRate, sourceSound.frameCount, AUDIO_BUFFER_USAGE_STATIC);
AudioBuffer* audioBuffer = LoadAudioBuffer(AUDIO_DEVICE_FORMAT, AUDIO_DEVICE_CHANNELS, AUDIO.System.device.sampleRate, source.frameCount, AUDIO_BUFFER_USAGE_STATIC);
if (audioBuffer == NULL)
{
TRACELOG(LOG_WARNING, "SOUND: Failed to create buffer");
return sound; // early return to avoid dereferencing the audioBuffer null pointer
}
audioBuffer->data = sourceSound.stream.buffer->data;
sound.frameCount = sourceSound.frameCount;
audioBuffer->data = source.stream.buffer->data;
sound.frameCount = source.frameCount;
sound.stream.sampleRate = AUDIO.System.device.sampleRate;
sound.stream.sampleSize = 32;
sound.stream.channels = AUDIO_DEVICE_CHANNELS;
sound.stream.buffer = audioBuffer;
sound.noFree = true;
}

return sound;
Expand All @@ -965,7 +963,13 @@ void UnloadWave(Wave wave)
// Unload sound
void UnloadSound(Sound sound)
{
UnloadAudioBuffer(sound.stream.buffer, !sound.noFree);
UnloadAudioBuffer(sound.stream.buffer, true);
//TRACELOG(LOG_INFO, "SOUND: Unloaded sound data from RAM");
}

void UnloadSoundAlias(Sound alias)
{
UnloadAudioBuffer(alias.stream.buffer, false);
//TRACELOG(LOG_INFO, "SOUND: Unloaded sound data from RAM");
}

Expand Down
4 changes: 2 additions & 2 deletions src/raylib.h
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,6 @@ typedef struct AudioStream {
typedef struct Sound {
AudioStream stream; // Audio stream
unsigned int frameCount; // Total number of frames (considering channels)
bool noFree; // The sound data buffer is owned by something else, don't free it
} Sound;

// Music, audio stream, anything longer than ~10 seconds should be streamed
Expand Down Expand Up @@ -1532,11 +1531,12 @@ RLAPI Wave LoadWaveFromMemory(const char *fileType, const unsigned char *fileDat
RLAPI bool IsWaveReady(Wave wave); // Checks if wave data is ready
RLAPI Sound LoadSound(const char *fileName); // Load sound from file
RLAPI Sound LoadSoundFromWave(Wave wave); // Load sound from wave data
RLAPI Sound CloneSound(Sound sourceSound); // Create a new sound that shares the same sample data as the source sound, does not own the sound data
RLAPI Sound LoadSoundAlias(Sound source); // Create a new sound that shares the same sample data as the source sound, does not own the sound data
RLAPI bool IsSoundReady(Sound sound); // Checks if a sound is ready
RLAPI void UpdateSound(Sound sound, const void *data, int sampleCount); // Update sound buffer with new data
RLAPI void UnloadWave(Wave wave); // Unload wave data
RLAPI void UnloadSound(Sound sound); // Unload sound
RLAPI void UnloadSoundAlias(Sound alias); // Unload a sound alias (does not deallocate sample data)
RLAPI bool ExportWave(Wave wave, const char *fileName); // Export wave data to file, returns true on success
RLAPI bool ExportWaveAsCode(Wave wave, const char *fileName); // Export wave sample data to code (.h), returns true on success

Expand Down

0 comments on commit 6a6373b

Please sign in to comment.