mirror of
https://github.com/switchbrew/switch-examples.git
synced 2025-06-21 21:32:40 +02:00
Compare commits
No commits in common. "master" and "v20231028" have entirely different histories.
@ -74,15 +74,15 @@ int main(void)
|
||||
|
||||
size_t num_channels = 1;
|
||||
size_t samplerate = 48000;
|
||||
size_t max_samples = samplerate/20;//each wavebuf can hold upto 1sec/20 = 50ms of audio data
|
||||
size_t max_samples = samplerate;
|
||||
size_t max_samples_datasize = max_samples*num_channels*sizeof(opus_int16);
|
||||
size_t mempool_size = (max_samples_datasize*4 + 0xFFF) &~ 0xFFF;//*4 for 4 wavebufs.
|
||||
size_t mempool_size = (max_samples_datasize*2 + 0xFFF) &~ 0xFFF;//*2 for 2 wavebufs.
|
||||
void* mempool_ptr = memalign(0x1000, mempool_size);
|
||||
void* tmpdata_ptr = malloc(max_samples_datasize);
|
||||
opuspkt_tmpbuf = (u8*)malloc(opuspkt_tmpbuf_size);
|
||||
opus_int16* curbuf = NULL;
|
||||
|
||||
AudioDriverWaveBuf wavebuf[4] = {0};
|
||||
AudioDriverWaveBuf wavebuf[2] = {0};
|
||||
int i, wavei;
|
||||
|
||||
HwopusDecoder hwdecoder = {0};
|
||||
@ -151,9 +151,9 @@ int main(void)
|
||||
}
|
||||
audrvVoiceStart(&drv, 0);
|
||||
|
||||
for(i=0; i<4; i++) {
|
||||
for(i=0; i<2; i++) {
|
||||
wavebuf[i].data_raw = mempool_ptr;
|
||||
wavebuf[i].size = max_samples_datasize*4;//*4 for 4 wavebufs.
|
||||
wavebuf[i].size = max_samples_datasize*2;//*2 for 2 wavebufs.
|
||||
wavebuf[i].start_sample_offset = i * max_samples;
|
||||
wavebuf[i].end_sample_offset = wavebuf[i].start_sample_offset + max_samples;
|
||||
}
|
||||
@ -198,7 +198,7 @@ int main(void)
|
||||
|
||||
if (audio_playing) {
|
||||
wavei = -1;
|
||||
for(i=0; i<4; i++) {
|
||||
for(i=0; i<2; i++) {
|
||||
if (wavebuf[i].state == AudioDriverWaveBufState_Free || wavebuf[i].state == AudioDriverWaveBufState_Done) {
|
||||
wavei = i;
|
||||
break;
|
||||
@ -206,7 +206,7 @@ int main(void)
|
||||
}
|
||||
|
||||
if (wavei >= 0) {
|
||||
curbuf = (opus_int16*)(mempool_ptr + wavebuf[wavei].start_sample_offset * sizeof(opus_int16));
|
||||
curbuf = (opus_int16*)(mempool_ptr + wavebuf[wavei].start_sample_offset);
|
||||
|
||||
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)
|
||||
|
@ -100,7 +100,7 @@ int main(int argc, char** argv) {
|
||||
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_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
|
||||
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_SOFTWARE);
|
||||
|
||||
// load logos from file
|
||||
SDL_Surface *sdllogo = IMG_Load("data/sdl.png");
|
||||
|
@ -28,12 +28,17 @@ int main(int argc, char* argv[])
|
||||
PadState pad;
|
||||
padInitializeDefault(&pad);
|
||||
|
||||
printf("Press PLUS to exit.\n");
|
||||
|
||||
// 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.
|
||||
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.
|
||||
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.freq_low = 10.0f;
|
||||
@ -50,14 +55,6 @@ int main(int argc, char* argv[])
|
||||
// Main loop
|
||||
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
|
||||
padUpdate(&pad);
|
||||
|
||||
@ -70,18 +67,6 @@ int main(int argc, char* argv[])
|
||||
//Select which devices to vibrate.
|
||||
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))
|
||||
{
|
||||
//Calling hidSendVibrationValue/hidSendVibrationValues is really only needed when sending new VibrationValue(s).
|
||||
@ -92,6 +77,11 @@ int main(int argc, char* argv[])
|
||||
|
||||
rc2 = hidSendVibrationValues(VibrationDeviceHandles[target_device], VibrationValues, 2);
|
||||
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.
|
||||
{
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
#include <switch.h>
|
||||
|
||||
const char* const chargers[4] = {"None", "Full Power", "Low Power", "Unsupported"};
|
||||
const char* const chargers[3] = {"None", "Official", "Generic"};
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
@ -166,8 +166,7 @@
|
||||
"type": "debug_flags",
|
||||
"value": {
|
||||
"allow_debug": false,
|
||||
"force_debug": true,
|
||||
"force_debug_prod": false
|
||||
"force_debug": true
|
||||
}
|
||||
}]
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <switch.h>
|
||||
@ -21,7 +20,6 @@ int main(int argc, char **argv)
|
||||
padInitializeDefault(&pad);
|
||||
|
||||
printf("\x1b[16;16HPress PLUS to exit.");
|
||||
printf("\x1b[17;16HTZ=%s\n", getenv("TZ"));
|
||||
|
||||
// Main loop
|
||||
while(appletMainLoop())
|
||||
@ -36,7 +34,7 @@ int main(int argc, char **argv)
|
||||
|
||||
//Print current time
|
||||
time_t unixTime = time(NULL);
|
||||
struct tm* timeStruct = localtime((const time_t *)&unixTime); // Gets local time. If you want UTC use gmtime().
|
||||
struct tm* timeStruct = gmtime((const time_t *)&unixTime);//Gets UTC time. If you want local-time use localtime().
|
||||
|
||||
int hours = timeStruct->tm_hour;
|
||||
int minutes = timeStruct->tm_min;
|
||||
|
Loading…
Reference in New Issue
Block a user