aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRay <raysan5@gmail.com>2017-05-03 14:16:53 +0200
committerRay <raysan5@gmail.com>2017-05-03 14:16:53 +0200
commit2d5c8e61b1d34b9b482b807f5bef555f532533fd (patch)
treea4890493162e8139b31d827eaa8c49983462ca3e /src
parent73774aadd63bba93908ee57f1e711c9bf2c70b53 (diff)
downloadraylib-2d5c8e61b1d34b9b482b807f5bef555f532533fd.tar.gz
raylib-2d5c8e61b1d34b9b482b807f5bef555f532533fd.zip
Some code tweaks
Diffstat (limited to 'src')
-rw-r--r--src/audio.c20
-rw-r--r--src/textures.c2
2 files changed, 9 insertions, 13 deletions
diff --git a/src/audio.c b/src/audio.c
index d63047a8..e8e80985 100644
--- a/src/audio.c
+++ b/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);
diff --git a/src/textures.c b/src/textures.c
index 2b61c241..d944bd64 100644
--- a/src/textures.c
+++ b/src/textures.c
@@ -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