Skip to content

Commit

Permalink
Add build test for samples
Browse files Browse the repository at this point in the history
  • Loading branch information
sharkwouter committed Feb 18, 2024
1 parent 64495da commit 1f59128
Show file tree
Hide file tree
Showing 16 changed files with 918 additions and 4 deletions.
23 changes: 20 additions & 3 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
name: Deploy Jekyll site to Pages

on:
# Runs on pushes targeting the default branch
# Runs on pushes
push:
branches: ["master"]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand All @@ -27,6 +26,23 @@ concurrency:
cancel-in-progress: false

jobs:
# Test the samples to make sure they build
test:
runs-on: ubuntu-latest
container: pspdev/pspdev:latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build
run: |
cd _includes/samples
for SAMPLE_DIR in $(ls); do
cd "${SAMPLE_DIR}"
psp-cmake .
make
cd ..
done
# Build job
build:
runs-on: ubuntu-latest
Expand All @@ -51,13 +67,14 @@ jobs:
# Automatically uploads an artifact from the './_site' directory by default
uses: actions/upload-pages-artifact@v3

# Deployment job
# Deployment job, only runs for master branch
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
if: github.ref == 'refs/heads/master'
steps:
- name: Deploy to GitHub Pages
id: deployment
Expand Down
17 changes: 16 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,19 @@ Gemfile.lock
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
# .rubocop-https?--*

# End of https://www.toptal.com/developers/gitignore/api/jekyll,ruby
# End of https://www.toptal.com/developers/gitignore/api/jekyll,ruby

# Sample build files
_includes/samples/*/CMakeFiles/
_includes/samples/*/CMakeCache.txt
_includes/samples/*/Makefile
_includes/samples/*/cmake_install.cmake
_includes/samples/*/EBOOT.PBP
_includes/samples/*/PARAM.SFO
_includes/samples/audio/audio
_includes/samples/controls/controls
_includes/samples/hello/hello
_includes/samples/sdl2/sdl2
_includes/samples/sdl2_mixer/sdl2_mixer
_includes/samples/sdl2_ttf/sdl2_ttf
_includes/samples/shape/shape
24 changes: 24 additions & 0 deletions _includes/samples/audio/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
cmake_minimum_required(VERSION 3.0)

project(audio)

add_executable(${PROJECT_NAME} main.c)

target_link_libraries(${PROJECT_NAME} PRIVATE
pspdebug
pspdisplay
pspge
pspctrl
pspaudio
pspaudiolib
psputility
)

# Create an EBOOT.PBP file
create_pbp_file(
TARGET ${PROJECT_NAME}
ICON_PATH NULL
BACKGROUND_PATH NULL
PREVIEW_PATH NULL
TITLE ${PROJECT_NAME}
)
188 changes: 188 additions & 0 deletions _includes/samples/audio/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspaudiolib.h>
#include <pspaudio.h>
#include <pspdisplay.h>
#include <pspctrl.h>

#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>

PSP_MODULE_INFO("audio", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);

#define printf pspDebugScreenPrintf

/* Exit callback */
int exitCallback(int arg1, int arg2, void *common) {
sceKernelExitGame();
return 0;
}

/* Callback thread */
int callbackThread(SceSize args, void *argp) {
int cbid;

cbid = sceKernelCreateCallback("Exit Callback", (void*) exitCallback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();

return 0;
}

/* Sets up the callback thread and returns its thread id */
int setupCallbacks(void) {
int thid = 0;

thid = sceKernelCreateThread("update_thread", callbackThread, 0x11, 0xFA0, 0, 0);
if (thid >= 0) {
sceKernelStartThread(thid, 0, 0);
}
return thid;
}

/* Main code */

const float PI = 3.1415926535897932f;
const int sampleRate = 44100;
float frequency = 440.0f;
float currentTime = 0;
int function = 0;

typedef struct {
short l, r;
} sample_t;

float currentFunction(const float time) {
double x;
float t = modf((time / (2 * PI)), &x);

switch(function) {
case 0: // SINE
return sinf(time);
case 1: // SQUARE
if (t < 0.5f) {
return -0.2f;
} else {
return 0.2f;
}
case 2: // TRIANGLE
if (t < 0.5f) {
return (t * 2.0f) - 0.5f;
} else {
return 0.5f - (t - 0.5f) * 2.0f;
}
default:
return 0.0f;
}
}

/* This function gets called by pspaudiolib every time the
audio buffer needs to be filled. The sample format is
16-bit, stereo. */
void audioCallback(void* buf, unsigned int length, void *userdata) {
const float sampleLength = 1.0f / sampleRate;
const float scaleFactor = SHRT_MAX - 1.0f;
static float freq0 = 440.0f;
sample_t* ubuf = (sample_t*) buf;
int i;

if (frequency != freq0) {
currentTime *= (freq0 / frequency);
}
for (i = 0; i < length; i++) {
short s = (short) (scaleFactor * currentFunction(2.0f * PI * frequency * currentTime));
ubuf[i].l = s;
ubuf[i].r = s;
currentTime += sampleLength;
}
if (currentTime * frequency > 1.0f) {
double d;
currentTime = modf(currentTime * frequency, &d) / frequency;
}

freq0 = frequency;
}

/* Read the analog stick and adjust the frequency */
void controlFrequency(void) {
static int oldButtons = 0;
const int zones[6] = {30, 70, 100, 112, 125, 130};
const float response[6] = {0.0f, 0.1f, 0.5f, 1.0f, 4.0f, 8.0f};
const float minFreq = 32.0f;
const float maxFreq = 7040.0f;
SceCtrlData pad;
float direction;
int changedButtons;
int i, v;

sceCtrlReadBufferPositive(&pad, 1);

v = pad.Ly - 128;
if (v < 0) {
direction = 1.0f;
v = -v;
} else {
direction = -1.0f;
}

for (i = 0; i < 6; i++) {
if (v < zones[i]) {
frequency += (response[i] * direction);
break;
}
}

if (frequency < minFreq) {
frequency = minFreq;
} else if (frequency > maxFreq) {
frequency = maxFreq;
}

changedButtons = pad.Buttons & (~oldButtons);
if (changedButtons & PSP_CTRL_CROSS) {
function++;
if (function > 2) {
function = 0;
}
}

oldButtons = pad.Buttons;
}

int main(void) {
pspDebugScreenInit();
setupCallbacks();

pspAudioInit();
pspAudioSetChannelCallback(0, audioCallback, NULL);

sceCtrlSetSamplingCycle(0);
sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);

printf("Press up and down to select frequency\nPress X to change function\n");

while(1) {
sceDisplayWaitVblankStart();
pspDebugScreenSetXY(0,2);
printf("freq = %.2f \n", frequency);

switch(function) {
case 0:
printf("SINE WAVE. \n");
break;
case 1:
printf("SQUARE WAVE. \n");
break;
case 2:
printf("TRIANGLE WAVE. \n");
break;
}

controlFrequency();
}

return 0;
}
21 changes: 21 additions & 0 deletions _includes/samples/controls/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
cmake_minimum_required(VERSION 3.0)

project(controls)

add_executable(${PROJECT_NAME} main.c)

target_link_libraries(${PROJECT_NAME} PRIVATE
pspdebug
pspdisplay
pspge
pspctrl
)

# Create an EBOOT.PBP file
create_pbp_file(
TARGET ${PROJECT_NAME}
ICON_PATH NULL
BACKGROUND_PATH NULL
PREVIEW_PATH NULL
TITLE ${PROJECT_NAME}
)
Loading

0 comments on commit 1f59128

Please sign in to comment.