switch-examples: Updated Makefile for romfs and updated all audio examples for switch

This commit is contained in:
Spencer Vaughn 2023-02-22 18:22:42 -06:00
commit 6719c57ba8
23 changed files with 85 additions and 49 deletions

View file

@ -51,6 +51,11 @@ USE_EXTERNAL_GLFW ?= FALSE
# NOTE: This variable is only used for PLATFORM_OS: LINUX
USE_WAYLAND_DISPLAY ?= FALSE
# Define romfs folder location relative to Makefile
ifeq ($(PLATFORM),PLATFORM_NX)
ROMFS := romfs
endif
# Use cross-compiler for PLATFORM_RPI
ifeq ($(PLATFORM),PLATFORM_RPI)
USE_RPI_CROSS_COMPILER ?= FALSE
@ -561,7 +566,7 @@ else ifeq ($(PLATFORM),PLATFORM_NX)
$(CXX) $@.o $(LDFLAGS) $(LDLIBS) -o $@.elf -D$(PLATFORM)
$(NM) -CSn $@.elf > $@.lst
nacptool --create "$(notdir $@)" "Raylib Example" "1.0.0" $@.nacp
elf2nro $@.elf $@.nro --icon=textures/resources/raylib_logo.jpg --nacp=$@.nacp
elf2nro $@.elf $@.nro --icon=textures/resources/raylib_logo.jpg --nacp=$@.nacp --romfsdir=$(CURDIR)/$(ROMFS)
else
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
endif

View file

@ -34,6 +34,7 @@ int main(void)
const int screenWidth = 1280;
const int screenHeight = 720;
// Initialize resource directory
romfsInit();
SetConfigFlags(FLAG_MSAA_4X_HINT); // NOTE: Try to enable MSAA 4X
@ -58,7 +59,7 @@ int main(void)
circles[i].color = colors[GetRandomValue(0, 13)];
}
Music music = LoadMusicStream("resources/mini1111.xm");
Music music = LoadMusicStream("romfs:/resources/mini1111.xm");
music.looping = false;
float pitch = 1.0f;
@ -78,14 +79,14 @@ int main(void)
UpdateMusicStream(music); // Update music buffer with new stream data
// Restart music playing (stop and play)
if (IsKeyPressed(KEY_SPACE))
if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_LEFT))
{
StopMusicStream(music);
PlayMusicStream(music);
}
// Pause/Resume music playing
if (IsKeyPressed(KEY_P))
if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_RIGHT))
{
pause = !pause;
@ -93,8 +94,8 @@ int main(void)
else ResumeMusicStream(music);
}
if (IsKeyDown(KEY_DOWN)) pitch -= 0.01f;
else if (IsKeyDown(KEY_UP)) pitch += 0.01f;
if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_DOWN)) pitch -= 0.01f;
else if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_UP)) pitch += 0.01f;
SetMusicPitch(music, pitch);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 47 KiB

View file

@ -14,6 +14,7 @@
********************************************************************************************/
#include "raylib.h"
#include <switch.h>
//------------------------------------------------------------------------------------
// Program main entry point
@ -25,12 +26,14 @@ int main(void)
const int screenWidth = 1280;
const int screenHeight = 720;
// Initialize resource directory
romfsInit();
InitWindow(screenWidth, screenHeight, "raylib [audio] example - Multichannel sound playing");
InitAudioDevice(); // Initialize audio device
Sound fxWav = LoadSound("resources/sound.wav"); // Load WAV audio file
Sound fxOgg = LoadSound("resources/target.ogg"); // Load OGG audio file
Sound fxWav = LoadSound("romfs:/resources/sound.wav"); // Load WAV audio file
Sound fxOgg = LoadSound("romfs:/resources/target.ogg"); // Load OGG audio file
SetSoundVolume(fxWav, 0.2f);
@ -42,8 +45,8 @@ int main(void)
{
// Update
//----------------------------------------------------------------------------------
if (IsKeyPressed(KEY_ENTER)) PlaySoundMulti(fxWav); // Play a new wav sound instance
if (IsKeyPressed(KEY_SPACE)) PlaySoundMulti(fxOgg); // Play a new ogg sound instance
if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_RIGHT)) PlaySoundMulti(fxWav); // Play a new wav sound instance
if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_DOWN)) PlaySoundMulti(fxOgg); // Play a new ogg sound instance
//----------------------------------------------------------------------------------
// Draw
@ -53,8 +56,8 @@ int main(void)
ClearBackground(RAYWHITE);
DrawText("MULTICHANNEL SOUND PLAYING", 20, 20, 20, GRAY);
DrawText("Press SPACE to play new ogg instance!", 200, 120, 20, LIGHTGRAY);
DrawText("Press ENTER to play new wav instance!", 200, 180, 20, LIGHTGRAY);
DrawText("Press A button to play new ogg instance!", 200, 120, 20, LIGHTGRAY);
DrawText("Press B button to play new wav instance!", 200, 180, 20, LIGHTGRAY);
DrawText(TextFormat("CONCURRENT SOUNDS PLAYING: %02i", GetSoundsPlaying()), 220, 280, 20, RED);
@ -74,5 +77,6 @@ int main(void)
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
romfsExit();
return 0;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

View file

@ -12,6 +12,7 @@
********************************************************************************************/
#include "raylib.h"
#include <switch.h>
//------------------------------------------------------------------------------------
// Program main entry point
@ -23,11 +24,13 @@ int main(void)
const int screenWidth = 1280;
const int screenHeight = 720;
// Initialize resource directory
romfsInit();
InitWindow(screenWidth, screenHeight, "raylib [audio] example - music playing (streaming)");
InitAudioDevice(); // Initialize audio device
Music music = LoadMusicStream("resources/country.mp3");
Music music = LoadMusicStream("romfs:/resources/country.mp3");
PlayMusicStream(music);
@ -45,14 +48,14 @@ int main(void)
UpdateMusicStream(music); // Update music buffer with new stream data
// Restart music playing (stop and play)
if (IsKeyPressed(KEY_SPACE))
if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_LEFT))
{
StopMusicStream(music);
PlayMusicStream(music);
}
// Pause/Resume music playing
if (IsKeyPressed(KEY_P))
if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_RIGHT))
{
pause = !pause;
@ -72,14 +75,14 @@ int main(void)
ClearBackground(RAYWHITE);
DrawText("MUSIC SHOULD BE PLAYING!", 255, 150, 20, LIGHTGRAY);
DrawText("MUSIC SHOULD BE PLAYING!", screenWidth/2 - 150, screenHeight/2 - 50, 20, LIGHTGRAY);
DrawRectangle(200, 200, 400, 12, LIGHTGRAY);
DrawRectangle(200, 200, (int)(timePlayed*400.0f), 12, MAROON);
DrawRectangleLines(200, 200, 400, 12, GRAY);
DrawRectangle(screenWidth/2 - 200, screenHeight/2, 400, 12, LIGHTGRAY);
DrawRectangle(screenWidth/2 - 200, screenHeight/2, (int)(timePlayed*400.0f), 12, MAROON);
DrawRectangleLines(screenWidth/2 - 200, screenHeight/2, 400, 12, GRAY);
DrawText("PRESS SPACE TO RESTART MUSIC", 215, 250, 20, LIGHTGRAY);
DrawText("PRESS P TO PAUSE/RESUME MUSIC", 208, 280, 20, LIGHTGRAY);
DrawText("PRESS Y button TO RESTART MUSIC", screenWidth/2 -200, screenHeight/2 + 50, 20, LIGHTGRAY);
DrawText("PRESS A button TO PAUSE/RESUME MUSIC", screenWidth/2 -200, screenHeight/2 + 80, 20, LIGHTGRAY);
EndDrawing();
//----------------------------------------------------------------------------------
@ -94,5 +97,6 @@ int main(void)
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
romfsExit();
return 0;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

View file

@ -82,6 +82,8 @@ int main(void)
// Position read in to determine next frequency
Vector2 mousePosition = { -100.0f, -100.0f };
const int GAMEPAD = 0;
Vector2 thumbPosition = { screenWidth/2, screenHeight/2 };
/*
// Cycles per second (hz)
@ -108,15 +110,20 @@ int main(void)
// Update
//----------------------------------------------------------------------------------
// Sample mouse input.
mousePosition = GetMousePosition();
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT))
// Sample mouse input
if (IsGamepadAvailable(GAMEPAD))
{
float fp = (float)(mousePosition.y);
thumbPosition.x += (float) GetGamepadAxisMovement(GAMEPAD, 0) * 15;
thumbPosition.y -= (float) GetGamepadAxisMovement(GAMEPAD, 1) * 15;
}
if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_RIGHT))
{
float fp = (float)(thumbPosition.y);
frequency = 40.0f + (float)(fp);
float pan = (float)(mousePosition.x) / (float)screenWidth;
float pan = (float)(thumbPosition.x) / (float)screenWidth;
SetAudioStreamPan(stream, pan);
}
@ -185,7 +192,7 @@ int main(void)
ClearBackground(RAYWHITE);
DrawText(TextFormat("sine frequency: %i",(int)frequency), GetScreenWidth() - 220, 10, 20, RED);
DrawText("click mouse button to change frequency or pan", 10, 10, 20, DARKGRAY);
DrawText("Press A button to change frequency and pan with Left Thumbstick", 10, 10, 20, DARKGRAY);
// Draw the current buffer state proportionate to the screen
for (int i = 0; i < screenWidth; i++)
@ -195,6 +202,7 @@ int main(void)
DrawPixelV(position, RED);
}
DrawCircle(thumbPosition.x, thumbPosition.y, 20, DARKGRAY);
EndDrawing();
//----------------------------------------------------------------------------------

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

View file

@ -12,6 +12,7 @@
********************************************************************************************/
#include "raylib.h"
#include <switch.h>
//------------------------------------------------------------------------------------
// Program main entry point
@ -23,12 +24,14 @@ int main(void)
const int screenWidth = 1280;
const int screenHeight = 720;
// Initialize resource directory
romfsInit();
InitWindow(screenWidth, screenHeight, "raylib [audio] example - sound loading and playing");
InitAudioDevice(); // Initialize audio device
Sound fxWav = LoadSound("resources/sound.wav"); // Load WAV audio file
Sound fxOgg = LoadSound("resources/target.ogg"); // Load OGG audio file
Sound fxWav = LoadSound("romfs:/resources/sound.wav"); // Load WAV audio file
Sound fxOgg = LoadSound("romfs:/resources/target.ogg"); // Load OGG audio file
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@ -38,8 +41,8 @@ int main(void)
{
// Update
//----------------------------------------------------------------------------------
if (IsKeyPressed(KEY_SPACE)) PlaySound(fxWav); // Play WAV sound
if (IsKeyPressed(KEY_ENTER)) PlaySound(fxOgg); // Play OGG sound
if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_RIGHT)) PlaySound(fxWav); // Play WAV sound
if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_DOWN)) PlaySound(fxOgg); // Play OGG sound
//----------------------------------------------------------------------------------
// Draw
@ -48,8 +51,8 @@ int main(void)
ClearBackground(RAYWHITE);
DrawText("Press SPACE to PLAY the WAV sound!", 200, 180, 20, LIGHTGRAY);
DrawText("Press ENTER to PLAY the OGG sound!", 200, 220, 20, LIGHTGRAY);
DrawText("Press button A to PLAY the WAV sound!", 200, 180, 20, LIGHTGRAY);
DrawText("Press button B to PLAY the OGG sound!", 200, 220, 20, LIGHTGRAY);
EndDrawing();
//----------------------------------------------------------------------------------
@ -65,5 +68,6 @@ int main(void)
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
romfsExit();
return 0;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

View file

@ -14,6 +14,7 @@
#include "raylib.h"
#include <stdlib.h> // Required for: NULL
#include <switch.h>
// Required delay effect variables
static float *delayBuffer = NULL;
@ -37,11 +38,13 @@ int main(void)
const int screenWidth = 1280;
const int screenHeight = 720;
// Initialize resource directory
romfsInit();
InitWindow(screenWidth, screenHeight, "raylib [audio] example - stream effects");
InitAudioDevice(); // Initialize audio device
Music music = LoadMusicStream("resources/country.mp3");
Music music = LoadMusicStream("romfs:/resources/country.mp3");
// Allocate buffer for the delay effect
delayBufferSize = 48000*2; // 1 second delay (device sampleRate*channels)
@ -66,14 +69,14 @@ int main(void)
UpdateMusicStream(music); // Update music buffer with new stream data
// Restart music playing (stop and play)
if (IsKeyPressed(KEY_SPACE))
if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_LEFT))
{
StopMusicStream(music);
PlayMusicStream(music);
}
// Pause/Resume music playing
if (IsKeyPressed(KEY_P))
if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_RIGHT))
{
pause = !pause;
@ -82,7 +85,7 @@ int main(void)
}
// Add/Remove effect: lowpass filter
if (IsKeyPressed(KEY_F))
if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_UP))
{
enableEffectLPF = !enableEffectLPF;
if (enableEffectLPF) AttachAudioStreamProcessor(music.stream, AudioProcessEffectLPF);
@ -90,7 +93,7 @@ int main(void)
}
// Add/Remove effect: delay
if (IsKeyPressed(KEY_D))
if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_DOWN))
{
enableEffectDelay = !enableEffectDelay;
if (enableEffectDelay) AttachAudioStreamProcessor(music.stream, AudioProcessEffectDelay);
@ -109,17 +112,17 @@ int main(void)
ClearBackground(RAYWHITE);
DrawText("MUSIC SHOULD BE PLAYING!", 245, 150, 20, LIGHTGRAY);
DrawText("MUSIC SHOULD BE PLAYING!", screenWidth/2 - 200, 230, 20, LIGHTGRAY);
DrawRectangle(200, 180, 400, 12, LIGHTGRAY);
DrawRectangle(200, 180, (int)(timePlayed*400.0f), 12, MAROON);
DrawRectangleLines(200, 180, 400, 12, GRAY);
DrawRectangle(screenWidth/2 - 200, 260, 400, 12, LIGHTGRAY);
DrawRectangle(screenWidth/2 - 200, 260, (int)(timePlayed*400.0f), 12, MAROON);
DrawRectangleLines(screenWidth/2 - 200, 260, 400, 12, GRAY);
DrawText("PRESS SPACE TO RESTART MUSIC", 215, 230, 20, LIGHTGRAY);
DrawText("PRESS P TO PAUSE/RESUME MUSIC", 208, 260, 20, LIGHTGRAY);
DrawText("PRESS Y button TO RESTART MUSIC", screenWidth/2 - 200, 310, 20, LIGHTGRAY);
DrawText("PRESS A button TO PAUSE/RESUME MUSIC", screenWidth/2 - 200, 340, 20, LIGHTGRAY);
DrawText(TextFormat("PRESS F TO TOGGLE LPF EFFECT: %s", enableEffectLPF? "ON" : "OFF"), 200, 320, 20, GRAY);
DrawText(TextFormat("PRESS D TO TOGGLE DELAY EFFECT: %s", enableEffectDelay? "ON" : "OFF"), 180, 350, 20, GRAY);
DrawText(TextFormat("PRESS X button TO TOGGLE LPF EFFECT: %s", enableEffectLPF? "ON" : "OFF"), screenWidth/2 - 200, 400, 20, GRAY);
DrawText(TextFormat("PRESS B button TO TOGGLE DELAY EFFECT: %s", enableEffectDelay? "ON" : "OFF"), screenWidth/2 - 200, 430, 20, GRAY);
EndDrawing();
//----------------------------------------------------------------------------------
@ -136,6 +139,7 @@ int main(void)
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
romfsExit();
return 0;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

View file

@ -0,0 +1,10 @@
| resource | author | licence | notes |
| :------------------- | :---------: | :------ | :---- |
| country.mp3 | [@emegeme](https://github.com/emegeme) | [CC0](https://creativecommons.org/publicdomain/zero/1.0/) | Originally created for "DART that TARGET" game |
| target.ogg | [@emegeme](https://github.com/emegeme) | [CC0](https://creativecommons.org/publicdomain/zero/1.0/) | Originally created for "DART that TARGET" game |
| target.flac | [@emegeme](https://github.com/emegeme) | [CC0](https://creativecommons.org/publicdomain/zero/1.0/) | Originally created for "DART that TARGET" game |
| coin.wav | [@raysan5](https://github.com/raysan5) | [CC0](https://creativecommons.org/publicdomain/zero/1.0/) | Made with [rFXGen](https://raylibtech.itch.io/rfxgen) |
| sound.wav | [@raysan5](https://github.com/raysan5) | [CC0](https://creativecommons.org/publicdomain/zero/1.0/) | Made with [rFXGen](https://raylibtech.itch.io/rfxgen) |
| spring.wav | [@raysan5](https://github.com/raysan5) | [CC0](https://creativecommons.org/publicdomain/zero/1.0/) | Made with [rFXGen](https://raylibtech.itch.io/rfxgen) |
| weird.wav | [@raysan5](https://github.com/raysan5) | [CC0](https://creativecommons.org/publicdomain/zero/1.0/) | Made with [rFXGen](https://raylibtech.itch.io/rfxgen) |
| mini1111.xm | [tPORt](https://modarchive.org/index.php?request=view_by_moduleid&query=51891) | [Mod Archive Distribution license](https://modarchive.org/index.php?terms-upload) | - |

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show more