NGN_SOUND.H

METHODS of the class: Sound Effects (SFX)


Method

NGN_AudioClip* PlaySfx(
    NGN_AudioClipData* sound,                   // Audio clip
    int32_t volume = 100,                       // Volume
    int32_t panning = 0,                        // Panning (-100 to 100)
    bool loop = false,                          // Loop?
    uint8_t mixer_channel = MIXER_EFFECTS_CH    // Default channel in the mixer
);

Description

Plays a previously loaded audio clip in RAM using the ngn->load->AudioClip() command. Returns the reference of the created instance and adds it to the playback queue.

Example

NGN_AudioClipData* coin_sfx = ngn->load->AudioClip("data/wav/coin.wav");
// Simple playback
ngn->sound->PlaySfx(coin_sfx);
// Advanced playback
NGN_AudioClip* my_sound = ngn->sound->PlaySfx(coin_sfx, 100, false);
ngn->sound->SfxVolume(my_sound, 50);

Method

void ResumeSfx(NGN_AudioClip* sound);

Description

Resumes the playback of a sound effect.

Example

ngn->sound->ResumeSfx(my_sound);

Method

void PauseSfx(NGN_AudioClip* sound);

Description

Pauses a sound effect.

Example

ngn->sound->PauseSfx(my_sound);

Method

void StopSfx(NGN_AudioClip* sound);

Description

Stops the playback of a sound effect. This will automatically remove it from the playback queue.

Example

ngn->sound->StopSfx(my_sound);

Method

void SfxVolume(NGN_AudioClip* sound, int32_t volume = 100);

Description

Changes the volume level of a sound (0 – 100).

Example

ngn->sound->SfxVolume(my_sound, 50);

Method

int32_t SfxGetVolume(NGN_AudioClip* sound);

Description

Returns the current volume level of a sound.

Example

uint32_t vol = ngn->sound->SfxGetVolume(my_sound);

Method

void SfxPitch(NGN_AudioClip* sound, float pitch = 1.0f);

Description

Changes the playback speed and frequency of a sound. (Use 1.0f as the nominal value).

Example

ngn->sound->SfxPitch(my_sound, 1.2f);

Method

float SfxGetPitch(NGN_AudioClip* sound);

Description

Returns the current PITCH value of a sound.

Example

float my_pitch = ngn->sound->SfxGetPitch(my_sound);

Method

void SfxLoop(NGN_AudioClip* sound, bool loop = true);

Description

Sets whether a sound should loop upon completion.

Example

ngn->sound->SfxLoop(my_sound, true);

Method

bool SfxGetLoop(NGN_AudioClip* sound);

Description

Returns the loop state of a sound.

Example

bool repeat = ngn->sound->SfxGetLoop(my_sound);

Method

void SfxPanning(NGN_AudioClip* sound, int32_t panning = 0);

Description

Sets the panning effect of a sound (-100 left, 0 center, 100 right).

Example

ngn->sound->SfxPanning(my_sound, -66);

Method

int32_t SfxGetPanning(NGN_AudioClip* sound);

Description

Returns the panning level of a sound.

Example

int32_t pan = ngn->sound->SfxGetPanning(my_sound);

Method

bool SfxIsPlaying(NGN_AudioClip* sound);

Description

Returns the playback state of a sound.

Example

bool play = ngn->sound->SfxIsPlaying(my_sound);

Method

bool SfxIsAlive(NGN_AudioClip* sound);

Description

Returns whether a sound still exists.

Example

bool alive = ngn->sound->SfxIsAlive(my_sound);

Method

void ClearSfx();

Description

Stops and removes all sound effects stored in the queue.

Example

ngn->sound->ClearSfx();

Methods of the class: Music and Dialogues (BGM)


Method

NGN_MusicClip* OpenMusic(
    std::string filepath,                       // Audio file
    bool auto_start = true,                     // Auto-start playback
    int32_t volume = 100,                       // Volume
    bool loop = true,                           // Loop?
    uint8_t mixer_channel = MIXER_MUSIC_CH      // Default channel in the mixer
);

NGN_MusicClip* OpenMusic(
    std::string filepath,                       // Audio file
    int32_t loop_start,                         // Loop start (milliseconds)
    int32_t loop_end = NGN_DEFAULT_VALUE,       // Loop end (milliseconds)
    bool auto_start = true,                     // Auto-start playback
    int32_t volume = 100,                       // Volume
    uint8_t mixer_channel = MIXER_MUSIC_CH      // Default channel in the mixer
);

Description

Opens and optionally plays a streaming audio file in WAV, OGG, or FLAC format. It's possible to set the loop start and end points (in milliseconds) if needed. Returns the reference of the created instance and adds it to the playback queue. Optionally, you can assign the audio mixer channel.

Example

NGN_MusicClip* bgm = ngn->sound->OpenMusic("data/ogg/stage01.ogg");
NGN_MusicClip* bgm_loop = ngn->sound->OpenMusic("data/ogg/stage01.ogg", 13721);

Method

void CloseMusic(NGN_MusicClip* music);

Description

Closes an audio stream and removes it from the playback queue.

Example

ngn->sound->CloseMusic(bgm);

Method

void PlayMusic(
    NGN_MusicClip* music,       // Music clip
    int32_t volume = 100,       // Volume
    bool loop = true            // Loop?
);

Description

Starts or restarts the playback of a previously opened audio file, allowing you to specify new volume and loop values.

Example

ngn->sound->PlayMusic(bgm, 50, false);

Method

void ResumeMusic(NGN_MusicClip* music);

Description

Resumes playback of a previously paused music. If it wasn't paused, playback starts from the beginning.

Example

ngn->sound->ResumeMusic(bgm);

Method

void PauseMusic(NGN_MusicClip* music);

Description

Pauses the specified music.

Example

ngn->sound->PauseMusic(bgm);

Method

void StopMusic(NGN_MusicClip* music);

Description

Stops playback of the specified music. It will not be removed from the playback queue.

Example

ngn->sound->StopMusic(bgm);

Method

void MusicVolume(NGN_MusicClip* music, int32_t volume = 100);

Description

Changes the volume level (0 – 100) of the specified music.

Example

ngn->sound->MusicVolume(bgm, 75);

Method

int32_t MusicGetVolume(NGN_MusicClip* music);

Description

Returns the current volume level of the specified music.

Example

uint32_t vol = ngn->sound->MusicGetVolume(bgm);

Method

void MusicPitch(NGN_MusicClip* music, float pitch = 1.0f);

Description

Changes the playback speed and frequency of the specified music. (Use 1.0f as the nominal value).

Example

ngn->sound->MusicPitch(bgm, 0.75f);

Method

float MusicGetPitch(NGN_MusicClip* music);

Description

Returns the current PITCH value of the specified music.

Example

float pitch = ngn->sound->MusicGetPitch(bgm);

Method

void MusicLoop(NGN_MusicClip* music, bool loop = true);

Description

Changes the LOOP (looping) state of the specified music.

Example

ngn->sound->MusicLoop(bgm, false);

Method

bool MusicGetLoop(NGN_MusicClip* music);

Description

Returns the LOOP state of the specified music.

Example

bool loop = ngn->sound->MusicGetLoop(bgm);

Method

bool MusicIsPlaying(NGN_MusicClip* music);

Description

Returns the playback state of the specified music.

Example

bool play = ngn->sound->MusicIsPlaying(bgm);

Method

bool MusicIsAlive(NGN_MusicClip* music);

Description

Returns whether the specified music still exists.

Example

bool alive = ngn->sound->MusicIsAlive(bgm);

Method

void ClearMusic();

Description

Stops and removes all music streams stored in the queue.

Example

ngn->sound->ClearMusic();

Methods of the class: Mixer


Method

void SetMixerLevel(uint8_t channel, int32_t level);

Description

Changes the volume level of one of the sound mixer channels. Available channels are MIXER_MASTER_CH (master channel), MIXER_MUSIC_CH (music), MIXER_EFFECTS_CH (sound effects), MIXER_AUX1_CH (auxiliary channel 1), and MIXER_AUX2_CH (auxiliary channel 2). The volume value is an integer between 0 and 100.

Example

ngn->sound->SetMixerLevel(MIXER_MASTER_CH, 75);

Method

int32_t GetMixerLevel(uint8_t channel);

Description

Returns the current volume level of the specified channel in the sound mixer. The returned value is an integer between 0 and 100. In case of specifying a nonexistent channel, it will return 0.

Example

int32_t vol = ngn->sound->GetMixerLevel(MIXER_MASTER_CH);

Method

PushMixer();
PopMixer();

Description

Saves the current mixer values (PushMixer()) or restores the saved ones (PopMixer()).

Example

ngn->sound->PushMixer();
ngn->sound->PopMixer();

Methods of the class: Common methods


Method

void PauseAll();

Description

Pauses all currently playing sound effects (SFX) and music. Sounds and music played after executing this command will not be affected.

Example

ngn->sound->PauseAll();

Method

void ResumeAll();

Description

Resumes playback of all sound effects (SFX) and music that were paused by the PauseAll() command.

Example

ngn->sound->ResumeAll();

Method

void StopAll();

Description

Stops playback of all active sound effects (SFX) and closes all opened music streams.

Example

ngn->sound->StopAll();

Method

void Update();

Description

Updates the state of all existing sound effects (SFX) and music in the audio queue, automatically removing those that are no longer needed. This command should be executed once per frame to keep the sound queue updated.

Example

ngn->sound->Update();
Back to Index Versión en Español Back to Top