mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2025-01-03 15:39:46 +01:00
Add notes for FAudio implementation
This commit is contained in:
parent
5202b80a3d
commit
adcabb9483
1 changed files with 18 additions and 0 deletions
|
@ -25,6 +25,7 @@ class MusicTrack
|
||||||
public:
|
public:
|
||||||
MusicTrack(SDL_RWops *rw)
|
MusicTrack(SDL_RWops *rw)
|
||||||
{
|
{
|
||||||
|
/* Open an stb_vorbis handle */
|
||||||
m_music = Mix_LoadMUS_RW(rw, 1);
|
m_music = Mix_LoadMUS_RW(rw, 1);
|
||||||
if (m_music == NULL)
|
if (m_music == NULL)
|
||||||
{
|
{
|
||||||
|
@ -34,11 +35,13 @@ public:
|
||||||
|
|
||||||
void Dispose()
|
void Dispose()
|
||||||
{
|
{
|
||||||
|
/* Free stb_vorbis */
|
||||||
Mix_FreeMusic(m_music);
|
Mix_FreeMusic(m_music);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Play(bool loop)
|
bool Play(bool loop)
|
||||||
{
|
{
|
||||||
|
/* Create/Validate static FAudioSourceVoice, begin streaming */
|
||||||
if (Mix_PlayMusic(m_music, loop ? -1 : 0) == -1)
|
if (Mix_PlayMusic(m_music, loop ? -1 : 0) == -1)
|
||||||
{
|
{
|
||||||
vlog_error("Mix_PlayMusic: %s", Mix_GetError());
|
vlog_error("Mix_PlayMusic: %s", Mix_GetError());
|
||||||
|
@ -49,26 +52,31 @@ public:
|
||||||
|
|
||||||
static void Halt()
|
static void Halt()
|
||||||
{
|
{
|
||||||
|
/* FAudioVoice_Destroy */
|
||||||
Mix_HaltMusic();
|
Mix_HaltMusic();
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool IsHalted()
|
static bool IsHalted()
|
||||||
{
|
{
|
||||||
|
/* return musicVoice == NULL; */
|
||||||
return Mix_PausedMusic() == 1;
|
return Mix_PausedMusic() == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Pause()
|
static void Pause()
|
||||||
{
|
{
|
||||||
|
/* FAudioSourceVoice_Pause */
|
||||||
Mix_PauseMusic();
|
Mix_PauseMusic();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Resume()
|
static void Resume()
|
||||||
{
|
{
|
||||||
|
/* FAudioSourceVoice_Resume */
|
||||||
Mix_ResumeMusic();
|
Mix_ResumeMusic();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SetVolume(int musicVolume)
|
static void SetVolume(int musicVolume)
|
||||||
{
|
{
|
||||||
|
/* FAudioSourceVoice_SetVolume */
|
||||||
Mix_VolumeMusic(musicVolume);
|
Mix_VolumeMusic(musicVolume);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,6 +89,7 @@ class SoundTrack
|
||||||
public:
|
public:
|
||||||
SoundTrack(const char* fileName)
|
SoundTrack(const char* fileName)
|
||||||
{
|
{
|
||||||
|
/* Parse WAV header, fill in FAudioBuffer, read PCM to malloc buffer */
|
||||||
unsigned char *mem;
|
unsigned char *mem;
|
||||||
size_t length;
|
size_t length;
|
||||||
FILESYSTEM_loadAssetToMemory(fileName, &mem, &length, false);
|
FILESYSTEM_loadAssetToMemory(fileName, &mem, &length, false);
|
||||||
|
@ -103,11 +112,13 @@ public:
|
||||||
|
|
||||||
void Dispose()
|
void Dispose()
|
||||||
{
|
{
|
||||||
|
/* Destroy all source voices, free buffer used by FAudioBuffer */
|
||||||
Mix_FreeChunk(m_sound);
|
Mix_FreeChunk(m_sound);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Play()
|
void Play()
|
||||||
{
|
{
|
||||||
|
/* Fire-and-forget from a per-track FAudioSourceVoice pool */
|
||||||
if (Mix_PlayChannel(-1, m_sound, 0) == -1)
|
if (Mix_PlayChannel(-1, m_sound, 0) == -1)
|
||||||
{
|
{
|
||||||
vlog_error("Unable to play WAV file: %s", Mix_GetError());
|
vlog_error("Unable to play WAV file: %s", Mix_GetError());
|
||||||
|
@ -119,6 +130,7 @@ public:
|
||||||
const Uint16 audio_format = AUDIO_S16SYS;
|
const Uint16 audio_format = AUDIO_S16SYS;
|
||||||
const int audio_buffers = 1024;
|
const int audio_buffers = 1024;
|
||||||
|
|
||||||
|
/* FAudioCreate, FAudio_CreateMasteringVoice */
|
||||||
if (Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers) != 0)
|
if (Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers) != 0)
|
||||||
{
|
{
|
||||||
vlog_error("Unable to initialize audio: %s", Mix_GetError());
|
vlog_error("Unable to initialize audio: %s", Mix_GetError());
|
||||||
|
@ -128,16 +140,22 @@ public:
|
||||||
|
|
||||||
static void Pause()
|
static void Pause()
|
||||||
{
|
{
|
||||||
|
/* FAudio_StopEngine */
|
||||||
Mix_Pause(-1);
|
Mix_Pause(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Resume()
|
static void Resume()
|
||||||
{
|
{
|
||||||
|
/* FAudio_StartEngine */
|
||||||
Mix_Resume(-1);
|
Mix_Resume(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SetVolume(int soundVolume)
|
static void SetVolume(int soundVolume)
|
||||||
{
|
{
|
||||||
|
/* FAudioVoice_SetVolume on all sounds. Yeah, all of them :/
|
||||||
|
* If we get desperate we can use a submix and set volume on that, but
|
||||||
|
* the submix is an extra mix stage so just loop all sounds manually...
|
||||||
|
*/
|
||||||
Mix_Volume(-1, soundVolume);
|
Mix_Volume(-1, soundVolume);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue