mirror of
https://github.com/switchbrew/switch-examples.git
synced 2025-06-21 21:32:40 +02:00
Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
bf9df10259 | ||
|
5e36dc2902 | ||
|
399aa26c6e | ||
|
b41c4957e7 | ||
|
d1b2175d58 | ||
|
4f6e700642 |
@ -74,15 +74,15 @@ int main(void)
|
|||||||
|
|
||||||
size_t num_channels = 1;
|
size_t num_channels = 1;
|
||||||
size_t samplerate = 48000;
|
size_t samplerate = 48000;
|
||||||
size_t max_samples = samplerate;
|
size_t max_samples = samplerate/20;//each wavebuf can hold upto 1sec/20 = 50ms of audio data
|
||||||
size_t max_samples_datasize = max_samples*num_channels*sizeof(opus_int16);
|
size_t max_samples_datasize = max_samples*num_channels*sizeof(opus_int16);
|
||||||
size_t mempool_size = (max_samples_datasize*2 + 0xFFF) &~ 0xFFF;//*2 for 2 wavebufs.
|
size_t mempool_size = (max_samples_datasize*4 + 0xFFF) &~ 0xFFF;//*4 for 4 wavebufs.
|
||||||
void* mempool_ptr = memalign(0x1000, mempool_size);
|
void* mempool_ptr = memalign(0x1000, mempool_size);
|
||||||
void* tmpdata_ptr = malloc(max_samples_datasize);
|
void* tmpdata_ptr = malloc(max_samples_datasize);
|
||||||
opuspkt_tmpbuf = (u8*)malloc(opuspkt_tmpbuf_size);
|
opuspkt_tmpbuf = (u8*)malloc(opuspkt_tmpbuf_size);
|
||||||
opus_int16* curbuf = NULL;
|
opus_int16* curbuf = NULL;
|
||||||
|
|
||||||
AudioDriverWaveBuf wavebuf[2] = {0};
|
AudioDriverWaveBuf wavebuf[4] = {0};
|
||||||
int i, wavei;
|
int i, wavei;
|
||||||
|
|
||||||
HwopusDecoder hwdecoder = {0};
|
HwopusDecoder hwdecoder = {0};
|
||||||
@ -151,9 +151,9 @@ int main(void)
|
|||||||
}
|
}
|
||||||
audrvVoiceStart(&drv, 0);
|
audrvVoiceStart(&drv, 0);
|
||||||
|
|
||||||
for(i=0; i<2; i++) {
|
for(i=0; i<4; i++) {
|
||||||
wavebuf[i].data_raw = mempool_ptr;
|
wavebuf[i].data_raw = mempool_ptr;
|
||||||
wavebuf[i].size = max_samples_datasize*2;//*2 for 2 wavebufs.
|
wavebuf[i].size = max_samples_datasize*4;//*4 for 4 wavebufs.
|
||||||
wavebuf[i].start_sample_offset = i * max_samples;
|
wavebuf[i].start_sample_offset = i * max_samples;
|
||||||
wavebuf[i].end_sample_offset = wavebuf[i].start_sample_offset + max_samples;
|
wavebuf[i].end_sample_offset = wavebuf[i].start_sample_offset + max_samples;
|
||||||
}
|
}
|
||||||
@ -198,7 +198,7 @@ int main(void)
|
|||||||
|
|
||||||
if (audio_playing) {
|
if (audio_playing) {
|
||||||
wavei = -1;
|
wavei = -1;
|
||||||
for(i=0; i<2; i++) {
|
for(i=0; i<4; i++) {
|
||||||
if (wavebuf[i].state == AudioDriverWaveBufState_Free || wavebuf[i].state == AudioDriverWaveBufState_Done) {
|
if (wavebuf[i].state == AudioDriverWaveBufState_Free || wavebuf[i].state == AudioDriverWaveBufState_Done) {
|
||||||
wavei = i;
|
wavei = i;
|
||||||
break;
|
break;
|
||||||
@ -206,7 +206,7 @@ int main(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (wavei >= 0) {
|
if (wavei >= 0) {
|
||||||
curbuf = (opus_int16*)(mempool_ptr + wavebuf[wavei].start_sample_offset);
|
curbuf = (opus_int16*)(mempool_ptr + wavebuf[wavei].start_sample_offset * sizeof(opus_int16));
|
||||||
|
|
||||||
opret = op_read(of, tmpdata_ptr, max_samples * num_channels, NULL);//The buffer used here has to be seperate from mempool_ptr.
|
opret = op_read(of, tmpdata_ptr, max_samples * num_channels, NULL);//The buffer used here has to be seperate from mempool_ptr.
|
||||||
if (opret < 0)
|
if (opret < 0)
|
||||||
|
@ -100,7 +100,7 @@ int main(int argc, char** argv) {
|
|||||||
TTF_Init();
|
TTF_Init();
|
||||||
|
|
||||||
SDL_Window* window = SDL_CreateWindow("sdl2+mixer+image+ttf demo", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SCREEN_W, SCREEN_H, SDL_WINDOW_SHOWN);
|
SDL_Window* window = SDL_CreateWindow("sdl2+mixer+image+ttf demo", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SCREEN_W, SCREEN_H, SDL_WINDOW_SHOWN);
|
||||||
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_SOFTWARE);
|
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
|
||||||
|
|
||||||
// load logos from file
|
// load logos from file
|
||||||
SDL_Surface *sdllogo = IMG_Load("data/sdl.png");
|
SDL_Surface *sdllogo = IMG_Load("data/sdl.png");
|
||||||
|
@ -28,17 +28,12 @@ int main(int argc, char* argv[])
|
|||||||
PadState pad;
|
PadState pad;
|
||||||
padInitializeDefault(&pad);
|
padInitializeDefault(&pad);
|
||||||
|
|
||||||
printf("Press PLUS to exit.\n");
|
|
||||||
|
|
||||||
// Two VibrationDeviceHandles are returned: first one for left-joycon, second one for right-joycon.
|
// Two VibrationDeviceHandles are returned: first one for left-joycon, second one for right-joycon.
|
||||||
// Change the total_handles param to 1, and update the hidSendVibrationValues calls, if you only want 1 VibrationDeviceHandle.
|
// Change the total_handles param to 1, and update the hidSendVibrationValues calls, if you only want 1 VibrationDeviceHandle.
|
||||||
rc = hidInitializeVibrationDevices(VibrationDeviceHandles[0], 2, HidNpadIdType_Handheld, HidNpadStyleTag_NpadHandheld);
|
rc = hidInitializeVibrationDevices(VibrationDeviceHandles[0], 2, HidNpadIdType_Handheld, HidNpadStyleTag_NpadHandheld);
|
||||||
|
|
||||||
// Setup VibrationDeviceHandles for HidNpadIdType_No1 too, since we want to support both HidNpadIdType_Handheld and HidNpadIdType_No1.
|
// Setup VibrationDeviceHandles for HidNpadIdType_No1 too, since we want to support both HidNpadIdType_Handheld and HidNpadIdType_No1.
|
||||||
if (R_SUCCEEDED(rc)) rc = hidInitializeVibrationDevices(VibrationDeviceHandles[1], 2, HidNpadIdType_No1, HidNpadStyleTag_NpadJoyDual);
|
if (R_SUCCEEDED(rc)) rc = hidInitializeVibrationDevices(VibrationDeviceHandles[1], 2, HidNpadIdType_No1, HidNpadStyleTag_NpadJoyDual);
|
||||||
printf("hidInitializeVibrationDevices() returned: 0x%x\n", rc);
|
|
||||||
|
|
||||||
if (R_SUCCEEDED(rc)) printf("Hold R to vibrate, and press A/B/X/Y while holding R to adjust values.\n");
|
|
||||||
|
|
||||||
VibrationValue.amp_low = 0.2f;
|
VibrationValue.amp_low = 0.2f;
|
||||||
VibrationValue.freq_low = 10.0f;
|
VibrationValue.freq_low = 10.0f;
|
||||||
@ -55,6 +50,14 @@ int main(int argc, char* argv[])
|
|||||||
// Main loop
|
// Main loop
|
||||||
while(appletMainLoop())
|
while(appletMainLoop())
|
||||||
{
|
{
|
||||||
|
consoleClear();
|
||||||
|
printf("Press PLUS to exit.\n");
|
||||||
|
printf("Hold R to vibrate.\n");
|
||||||
|
printf("Press D-Pad (frequency) and face buttons (amplitude) to adjust values.\n");
|
||||||
|
|
||||||
|
printf("High frequency %.0f, amplitude %.1f\n", VibrationValue.freq_high, VibrationValue.amp_high);
|
||||||
|
printf("Low frequency %.0f, amplitude %.1f\n", VibrationValue.freq_low, VibrationValue.amp_low);
|
||||||
|
|
||||||
// Scan the gamepad. This should be done once for each frame
|
// Scan the gamepad. This should be done once for each frame
|
||||||
padUpdate(&pad);
|
padUpdate(&pad);
|
||||||
|
|
||||||
@ -67,6 +70,18 @@ int main(int argc, char* argv[])
|
|||||||
//Select which devices to vibrate.
|
//Select which devices to vibrate.
|
||||||
target_device = padIsHandheld(&pad) ? 0 : 1;
|
target_device = padIsHandheld(&pad) ? 0 : 1;
|
||||||
|
|
||||||
|
if (kDown & HidNpadButton_A) VibrationValue.amp_low += 0.1f;
|
||||||
|
if (kDown & HidNpadButton_Y) VibrationValue.amp_low -= 0.1f;
|
||||||
|
|
||||||
|
if (kDown & HidNpadButton_X) VibrationValue.amp_high += 0.1f;
|
||||||
|
if (kDown & HidNpadButton_B) VibrationValue.amp_high -= 0.1f;
|
||||||
|
|
||||||
|
if (kDown & HidNpadButton_Right) VibrationValue.freq_low += 5.0f;
|
||||||
|
if (kDown & HidNpadButton_Left) VibrationValue.freq_low -= 5.0f;
|
||||||
|
|
||||||
|
if (kDown & HidNpadButton_Up) VibrationValue.freq_high += 12.0f;
|
||||||
|
if (kDown & HidNpadButton_Down) VibrationValue.freq_high -= 12.0f;
|
||||||
|
|
||||||
if (R_SUCCEEDED(rc) && (kHeld & HidNpadButton_R))
|
if (R_SUCCEEDED(rc) && (kHeld & HidNpadButton_R))
|
||||||
{
|
{
|
||||||
//Calling hidSendVibrationValue/hidSendVibrationValues is really only needed when sending new VibrationValue(s).
|
//Calling hidSendVibrationValue/hidSendVibrationValues is really only needed when sending new VibrationValue(s).
|
||||||
@ -77,11 +92,6 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
rc2 = hidSendVibrationValues(VibrationDeviceHandles[target_device], VibrationValues, 2);
|
rc2 = hidSendVibrationValues(VibrationDeviceHandles[target_device], VibrationValues, 2);
|
||||||
if (R_FAILED(rc2)) printf("hidSendVibrationValues() returned: 0x%x\n", rc2);
|
if (R_FAILED(rc2)) printf("hidSendVibrationValues() returned: 0x%x\n", rc2);
|
||||||
|
|
||||||
if (kDown & HidNpadButton_A) VibrationValue.amp_low += 0.1f;
|
|
||||||
if (kDown & HidNpadButton_B) VibrationValue.freq_low += 5.0f;
|
|
||||||
if (kDown & HidNpadButton_X) VibrationValue.amp_high += 0.1f;
|
|
||||||
if (kDown & HidNpadButton_Y) VibrationValue.freq_high += 12.0f;
|
|
||||||
}
|
}
|
||||||
else if(kUp & HidNpadButton_R)//Stop vibration for all devices.
|
else if(kUp & HidNpadButton_R)//Stop vibration for all devices.
|
||||||
{
|
{
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
#include <switch.h>
|
#include <switch.h>
|
||||||
|
|
||||||
const char* const chargers[3] = {"None", "Official", "Generic"};
|
const char* const chargers[4] = {"None", "Full Power", "Low Power", "Unsupported"};
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
@ -166,7 +166,8 @@
|
|||||||
"type": "debug_flags",
|
"type": "debug_flags",
|
||||||
"value": {
|
"value": {
|
||||||
"allow_debug": false,
|
"allow_debug": false,
|
||||||
"force_debug": true
|
"force_debug": true,
|
||||||
|
"force_debug_prod": false
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#include <switch.h>
|
#include <switch.h>
|
||||||
@ -20,6 +21,7 @@ int main(int argc, char **argv)
|
|||||||
padInitializeDefault(&pad);
|
padInitializeDefault(&pad);
|
||||||
|
|
||||||
printf("\x1b[16;16HPress PLUS to exit.");
|
printf("\x1b[16;16HPress PLUS to exit.");
|
||||||
|
printf("\x1b[17;16HTZ=%s\n", getenv("TZ"));
|
||||||
|
|
||||||
// Main loop
|
// Main loop
|
||||||
while(appletMainLoop())
|
while(appletMainLoop())
|
||||||
@ -34,7 +36,7 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
//Print current time
|
//Print current time
|
||||||
time_t unixTime = time(NULL);
|
time_t unixTime = time(NULL);
|
||||||
struct tm* timeStruct = gmtime((const time_t *)&unixTime);//Gets UTC time. If you want local-time use localtime().
|
struct tm* timeStruct = localtime((const time_t *)&unixTime); // Gets local time. If you want UTC use gmtime().
|
||||||
|
|
||||||
int hours = timeStruct->tm_hour;
|
int hours = timeStruct->tm_hour;
|
||||||
int minutes = timeStruct->tm_min;
|
int minutes = timeStruct->tm_min;
|
||||||
|
Loading…
Reference in New Issue
Block a user