mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2024-11-10 07:12:07 +00:00
sound: cleanup ogg to wav code
This commit is contained in:
parent
fbde7b753f
commit
d554b89730
2 changed files with 14 additions and 19 deletions
|
@ -728,7 +728,7 @@ OGG_LoadAsWav(char *filename, wavinfo_t *info, void **buffer)
|
|||
|
||||
/* load vorbis file from memory */
|
||||
ogg_file = stb_vorbis_open_memory(temp_buffer, size, &res, NULL);
|
||||
if (!res)
|
||||
if (!res && ogg_file->channels > 0)
|
||||
{
|
||||
int read_samples = 0;
|
||||
|
||||
|
@ -737,22 +737,24 @@ OGG_LoadAsWav(char *filename, wavinfo_t *info, void **buffer)
|
|||
info->width = 2;
|
||||
info->channels = ogg_file->channels;
|
||||
info->loopstart = -1;
|
||||
info->samples = stb_vorbis_stream_length_in_samples(ogg_file);
|
||||
/* return length * channels */
|
||||
info->samples = stb_vorbis_stream_length_in_samples(ogg_file) / ogg_file->channels;
|
||||
info->dataofs = 0;
|
||||
|
||||
/* alloc memory for uncompressed wav */
|
||||
final_buffer = Z_Malloc(info->samples * sizeof(short));
|
||||
final_buffer = Z_Malloc(info->samples * sizeof(short) * ogg_file->channels);
|
||||
|
||||
/* load sampleas to buffer */
|
||||
read_samples = stb_vorbis_get_samples_short_interleaved(ogg_file, info->channels, final_buffer,
|
||||
info->samples);
|
||||
read_samples = stb_vorbis_get_samples_short_interleaved(
|
||||
ogg_file, info->channels, final_buffer,
|
||||
info->samples * ogg_file->channels);
|
||||
|
||||
if (read_samples > 0)
|
||||
{
|
||||
/* fix sample list size*/
|
||||
if (read_samples * info->channels < info->samples)
|
||||
if (read_samples < info->samples)
|
||||
{
|
||||
info->samples = read_samples * info->channels;
|
||||
info->samples = read_samples;
|
||||
}
|
||||
|
||||
/* copy to final result */
|
||||
|
|
|
@ -206,7 +206,7 @@ S_IsSilencedMuzzleFlash(const wavinfo_t* info, const void* raw_data, const char*
|
|||
}
|
||||
|
||||
static void
|
||||
S_LoadVorbis(char *path, char* name, wavinfo_t *info, void **buffer)
|
||||
S_LoadVorbis(const char *path, const char* name, wavinfo_t *info, void **buffer)
|
||||
{
|
||||
int len;
|
||||
char namewe[256];
|
||||
|
@ -227,27 +227,20 @@ S_LoadVorbis(char *path, char* name, wavinfo_t *info, void **buffer)
|
|||
|
||||
len = strlen(path);
|
||||
|
||||
/* Remove the extension */
|
||||
memset(namewe, 0, 256);
|
||||
memcpy(namewe, path, len - (strlen(ext) + 1));
|
||||
|
||||
if (len < 5)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (strcmp(ext, "wav"))
|
||||
{
|
||||
/* Non wav? */
|
||||
return;
|
||||
}
|
||||
/* Remove the extension */
|
||||
memset(namewe, 0, sizeof(namewe));
|
||||
memcpy(namewe, path, len - (strlen(ext) + 1));
|
||||
|
||||
/* Combine with ogg */
|
||||
Q_strlcpy(filename, namewe, sizeof(filename));
|
||||
|
||||
/* Add the extension */
|
||||
Q_strlcat(filename, ".", sizeof(filename));
|
||||
Q_strlcat(filename, "ogg", sizeof(filename));
|
||||
Q_strlcat(filename, ".ogg", sizeof(filename));
|
||||
|
||||
OGG_LoadAsWav(filename, info, buffer);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue