Skip to content

Commit

Permalink
Convert music and sfx to Ogg Vorbis
Browse files Browse the repository at this point in the history
This reduces the amount of I/O necessary. This avoids stutters when
streaming music on devices with slow I/O. Thanks to Paul Cercueil
for coming up with and testing this idea.

I put the conversion in the Makefile, so we have the option to switch
to a different codec later, or use an improved encoder or change the
quality setting.

The encoder is instructed to resample the audio if necessary. Some of
the sfx weren't at 44100 kHz and I imagine oggenc can do a better job
at resampling than SDL_mixer, since it doesn't run realtime.

I picked -q2 as the quality setting. In general -q4 to -q6 is
recommended for transparency, but with this particular music
-q2 sounded fine to me. Besides, reducing the chance of stutters
probably contributes more to a good audio experience than more
accurate encoding.

Note that despite the name, Mix_LoadWAV() loads Ogg files just fine.
  • Loading branch information
mthuurne committed May 2, 2019
1 parent 96cb326 commit 172cbc4
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*.o
data/*.ogg
hocoslamfy
hocoslamfy-od
hocoslamfy-od.opk
Expand Down
13 changes: 11 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,24 @@ ifneq (, $(findstring MINGW, $(shell uname -s)))
CFLAGS+=-DDONT_USE_PWD
endif

WAVS := $(wildcard sound/*.wav)
OGGS := $(WAVS:sound/%.wav=data/%.ogg)

DATA_TO_CLEAN := $(OGGS)

.PHONY: all opk

all: $(TARGET)
all: $(TARGET) $(OGGS)

include Makefile.rules

$(OGGS): data/%.ogg: sound/%.wav
$(SUM) " OGG $@"
$(CMD)oggenc --resample 44100 -q2 $< -o $@

opk: $(TARGET).opk

$(TARGET).opk: $(TARGET)
$(TARGET).opk: $(TARGET) $(OGGS)
$(SUM) " OPK $@"
$(CMD)rm -rf .opk_data
$(CMD)cp -r data .opk_data
Expand Down
14 changes: 7 additions & 7 deletions audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,19 @@ bool InitializeAudio()

if (SND_Available)
{
BGM = Mix_LoadMUS(DATA_PATH "bgm.wav");
BGM = Mix_LoadMUS(DATA_PATH "bgm.ogg");
if (BGM == NULL)
{
printf("%s: Mix_LoadMUS failed: %s\n", DATA_PATH "bgm.wav", Mix_GetError());
printf("%s: Mix_LoadMUS failed: %s\n", DATA_PATH "bgm.ogg", Mix_GetError());
return false;
}
else
printf("Successfully loaded %s\n", DATA_PATH "bgm.wav");
printf("Successfully loaded %s\n", DATA_PATH "bgm.ogg");

SFX_Fly = LoadSFX(DATA_PATH "fly.wav");
SFX_Pass = LoadSFX(DATA_PATH "pass.wav");
SFX_Collision = LoadSFX(DATA_PATH "collision.wav");
SFX_HighScore = LoadSFX(DATA_PATH "highscore.wav");
SFX_Fly = LoadSFX(DATA_PATH "fly.ogg");
SFX_Pass = LoadSFX(DATA_PATH "pass.ogg");
SFX_Collision = LoadSFX(DATA_PATH "collision.ogg");
SFX_HighScore = LoadSFX(DATA_PATH "highscore.ogg");
}

return true;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 172cbc4

Please sign in to comment.