Browse Source

Added audio function: SetMasterVolume()

pull/223/head
Ray 8 years ago
parent
commit
ac6b4d3830
2 changed files with 23 additions and 11 deletions
  1. +22
    -11
      src/audio.c
  2. +1
    -0
      src/raylib.h

+ 22
- 11
src/audio.c View File

@ -177,9 +177,11 @@ void InitAudioDevice(void)
TraceLog(INFO, "Audio device and context initialized successfully: %s", alcGetString(device, ALC_DEVICE_SPECIFIER));
// Listener definition (just for 2D)
alListener3f(AL_POSITION, 0, 0, 0);
alListener3f(AL_VELOCITY, 0, 0, 0);
alListener3f(AL_ORIENTATION, 0, 0, -1);
alListener3f(AL_POSITION, 0.0f, 0.0f, 0.0f);
alListener3f(AL_VELOCITY, 0.0f, 0.0f, 0.0f);
alListener3f(AL_ORIENTATION, 0.0f, 0.0f, -1.0f);
alListenerf(AL_GAIN, 1.0f);
}
}
}
@ -216,6 +218,15 @@ bool IsAudioDeviceReady(void)
}
}
// Set master volume (listener)
void SetMasterVolume(float volume)
{
if (volume < 0.0f) volume = 0.0f;
else if (volume > 1.0f) volume = 1.0f;
alListenerf(AL_GAIN, volume);
}
//----------------------------------------------------------------------------------
// Module Functions Definition - Sounds loading and playing (.WAV)
//----------------------------------------------------------------------------------
@ -313,10 +324,10 @@ Sound LoadSoundFromWave(Wave wave)
ALuint source;
alGenSources(1, &source); // Generate pointer to audio source
alSourcef(source, AL_PITCH, i">1);
alSourcef(source, AL_GAIN, i">1);
alSource3f(source, AL_POSITION, i">0, 0, 0);
alSource3f(source, AL_VELOCITY, i">0, 0, 0);
alSourcef(source, AL_PITCH, f">1.0f);
alSourcef(source, AL_GAIN, f">1.0f);
alSource3f(source, AL_POSITION, f">0.0f, 0.0f, 0.0f);
alSource3f(source, AL_VELOCITY, f">0.0f, 0.0f, 0.0f);
alSourcei(source, AL_LOOPING, AL_FALSE);
// Convert loaded data to OpenAL buffer
@ -899,10 +910,10 @@ AudioStream InitAudioStream(unsigned int sampleRate, unsigned int sampleSize, un
// Create an audio source
alGenSources(1, &stream.source);
alSourcef(stream.source, AL_PITCH, i">1);
alSourcef(stream.source, AL_GAIN, i">1);
alSource3f(stream.source, AL_POSITION, i">0, 0, 0);
alSource3f(stream.source, AL_VELOCITY, i">0, 0, 0);
alSourcef(stream.source, AL_PITCH, f">1.0f);
alSourcef(stream.source, AL_GAIN, f">1.0f);
alSource3f(stream.source, AL_POSITION, f">0.0f, 0.0f, 0.0f);
alSource3f(stream.source, AL_VELOCITY, f">0.0f, 0.0f, 0.0f);
// Create Buffers (double buffering)
alGenBuffers(MAX_STREAM_BUFFERS, stream.buffers);

+ 1
- 0
src/raylib.h View File

@ -947,6 +947,7 @@ RLAPI void ToggleVrMode(void); // Enable/Disable VR experienc
RLAPI void InitAudioDevice(void); // Initialize audio device and context
RLAPI void CloseAudioDevice(void); // Close the audio device and context
RLAPI bool IsAudioDeviceReady(void); // Check if audio device has been initialized successfully
RLAPI void SetMasterVolume(float volume); // Set master volume (listener)
RLAPI Wave LoadWave(const char *fileName); // Load wave data from file
RLAPI Wave LoadWaveEx(void *data, int sampleCount, int sampleRate, int sampleSize, int channels); // Load wave data from raw array data

Loading…
Cancel
Save