Skip to content

Commit 7568a18

Browse files
committed
Make panim automatically support wide range of audio formats
1 parent 85e0d37 commit 7568a18

1 file changed

Lines changed: 20 additions & 10 deletions

File tree

panim/panim.c

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,21 +98,31 @@ void ffmpeg_play_sound(Sound _sound, Wave wave)
9898
{
9999
(void)_sound;
100100

101-
if (
102-
wave.sampleRate != FFMPEG_SOUND_SAMPLE_RATE ||
103-
wave.sampleSize != FFMPEG_SOUND_SAMPLE_SIZE_BITS ||
104-
wave.channels != FFMPEG_SOUND_CHANNELS
105-
) {
101+
if (!(wave.sampleRate == 48000 || wave.sampleRate == 44100)) {
106102
TraceLog(LOG_ERROR,
107-
"Animation tried to play sound with rate: %dhz, sample size: %d bits, channels: %d. "
108-
"But we only support rate: %dhz, sample size: %d bits, channels: %d for now",
109-
wave.sampleRate, wave.sampleSize, wave.channels,
110-
FFMPEG_SOUND_SAMPLE_RATE, FFMPEG_SOUND_SAMPLE_SIZE_BITS, FFMPEG_SOUND_CHANNELS);
103+
"Animation tried to play a sound with a weird sample rate %dhz. "
104+
"Traditionally sample rates are either 48000hz or 44100hz.",
105+
wave.sampleRate);
111106
return;
112107
}
113108

114-
ffmpeg_wave = wave;
109+
if (!(wave.sampleSize == 8 || wave.sampleSize == 16 || wave.sampleSize == 32)) {
110+
TraceLog(LOG_ERROR,
111+
"Animation tried to play a sound with a weird sample size of %d bits. "
112+
"We support only 8, 16, or 32 bits for now.",
113+
wave.sampleSize);
114+
return;
115+
}
116+
117+
UnloadWave(ffmpeg_wave);
118+
ffmpeg_wave = WaveCopy(wave);
115119
ffmpeg_wave_cursor = 0;
120+
121+
if (
122+
ffmpeg_wave.sampleRate != FFMPEG_SOUND_SAMPLE_RATE ||
123+
ffmpeg_wave.sampleSize != FFMPEG_SOUND_SAMPLE_SIZE_BITS ||
124+
ffmpeg_wave.channels != FFMPEG_SOUND_CHANNELS
125+
) WaveFormat(&ffmpeg_wave, FFMPEG_SOUND_SAMPLE_RATE, FFMPEG_SOUND_SAMPLE_SIZE_BITS, FFMPEG_SOUND_CHANNELS);
116126
}
117127

118128
void preview_play_sound(Sound sound, Wave _wave)

0 commit comments

Comments
 (0)