-
-
Save anonymous/90a6dccad86d9c02490ed92b64663985 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <psp2/kernel/processmgr.h> | |
#include <psp2/touch.h> | |
#include <psp2/display.h> | |
#include <psp2/audioout.h> | |
#include <stdio.h> | |
#include <string.h> | |
#include "debugScreen.h" | |
#define printf psvDebugScreenPrintf | |
/* TODO: why touch[port].report[i].force is always at 128 ? */ | |
double gen_sqr(double p){return p>.5?-1.:1.;} | |
double gen_tri(double p){return p*2;} | |
double gen_nul(double p){return 0.;} | |
typedef double (*wav_gen)(double); | |
void wave_set(int16_t*buffer, size_t size, wav_gen generator){ | |
for (size_t smpl = 0; smpl < size; ++smpl){ | |
buffer[smpl] = 0x7FFF*generator((float)smpl/(float)size); | |
printf("sample: %d", buffer[smpl]); | |
} | |
} | |
int main(int argc, char *argv[]) { | |
psvDebugScreenInit(); | |
wav_gen gen = gen_sqr; | |
int vol[] = {SCE_AUDIO_OUT_MAX_VOL,SCE_AUDIO_OUT_MAX_VOL}; | |
int16_t wave_buf[SCE_AUDIO_MAX_LEN]={0}; | |
int size = 256; | |
printf("swipe to the bottom with 1 finger to stop\n"); | |
/* should use SCE_TOUCH_SAMPLING_STATE_START instead of 1 but old SDK have an invalid values */ | |
sceTouchSetSamplingState(SCE_TOUCH_PORT_FRONT, 1); | |
sceTouchSetSamplingState(SCE_TOUCH_PORT_BACK, 1); | |
sceTouchEnableTouchForce(SCE_TOUCH_PORT_FRONT); | |
sceTouchEnableTouchForce(SCE_TOUCH_PORT_BACK); | |
SceTouchData touch_old[SCE_TOUCH_PORT_MAX_NUM]; | |
SceTouchData touch[SCE_TOUCH_PORT_MAX_NUM]; | |
while (1) { | |
memcpy(touch_old, touch, sizeof(touch_old)); | |
printf("\e[0;5H"); | |
int port,i; | |
/* sample both back and front surfaces */ | |
for(port = 0; port < SCE_TOUCH_PORT_MAX_NUM; port++){ | |
sceTouchPeek(port, &touch[port], 1); | |
printf("%s",((const char*[]){"FRONT","BACK "})[port]); | |
/* print every touch coordinates on that surface */ | |
for(i = 0; i < SCE_TOUCH_MAX_REPORT; i++) | |
printf("\e[9%im%4i:%-4i ", (i < touch[port].reportNum)? 7:0, | |
touch[port].report[i].x,touch[port].report[i].y); | |
printf("\n"); | |
} | |
int freq = 25*touch[SCE_TOUCH_PORT_FRONT].report[0].x; | |
printf("Frequency: %d", freq); | |
printf("\n"); | |
printf("vol0: %d",vol[0]); | |
printf("\n"); | |
printf("vol1: %d",vol[1]); | |
int audioPort = sceAudioOutOpenPort(SCE_AUDIO_OUT_PORT_TYPE_BGM,size,freq,SCE_AUDIO_OUT_MODE_MONO); | |
sceAudioOutSetVolume(audioPort, SCE_AUDIO_VOLUME_FLAG_L_CH |SCE_AUDIO_VOLUME_FLAG_R_CH, vol); | |
wave_set(wave_buf, size, gen); | |
sceAudioOutOutput(audioPort, wave_buf); | |
if ( (touch[SCE_TOUCH_PORT_FRONT].reportNum == 1) | |
&& (touch_old[SCE_TOUCH_PORT_FRONT].reportNum == 1) | |
&& (touch[SCE_TOUCH_PORT_FRONT].report[0].y >= 1000) | |
&& (touch_old[SCE_TOUCH_PORT_FRONT].report[0].y < 1000)) | |
break; | |
} | |
sceKernelExitProcess(0); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment