mirror of https://github.com/encounter/SDL.git
audio: Calculate a legitimate SDL_AudioSpec::silence in SDL_LoadWAV_RW().
This commit is contained in:
parent
55afc281fa
commit
dbe5c14b33
|
@ -1664,24 +1664,28 @@ SDL_NextAudioFormat(void)
|
||||||
return format_list[format_idx][format_idx_sub++];
|
return format_list[format_idx][format_idx_sub++];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Uint8
|
||||||
|
SDL_SilenceValueForFormat(const SDL_AudioFormat format)
|
||||||
|
{
|
||||||
|
switch (format) {
|
||||||
|
// !!! FIXME: 0x80 isn't perfect for U16, but we can't fit 0x8000 in a
|
||||||
|
// !!! FIXME: byte for memset() use. This is actually 0.1953 percent off
|
||||||
|
// from silence. Maybe just don't use U16.
|
||||||
|
case AUDIO_U16LSB:
|
||||||
|
case AUDIO_U16MSB:
|
||||||
|
case AUDIO_U8:
|
||||||
|
return 0x80;
|
||||||
|
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0x00;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SDL_CalculateAudioSpec(SDL_AudioSpec * spec)
|
SDL_CalculateAudioSpec(SDL_AudioSpec * spec)
|
||||||
{
|
{
|
||||||
switch (spec->format) {
|
spec->silence = SDL_SilenceValueForFormat(spec->format);
|
||||||
case AUDIO_U8:
|
|
||||||
|
|
||||||
// !!! FIXME: 0x80 isn't perfect for U16, but we can't fit 0x8000 in a
|
|
||||||
// !!! FIXME: byte for memset() use. This is actually 0.1953 percent off
|
|
||||||
// from silence. Maybe just don't use U16.
|
|
||||||
case AUDIO_U16LSB:
|
|
||||||
case AUDIO_U16MSB:
|
|
||||||
spec->silence = 0x80;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
spec->silence = 0x00;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
spec->size = SDL_AUDIO_BITSIZE(spec->format) / 8;
|
spec->size = SDL_AUDIO_BITSIZE(spec->format) / 8;
|
||||||
spec->size *= spec->channels;
|
spec->size *= spec->channels;
|
||||||
spec->size *= spec->samples;
|
spec->size *= spec->samples;
|
||||||
|
|
|
@ -52,6 +52,7 @@ extern SDL_AudioFormat SDL_FirstAudioFormat(SDL_AudioFormat format);
|
||||||
extern SDL_AudioFormat SDL_NextAudioFormat(void);
|
extern SDL_AudioFormat SDL_NextAudioFormat(void);
|
||||||
|
|
||||||
/* Function to calculate the size and silence for a SDL_AudioSpec */
|
/* Function to calculate the size and silence for a SDL_AudioSpec */
|
||||||
|
extern Uint8 SDL_SilenceValueForFormat(const SDL_AudioFormat format);
|
||||||
extern void SDL_CalculateAudioSpec(SDL_AudioSpec * spec);
|
extern void SDL_CalculateAudioSpec(SDL_AudioSpec * spec);
|
||||||
|
|
||||||
/* Choose the audio filter functions below */
|
/* Choose the audio filter functions below */
|
||||||
|
|
|
@ -2081,6 +2081,8 @@ WaveLoad(SDL_RWops *src, WaveFile *file, SDL_AudioSpec *spec, Uint8 **audio_buf,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
spec->silence = SDL_SilenceValueForFormat(spec->format);
|
||||||
|
|
||||||
/* Report the end position back to the cleanup code. */
|
/* Report the end position back to the cleanup code. */
|
||||||
if (RIFFlengthknown) {
|
if (RIFFlengthknown) {
|
||||||
chunk->position = RIFFend;
|
chunk->position = RIFFend;
|
||||||
|
|
Loading…
Reference in New Issue