Some code tweaks
This commit is contained in:
parent
73774aadd6
commit
2d5c8e61b1
20
src/audio.c
20
src/audio.c
@ -570,7 +570,7 @@ void WaveFormat(Wave *wave, int sampleRate, int sampleSize, int channels)
|
||||
// NOTE: Only supported mono <--> stereo
|
||||
if (wave->channels != channels)
|
||||
{
|
||||
void *data = malloc(wave->sampleCount*channels*wave->sampleSize/8);
|
||||
void *data = malloc(wave->sampleCount*wave->sampleSize/8*channels);
|
||||
|
||||
if ((wave->channels == 1) && (channels == 2)) // mono ---> stereo (duplicate mono information)
|
||||
{
|
||||
@ -607,7 +607,7 @@ Wave WaveCopy(Wave wave)
|
||||
{
|
||||
Wave newWave = { 0 };
|
||||
|
||||
newWave.data = malloc(wave.sampleCount*wave.channels*wave.sampleSize/8);
|
||||
newWave.data = malloc(wave.sampleCount*wave.sampleSize/8*wave.channels);
|
||||
|
||||
if (newWave.data != NULL)
|
||||
{
|
||||
@ -632,7 +632,7 @@ void WaveCrop(Wave *wave, int initSample, int finalSample)
|
||||
{
|
||||
int sampleCount = finalSample - initSample;
|
||||
|
||||
void *data = malloc(sampleCount*wave->channels*wave->sampleSize/8);
|
||||
void *data = malloc(sampleCount*wave->sampleSize/8*wave->channels);
|
||||
|
||||
memcpy(data, (unsigned char*)wave->data + (initSample*wave->channels*wave->sampleSize/8), sampleCount*wave->channels*wave->sampleSize/8);
|
||||
|
||||
@ -849,7 +849,7 @@ void UpdateMusicStream(Music music)
|
||||
bool active = true;
|
||||
|
||||
// NOTE: Using dynamic allocation because it could require more than 16KB
|
||||
void *pcm = calloc(AUDIO_BUFFER_SIZE*music->stream.channels*music->stream.sampleSize/8, 1);
|
||||
void *pcm = calloc(AUDIO_BUFFER_SIZE*music->stream.sampleSize/8*music->stream.channels, 1);
|
||||
|
||||
int numBuffersToProcess = processed;
|
||||
int samplesCount = 0; // Total size of data steamed in L+R samples for xm floats,
|
||||
@ -1245,23 +1245,19 @@ static Wave LoadWAV(const char *fileName)
|
||||
// NOTE: Using stb_vorbis library
|
||||
static Wave LoadOGG(const char *fileName)
|
||||
{
|
||||
Wave wave;
|
||||
Wave wave = { 0 };
|
||||
|
||||
stb_vorbis *oggFile = stb_vorbis_open_filename(fileName, NULL, NULL);
|
||||
|
||||
if (oggFile == NULL)
|
||||
{
|
||||
TraceLog(WARNING, "[%s] OGG file could not be opened", fileName);
|
||||
wave.data = NULL;
|
||||
}
|
||||
if (oggFile == NULL) TraceLog(WARNING, "[%s] OGG file could not be opened", fileName);
|
||||
else
|
||||
{
|
||||
stb_vorbis_info info = stb_vorbis_get_info(oggFile);
|
||||
|
||||
|
||||
wave.sampleRate = info.sample_rate;
|
||||
wave.sampleSize = 16; // 16 bit per sample (short)
|
||||
wave.channels = info.channels;
|
||||
wave.sampleCount = (int)stb_vorbis_stream_length_in_samples(oggFile);
|
||||
wave.sampleCount = (int)stb_vorbis_stream_length_in_samples(oggFile); // Independent by channel
|
||||
|
||||
float totalSeconds = stb_vorbis_stream_length_in_seconds(oggFile);
|
||||
if (totalSeconds > 10) TraceLog(WARNING, "[%s] Ogg audio length is larger than 10 seconds (%f), that's a big file in memory, consider music streaming", fileName, totalSeconds);
|
||||
|
@ -98,7 +98,7 @@
|
||||
defined(SUPPORT_FILEFORMAT_JPG) || defined(SUPPORT_FILEFORMAT_PSD) || defined(SUPPORT_FILEFORMAT_GIF) || \
|
||||
defined(SUPPORT_FILEFORMAT_HDR))
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "external/stb_image.h" // Required for: stbi_load()
|
||||
#include "external/stb_image.h" // Required for: stbi_load_from_file()
|
||||
// NOTE: Used to read image data (multiple formats support)
|
||||
#endif
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user