forked from JailDoctor/JailAudio
- Prova amb update explicit
This commit is contained in:
@@ -46,7 +46,7 @@ float JA_soundVolume[JA_MAX_GROUPS];
|
|||||||
bool JA_musicEnabled { true };
|
bool JA_musicEnabled { true };
|
||||||
bool JA_soundEnabled { true };
|
bool JA_soundEnabled { true };
|
||||||
SDL_AudioDeviceID sdlAudioDevice { 0 };
|
SDL_AudioDeviceID sdlAudioDevice { 0 };
|
||||||
SDL_TimerID JA_timerID { 0 };
|
//SDL_TimerID JA_timerID { 0 };
|
||||||
|
|
||||||
bool fading = false;
|
bool fading = false;
|
||||||
int fade_start_time;
|
int fade_start_time;
|
||||||
@@ -54,7 +54,7 @@ int fade_duration;
|
|||||||
int fade_initial_volume;
|
int fade_initial_volume;
|
||||||
|
|
||||||
|
|
||||||
Uint32 JA_UpdateCallback(void *userdata, SDL_TimerID timerID, Uint32 interval)
|
void JA_Update()
|
||||||
{
|
{
|
||||||
if (JA_musicEnabled && current_music && current_music->state == JA_MUSIC_PLAYING)
|
if (JA_musicEnabled && current_music && current_music->state == JA_MUSIC_PLAYING)
|
||||||
{
|
{
|
||||||
@@ -63,7 +63,7 @@ Uint32 JA_UpdateCallback(void *userdata, SDL_TimerID timerID, Uint32 interval)
|
|||||||
if (time > (fade_start_time+fade_duration)) {
|
if (time > (fade_start_time+fade_duration)) {
|
||||||
fading = false;
|
fading = false;
|
||||||
JA_StopMusic();
|
JA_StopMusic();
|
||||||
return 30;
|
return;
|
||||||
} else {
|
} else {
|
||||||
const int time_passed = time - fade_start_time;
|
const int time_passed = time - fade_start_time;
|
||||||
const float percent = (float)time_passed / (float)fade_duration;
|
const float percent = (float)time_passed / (float)fade_duration;
|
||||||
@@ -104,7 +104,7 @@ Uint32 JA_UpdateCallback(void *userdata, SDL_TimerID timerID, Uint32 interval)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 30;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JA_Init(const int freq, const SDL_AudioFormat format, const int num_channels)
|
void JA_Init(const int freq, const SDL_AudioFormat format, const int num_channels)
|
||||||
@@ -121,12 +121,12 @@ void JA_Init(const int freq, const SDL_AudioFormat format, const int num_channel
|
|||||||
for (int i=0; i<JA_MAX_SIMULTANEOUS_CHANNELS; ++i) channels[i].state = JA_CHANNEL_FREE;
|
for (int i=0; i<JA_MAX_SIMULTANEOUS_CHANNELS; ++i) channels[i].state = JA_CHANNEL_FREE;
|
||||||
for (int i=0; i<JA_MAX_GROUPS; ++i) JA_soundVolume[i] = 0.5f;
|
for (int i=0; i<JA_MAX_GROUPS; ++i) JA_soundVolume[i] = 0.5f;
|
||||||
//SDL_PauseAudioDevice(sdlAudioDevice);
|
//SDL_PauseAudioDevice(sdlAudioDevice);
|
||||||
JA_timerID = SDL_AddTimer(30, JA_UpdateCallback, nullptr);
|
//JA_timerID = SDL_AddTimer(30, JA_UpdateCallback, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void JA_Quit()
|
void JA_Quit()
|
||||||
{
|
{
|
||||||
if (JA_timerID) SDL_RemoveTimer(JA_timerID);
|
//if (JA_timerID) SDL_RemoveTimer(JA_timerID);
|
||||||
|
|
||||||
if (!sdlAudioDevice) SDL_CloseAudioDevice(sdlAudioDevice);
|
if (!sdlAudioDevice) SDL_CloseAudioDevice(sdlAudioDevice);
|
||||||
sdlAudioDevice = 0;
|
sdlAudioDevice = 0;
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ enum JA_Music_state { JA_MUSIC_INVALID, JA_MUSIC_PLAYING, JA_MUSIC_PAUSED, JA_MU
|
|||||||
struct JA_Sound_t;
|
struct JA_Sound_t;
|
||||||
struct JA_Music_t;
|
struct JA_Music_t;
|
||||||
|
|
||||||
|
void JA_Update();
|
||||||
|
|
||||||
void JA_Init(const int freq, const SDL_AudioFormat format, const int num_channels);
|
void JA_Init(const int freq, const SDL_AudioFormat format, const int num_channels);
|
||||||
void JA_Quit();
|
void JA_Quit();
|
||||||
|
|
||||||
|
|||||||
5
main.cpp
5
main.cpp
@@ -31,10 +31,10 @@ int main(int argc, char **argv) {
|
|||||||
JA_PlaySound(peiv);
|
JA_PlaySound(peiv);
|
||||||
break;
|
break;
|
||||||
case SDL_SCANCODE_3: // Si pulsem la tecla '3' sona el wav 3 vegades
|
case SDL_SCANCODE_3: // Si pulsem la tecla '3' sona el wav 3 vegades
|
||||||
JA_PlaySound(peiv, 2);
|
JA_PlaySound(peiv, 2, 1);
|
||||||
break;
|
break;
|
||||||
case SDL_SCANCODE_4: // Si pulsem la tecla '4' sona el wav infinitament
|
case SDL_SCANCODE_4: // Si pulsem la tecla '4' sona el wav infinitament
|
||||||
channel = JA_PlaySound(peiv, -1);
|
channel = JA_PlaySound(peiv, -1, 2);
|
||||||
break;
|
break;
|
||||||
case SDL_SCANCODE_5: // Si pulsem la tecla '5' pausem o despausem el wav que sonaba infinitament
|
case SDL_SCANCODE_5: // Si pulsem la tecla '5' pausem o despausem el wav que sonaba infinitament
|
||||||
if (JA_GetChannelState(channel) == JA_CHANNEL_PLAYING) { JA_PauseChannel(channel); } else { JA_ResumeChannel(channel); }
|
if (JA_GetChannelState(channel) == JA_CHANNEL_PLAYING) { JA_PauseChannel(channel); } else { JA_ResumeChannel(channel); }
|
||||||
@@ -63,6 +63,7 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
JA_Update();
|
||||||
}
|
}
|
||||||
JA_DeleteSound(peiv);
|
JA_DeleteSound(peiv);
|
||||||
JA_DeleteMusic(music);
|
JA_DeleteMusic(music);
|
||||||
|
|||||||
Reference in New Issue
Block a user