Skip to content

Add LoadSoundFromPhysFS() #57

Description

@RobLoach

Summary

The README advertises loading "sounds" from archives, but there is no LoadSoundFromPhysFS(). Callers (including our own example examples/audio/audio_sound_loading.c, lines 31–35) must manually do:

Wave wav = LoadWaveFromPhysFS("res/sound.wav");
Sound fx = LoadSoundFromWave(wav);
UnloadWave(wav);

Every other common raylib file loader has a ...FromPhysFS counterpart (LoadImageFromPhysFS, LoadTextureFromPhysFS, LoadWaveFromPhysFS, LoadMusicStreamFromPhysFS, LoadFontFromPhysFS, LoadShaderFromPhysFS). LoadSound() is the missing obvious one.

Proposed API

RAYLIB_PHYSFS_DEF Sound LoadSoundFromPhysFS(const char* fileName);  // Load a sound from PhysFS

Suggested Implementation

In raylib-physfs.h, next to LoadWaveFromPhysFS():

Sound LoadSoundFromPhysFS(const char* fileName) {
    Wave wave = LoadWaveFromPhysFS(fileName);
    if (wave.data == NULL) {
        Sound output = { 0 };
        return output;
    }
    Sound sound = LoadSoundFromWave(wave);
    UnloadWave(wave);
    return sound;
}
  • Add the declaration to the header block and the README API list.
  • Simplify examples/audio/audio_sound_loading.c to use it.

QA

  • New test in test/raylib-physfs-test.c — note LoadSoundFromWave() needs the audio device only for playback in some raylib versions; if headless CI can't validate the Sound, at minimum assert the missing-file path returns a zeroed Sound (AssertEqual(sound.stream.buffer, 0)), mirroring the existing LoadWaveFromPhysFS missing-file test at test/raylib-physfs-test.c:162.
  • Example still builds and plays both WAV and OGG.

Context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions