forked from JailDoctor/JailAudio
- [NEW] JA_SetMusicVolume(int volume)
- [NEW] JA_EnableMusic(const bool value) - [NEW] JA_SetSoundVolume(int volume) - [NEW] JA_EnableSound(const bool value)
This commit is contained in:
@@ -10,6 +10,10 @@ struct JA_Music_t {};
|
||||
int JA_freq {48000};
|
||||
SDL_AudioFormat JA_format {AUDIO_S16};
|
||||
Uint8 JA_channels {2};
|
||||
int JA_musicVolume = 128;
|
||||
int JA_soundVolume = 64;
|
||||
bool JA_musicEnabled = true;
|
||||
bool JA_soundEnabled = true;
|
||||
|
||||
void JA_Init(const int freq, const SDL_AudioFormat format, const int channels) {
|
||||
JA_freq = freq;
|
||||
@@ -26,23 +30,35 @@ JA_Music_t *JA_LoadMusic(const char* filename) {
|
||||
return (JA_Music_t*)Mix_LoadMUS(filename);
|
||||
}
|
||||
|
||||
void JA_PlayMusic(JA_Music_t *music, const int loop) {
|
||||
void JA_PlayMusic(JA_Music_t *music, const int loop)
|
||||
{
|
||||
if (!JA_musicEnabled) return;
|
||||
Mix_PlayMusic((Mix_Music*)music, loop);
|
||||
Mix_VolumeMusic(JA_musicVolume);
|
||||
}
|
||||
|
||||
void JA_PauseMusic() {
|
||||
void JA_PauseMusic()
|
||||
{
|
||||
if (!JA_musicEnabled) return;
|
||||
Mix_PauseMusic();
|
||||
}
|
||||
|
||||
void JA_ResumeMusic() {
|
||||
void JA_ResumeMusic()
|
||||
{
|
||||
if (!JA_musicEnabled) return;
|
||||
Mix_ResumeMusic();
|
||||
}
|
||||
|
||||
void JA_StopMusic() {
|
||||
void JA_StopMusic()
|
||||
{
|
||||
if (!JA_musicEnabled) return;
|
||||
Mix_HaltMusic();
|
||||
}
|
||||
|
||||
JA_Music_state JA_GetMusicState() {
|
||||
JA_Music_state JA_GetMusicState()
|
||||
{
|
||||
if (!JA_musicEnabled) return JA_MUSIC_DISABLED;
|
||||
|
||||
if (Mix_PausedMusic()) {
|
||||
return JA_MUSIC_PAUSED;
|
||||
} else if (Mix_PlayingMusic()) {
|
||||
@@ -52,11 +68,30 @@ JA_Music_state JA_GetMusicState() {
|
||||
}
|
||||
}
|
||||
|
||||
void JA_DeleteMusic(JA_Music_t *music) {
|
||||
void JA_DeleteMusic(JA_Music_t *music)
|
||||
{
|
||||
Mix_FreeMusic((Mix_Music*)music);
|
||||
}
|
||||
|
||||
JA_Sound_t *JA_NewSound(Uint8* buffer, Uint32 length) {
|
||||
int JA_SetMusicVolume(int volume)
|
||||
{
|
||||
JA_musicVolume = volume;
|
||||
Mix_VolumeMusic(JA_musicVolume);
|
||||
return JA_musicVolume;
|
||||
}
|
||||
|
||||
void JA_EnableMusic(const bool value)
|
||||
{
|
||||
if (Mix_PlayingMusic()) Mix_HaltMusic();
|
||||
JA_musicEnabled = value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
JA_Sound_t *JA_NewSound(Uint8* buffer, Uint32 length)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -66,26 +101,39 @@ JA_Sound_t *JA_LoadSound(const char* filename) {
|
||||
}
|
||||
|
||||
int JA_PlaySound(JA_Sound_t *sound, const int loop) {
|
||||
return Mix_PlayChannel(-1, (Mix_Chunk*)sound, loop);
|
||||
if (!JA_soundEnabled) return -1;
|
||||
const int channel = Mix_PlayChannel(-1, (Mix_Chunk*)sound, loop);
|
||||
Mix_Volume(-1, JA_soundVolume);
|
||||
return channel;
|
||||
}
|
||||
|
||||
void JA_DeleteSound(JA_Sound_t *sound) {
|
||||
void JA_DeleteSound(JA_Sound_t *sound)
|
||||
{
|
||||
Mix_FreeChunk((Mix_Chunk*)sound);
|
||||
}
|
||||
|
||||
void JA_PauseChannel(const int channel) {
|
||||
void JA_PauseChannel(const int channel)
|
||||
{
|
||||
if (!JA_soundEnabled) return;
|
||||
Mix_Pause(channel);
|
||||
}
|
||||
|
||||
void JA_ResumeChannel(const int channel) {
|
||||
void JA_ResumeChannel(const int channel)
|
||||
{
|
||||
if (!JA_soundEnabled) return;
|
||||
Mix_Resume(channel);
|
||||
}
|
||||
|
||||
void JA_StopChannel(const int channel) {
|
||||
void JA_StopChannel(const int channel)
|
||||
{
|
||||
if (!JA_soundEnabled) return;
|
||||
Mix_HaltChannel(channel);
|
||||
}
|
||||
|
||||
JA_Channel_state JA_GetChannelState(const int channel) {
|
||||
JA_Channel_state JA_GetChannelState(const int channel)
|
||||
{
|
||||
if (!JA_soundEnabled) return JA_SOUND_DISABLED;
|
||||
|
||||
if (Mix_Paused(channel)) {
|
||||
return JA_CHANNEL_PAUSED;
|
||||
} else if (Mix_Playing(channel)) {
|
||||
@@ -95,7 +143,24 @@ JA_Channel_state JA_GetChannelState(const int channel) {
|
||||
}
|
||||
}
|
||||
|
||||
int JA_SetVolume(int volume) {
|
||||
return Mix_Volume(-1, volume);
|
||||
int JA_SetSoundVolume(int volume)
|
||||
{
|
||||
JA_musicVolume = volume;
|
||||
Mix_Volume(-1, JA_musicVolume);
|
||||
return JA_musicVolume;
|
||||
}
|
||||
|
||||
void JA_EnableSound(const bool value)
|
||||
{
|
||||
Mix_HaltChannel(-1);
|
||||
JA_soundEnabled = value;
|
||||
}
|
||||
|
||||
|
||||
int JA_SetVolume(int volume)
|
||||
{
|
||||
JA_SetSoundVolume(volume);
|
||||
return JA_SetMusicVolume(volume);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user