aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorraysan5 <raysan5@gmail.com>2016-08-03 09:26:30 +0200
committerraysan5 <raysan5@gmail.com>2016-08-03 09:26:30 +0200
commitd3d9aaceb12111ebe54f55f23cd87dfb43964f1f (patch)
treec0a11396384387bdc7f832f11c0e20501da5f949 /examples
parent8c0bd30fcb62550f71237cce73fc80efacbf8909 (diff)
downloadraylib-d3d9aaceb12111ebe54f55f23cd87dfb43964f1f.tar.gz
raylib-d3d9aaceb12111ebe54f55f23cd87dfb43964f1f.zip
Updated and comments
Diffstat (limited to 'examples')
-rw-r--r--examples/audio_raw_stream.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/examples/audio_raw_stream.c b/examples/audio_raw_stream.c
index 37a5b4ff..a372205b 100644
--- a/examples/audio_raw_stream.c
+++ b/examples/audio_raw_stream.c
@@ -16,6 +16,8 @@
#include <stdlib.h> // Required for: malloc(), free()
#include <math.h> // Required for: sinf()
+#define MAX_SAMPLES 20000
+
int main()
{
// Initialization
@@ -28,19 +30,23 @@ int main()
InitAudioDevice(); // Initialize audio device
- AudioStream stream = InitAudioStream(44100, 32, 1); // Init raw audio stream
+ // Init raw audio stream (sample rate: 22050, sample size: 32bit-float, channels: 1-mono)
+ AudioStream stream = InitAudioStream(22050, 32, 1);
// Fill audio stream with some samples (sine wave)
- float *data = (float *)malloc(sizeof(float)*44100);
+ float *data = (float *)malloc(sizeof(float)*MAX_SAMPLES);
- for (int i = 0; i < 44100; i++)
+ for (int i = 0; i < MAX_SAMPLES; i++)
{
- data[i] = sinf(2*PI*(float)i*DEG2RAD);
+ data[i] = sinf(((2*PI*(float)i)/2)*DEG2RAD);
}
+ // 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);
- int totalSamples = 44100;
+ int totalSamples = MAX_SAMPLES;
int samplesLeft = totalSamples;
Vector2 position = { 0, 0 };