summaryrefslogtreecommitdiffhomepage
path: root/examples/audio
diff options
context:
space:
mode:
authorchriscamacho <[email protected]>2019-06-29 09:49:42 +0100
committerRay <[email protected]>2019-06-29 10:49:42 +0200
commit83a4eb08525c25026dbf16211ef083a46745867f (patch)
treef681f33b075035a6540f391adcbc36b880b620bb /examples/audio
parenta4e307ed965d2bb64f915c604e8a9ea2c003cf48 (diff)
downloadraylib-83a4eb08525c25026dbf16211ef083a46745867f.tar.gz
raylib-83a4eb08525c25026dbf16211ef083a46745867f.zip
add multi channel audio to raudio (#895)
* added multi channel sound replay to raudio added -fPIC to Makefile for Linux added simple lighting and audio multi channel to examples Makefile * not properly reporting audio buffer pool size...
Diffstat (limited to 'examples/audio')
-rw-r--r--examples/audio/audio_multichannel_sound.c116
1 files changed, 116 insertions, 0 deletions
diff --git a/examples/audio/audio_multichannel_sound.c b/examples/audio/audio_multichannel_sound.c
new file mode 100644
index 00000000..42c71704
--- /dev/null
+++ b/examples/audio/audio_multichannel_sound.c
@@ -0,0 +1,116 @@
+
+/*
+* This example was coded to demonstrate multi channel audio changes added to raylib
+*
+* This example has been created using raylib (www.raylib.com)
+* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
+*
+* This example Copyright (c) 2018 Chris Camacho (codifies) http://bedroomcoders.co.uk/captcha/
+*
+* THIS EXAMPLE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+* OTHER DEALINGS IN THE SOFTWARE.
+*
+* This example may be freely redistributed.
+*/
+
+#include "raylib.h"
+#include <stdio.h> // sprintf
+
+int main(void)
+{
+ // Initialization
+ //--------------------------------------------------------------------------------------
+ const int screenWidth = 800;
+ const int screenHeight = 450;
+
+ InitWindow(screenWidth, screenHeight, "raylib [audio] abuse!");
+
+ InitAudioDevice(); // Initialize audio device
+
+ Sound fxWav = LoadSound("resources/sound.wav"); // Load WAV audio file
+ Sound fxOgg = LoadSound("resources/tanatana.ogg"); // Load OGG audio file
+
+
+ //InitPlayBufferPool();
+
+
+
+ SetTargetFPS(60); // Set our game to run at 60 frames-per-second
+ //--------------------------------------------------------------------------------------
+ int frame = 0;
+ // Main game loop
+
+ // old system still works alongside
+ SetSoundVolume(fxWav, 0.2); // effects all mutltiplay replay (really annoying sound!!!)
+ PlaySound(fxOgg);
+
+ bool inhibitWav = false;
+ bool inhibitOgg = false;
+ int maxFrame = 60;
+ int numberPlaying = 0;
+
+ while (!WindowShouldClose()) // Detect window close button or ESC key
+ {
+ // Update
+ //----------------------------------------------------------------------------------
+ frame++;
+
+ if (IsKeyDown(KEY_ENTER)) { inhibitWav=true; } else { inhibitWav=false; }
+ if (IsKeyDown(KEY_SPACE)) { inhibitOgg=true; } else { inhibitOgg=false; }
+
+ // deliberatly hammer the play pool to see what dropping old
+ // pool entries sounds like....
+ if (frame % 5==0) {
+ if (!inhibitWav) PlaySoundEx(fxWav);
+ }
+ if (frame==maxFrame) {
+ if (!inhibitOgg) PlaySoundEx(fxOgg);
+ frame=0;
+ maxFrame = GetRandomValue(6,12);
+ }
+
+ numberPlaying = ConcurrentPlayChannels();
+
+ //----------------------------------------------------------------------------------
+
+
+ // Draw
+ //----------------------------------------------------------------------------------
+ BeginDrawing();
+
+ ClearBackground(RAYWHITE);
+ char msg[1024];
+ DrawText("multichannel sound abuse!", 200, 180, 20, LIGHTGRAY);
+ DrawText("Space to inhibit new ogg triggering", 200, 200, 20, LIGHTGRAY);
+ DrawText("Enter to inhibit new wav triggering", 200, 220, 20, LIGHTGRAY);
+
+ sprintf(msg,"concurrently playing %i", numberPlaying);
+ DrawText(msg, 200, 280, 20, LIGHTGRAY);
+
+ EndDrawing();
+ //----------------------------------------------------------------------------------
+ }
+
+ // De-Initialization
+ //--------------------------------------------------------------------------------------
+
+
+ // you MUST stop the buffer pool before unloading
+ // any Sounds it might have used...
+ StopPlayBufferPool();
+
+ UnloadSound(fxWav); // Unload sound data
+ UnloadSound(fxOgg); // Unload sound data
+
+ CloseAudioDevice(); // Close audio device
+
+ CloseWindow(); // Close window and OpenGL context
+ //--------------------------------------------------------------------------------------
+
+ return 0;
+}