diff options
| author | raysan5 <[email protected]> | 2017-04-17 16:42:01 +0200 |
|---|---|---|
| committer | raysan5 <[email protected]> | 2017-04-17 16:42:01 +0200 |
| commit | 881f134f4d2fb4419d50382284e19b4f8ca4660e (patch) | |
| tree | 065658f8b462dd76837f849450bdd3895134121a /docs/examples/src/audio | |
| parent | 3e082f1d6251e366d7be6019d0950ea7a9e6b5b4 (diff) | |
| download | raylib-881f134f4d2fb4419d50382284e19b4f8ca4660e.tar.gz raylib-881f134f4d2fb4419d50382284e19b4f8ca4660e.zip | |
Review and recompile web examples
Diffstat (limited to 'docs/examples/src/audio')
| -rw-r--r-- | docs/examples/src/audio/audio_module_playing.c | 6 | ||||
| -rw-r--r-- | docs/examples/src/audio/audio_music_stream.c | 4 | ||||
| -rw-r--r-- | docs/examples/src/audio/audio_raw_stream.c | 29 | ||||
| -rw-r--r-- | docs/examples/src/audio/audio_sound_loading.c | 4 |
4 files changed, 23 insertions, 20 deletions
diff --git a/docs/examples/src/audio/audio_module_playing.c b/docs/examples/src/audio/audio_module_playing.c index a9ee4619..671a119f 100644 --- a/docs/examples/src/audio/audio_module_playing.c +++ b/docs/examples/src/audio/audio_module_playing.c @@ -52,7 +52,7 @@ int main() circles[i].color = colors[GetRandomValue(0, 13)]; } - Music xm = LoadMusicStream("resources/audio/mini1111.xm"); + Music xm = LoadMusicStream("resources/mini1111.xm"); PlayMusicStream(xm); @@ -86,7 +86,7 @@ int main() } // Get timePlayed scaled to bar dimensions - timePlayed = (GetMusicTimePlayed(xm)/GetMusicTimeLength(xm)*(screenWidth - 40))*2; + timePlayed = GetMusicTimePlayed(xm)/GetMusicTimeLength(xm)*(screenWidth - 40); // Color circles animation for (int i = MAX_CIRCLES - 1; (i >= 0) && !pause; i--) @@ -112,7 +112,7 @@ int main() //---------------------------------------------------------------------------------- BeginDrawing(); - ClearBackground(WHITE); + ClearBackground(RAYWHITE); for (int i = MAX_CIRCLES - 1; i >= 0; i--) { diff --git a/docs/examples/src/audio/audio_music_stream.c b/docs/examples/src/audio/audio_music_stream.c index dc9d4355..f9fe23d2 100644 --- a/docs/examples/src/audio/audio_music_stream.c +++ b/docs/examples/src/audio/audio_music_stream.c @@ -24,7 +24,7 @@ int main() InitAudioDevice(); // Initialize audio device - Music music = LoadMusicStream("resources/audio/guitar_noodling.ogg"); + Music music = LoadMusicStream("resources/guitar_noodling.ogg"); PlayMusicStream(music); @@ -58,7 +58,7 @@ int main() } // Get timePlayed scaled to bar dimensions (400 pixels) - timePlayed = GetMusicTimePlayed(music)/GetMusicTimeLength(music)*100*4; + timePlayed = GetMusicTimePlayed(music)/GetMusicTimeLength(music)*400; //---------------------------------------------------------------------------------- // Draw diff --git a/docs/examples/src/audio/audio_raw_stream.c b/docs/examples/src/audio/audio_raw_stream.c index c044a7e0..80c83e96 100644 --- a/docs/examples/src/audio/audio_raw_stream.c +++ b/docs/examples/src/audio/audio_raw_stream.c @@ -16,7 +16,8 @@ #include <stdlib.h> // Required for: malloc(), free() #include <math.h> // Required for: sinf() -#define MAX_SAMPLES 20000 +#define MAX_SAMPLES 22050 +#define MAX_SAMPLES_PER_UPDATE 4096 int main() { @@ -29,21 +30,20 @@ int main() InitAudioDevice(); // Initialize audio device - // Init raw audio stream (sample rate: 22050, sample size: 32bit-float, channels: 1-mono) - AudioStream stream = InitAudioStream(22050, 32, 1); + // Init raw audio stream (sample rate: 22050, sample size: 16bit-short, channels: 1-mono) + AudioStream stream = InitAudioStream(22050, 16, 1); - // Fill audio stream with some samples (sine wave) - float *data = (float *)malloc(sizeof(float)*MAX_SAMPLES); + // Generate samples data from sine wave + short *data = (short *)malloc(sizeof(short)*MAX_SAMPLES); + // TODO: Review data generation, it seems data is discontinued for loop, + // for that reason, there is a clip everytime audio stream is looped... for (int i = 0; i < MAX_SAMPLES; i++) { - data[i] = sinf(((2*PI*(float)i)/2)*DEG2RAD); + data[i] = (short)(sinf(((2*PI*(float)i)/2)*DEG2RAD)*32000); } - // NOTE: The generated MAX_SAMPLES do not fit to close a perfect loop - // for that reason, there is a clip everytime audio stream is looped - - PlayAudioStream(stream); + PlayAudioStream(stream); // Start processing stream buffer (no data loaded currently) int totalSamples = MAX_SAMPLES; int samplesLeft = totalSamples; @@ -60,10 +60,13 @@ int main() //---------------------------------------------------------------------------------- // Refill audio stream if required + // NOTE: Every update we check if stream data has been already consumed and we update + // buffer with new data from the generated samples, we upload data at a rate (MAX_SAMPLES_PER_UPDATE), + // but notice that at some point we update < MAX_SAMPLES_PER_UPDATE data... if (IsAudioBufferProcessed(stream)) { int numSamples = 0; - if (samplesLeft >= 4096) numSamples = 4096; + if (samplesLeft >= MAX_SAMPLES_PER_UPDATE) numSamples = MAX_SAMPLES_PER_UPDATE; else numSamples = samplesLeft; UpdateAudioStream(stream, data + (totalSamples - samplesLeft), numSamples); @@ -83,11 +86,11 @@ int main() DrawText("SINE WAVE SHOULD BE PLAYING!", 240, 140, 20, LIGHTGRAY); - // NOTE: Draw a part of the sine wave (only screen width) + // NOTE: Draw a part of the sine wave (only screen width, proportional values) for (int i = 0; i < GetScreenWidth(); i++) { position.x = i; - position.y = 250 + 50*data[i]; + position.y = 250 + 50*data[i]/32000; DrawPixelV(position, RED); } diff --git a/docs/examples/src/audio/audio_sound_loading.c b/docs/examples/src/audio/audio_sound_loading.c index f081e8ed..00e58326 100644 --- a/docs/examples/src/audio/audio_sound_loading.c +++ b/docs/examples/src/audio/audio_sound_loading.c @@ -24,8 +24,8 @@ int main() InitAudioDevice(); // Initialize audio device - Sound fxWav = LoadSound("resources/audio/weird.wav"); // Load WAV audio file - Sound fxOgg = LoadSound("resources/audio/tanatana.ogg"); // Load OGG audio file + Sound fxWav = LoadSound("resources/sound.wav"); // Load WAV audio file + Sound fxOgg = LoadSound("resources/tanatana.ogg"); // Load OGG audio file SetTargetFPS(60); //-------------------------------------------------------------------------------------- |
