mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-23 08:44:04 +02:00
Add PS Vita backend.
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
|
||||
if(DEFINED ENV{VITASDK})
|
||||
set(CMAKE_TOOLCHAIN_FILE "$ENV{VITASDK}/share/vita.toolchain.cmake" CACHE PATH "toolchain file")
|
||||
else()
|
||||
message(FATAL_ERROR "Please define VITASDK to point to your SDK path!")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
project(miniaudio_vita)
|
||||
include("${VITASDK}/share/vita.cmake" REQUIRED)
|
||||
|
||||
set(VITA_APP_NAME "miniaudio_vita")
|
||||
set(VITA_TITLEID "MINIAUDIO00001")
|
||||
set(VITA_VERSION "01.00")
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||
|
||||
add_executable(${PROJECT_NAME}
|
||||
miniaudio_vita.c
|
||||
)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
m
|
||||
SceAudio_stub
|
||||
SceDisplay_stub
|
||||
SceCtrl_stub
|
||||
)
|
||||
|
||||
vita_create_self(${PROJECT_NAME}.self ${PROJECT_NAME})
|
||||
vita_create_vpk(${PROJECT_NAME}.vpk ${VITA_TITLEID} ${PROJECT_NAME}.self
|
||||
VERSION ${VITA_VERSION}
|
||||
NAME ${VITA_APP_NAME}
|
||||
)
|
||||
@@ -0,0 +1,114 @@
|
||||
/* Uncomment this and update the path to enable the debug screen. */
|
||||
/*#include "/opt/toolchains/vitasdk/samples/common/debugScreen.c"*/
|
||||
|
||||
#if defined(DEBUG_SCREEN_H)
|
||||
#define HAS_DEBUG_SCREEN
|
||||
#endif
|
||||
|
||||
#ifdef HAS_DEBUG_SCREEN
|
||||
#define printf psvDebugScreenPrintf
|
||||
#endif
|
||||
|
||||
#define MA_DEBUG_OUTPUT
|
||||
#include "../../miniaudio.c"
|
||||
|
||||
#include <psp2/ctrl.h>
|
||||
|
||||
static void data_callback(ma_device* pDevice, void* pFramesOut, const void* pFramesIn, ma_uint32 frameCount)
|
||||
{
|
||||
static int c = 0;
|
||||
|
||||
ma_data_source* pDataSource = (ma_data_source*)ma_device_get_user_data(pDevice);
|
||||
ma_data_source_read_pcm_frames(pDataSource, pFramesOut, frameCount, NULL);
|
||||
|
||||
(void)pFramesIn;
|
||||
(void)pDevice;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
ma_result result;
|
||||
ma_device_config deviceConfig;
|
||||
ma_device device;
|
||||
ma_waveform waveform;
|
||||
ma_decoder decoder;
|
||||
SceCtrlData ctrlPeek, ctrlPress;
|
||||
|
||||
#ifdef HAS_DEBUG_SCREEN
|
||||
psvDebugScreenInit();
|
||||
#endif
|
||||
|
||||
deviceConfig = ma_device_config_init(ma_device_type_playback);
|
||||
//deviceConfig.threadingMode = MA_THREADING_MODE_SINGLE_THREADED;
|
||||
deviceConfig.playback.format = ma_format_s16;
|
||||
deviceConfig.playback.channels = 2;
|
||||
deviceConfig.sampleRate = 48000;
|
||||
deviceConfig.dataCallback = data_callback;
|
||||
deviceConfig.pUserData = &waveform;
|
||||
deviceConfig.periodSizeInFrames = 1024;
|
||||
|
||||
#if 0
|
||||
ma_device_backend_config backend = ma_device_backend_config_init(ma_device_backend_vita, NULL);
|
||||
result = ma_device_init_ex(&backend, 1, NULL, &deviceConfig, &device);
|
||||
#else
|
||||
result = ma_device_init(NULL, &deviceConfig, &device);
|
||||
#endif
|
||||
if (result != MA_SUCCESS) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Initialize the waveform before starting the device. */
|
||||
{
|
||||
ma_waveform_config waveformConfig = ma_waveform_config_init(device.playback.format, device.playback.channels, device.sampleRate, ma_waveform_type_sine, 0.1f, 400);
|
||||
ma_waveform_init(&waveformConfig, &waveform);
|
||||
}
|
||||
|
||||
/* Decoder. */
|
||||
#if 0
|
||||
{
|
||||
ma_decoder_config decoderConfig = ma_decoder_config_init(device.playback.format, device.playback.channels, device.sampleRate);
|
||||
ma_decoder_init_file("test.mp3", &decoderConfig, &decoder);
|
||||
}
|
||||
#endif
|
||||
|
||||
result = ma_device_start(&device);
|
||||
if (result != MA_SUCCESS) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
ctrlPress = ctrlPeek;
|
||||
sceCtrlPeekBufferPositive(0, &ctrlPeek, 1);
|
||||
ctrlPress.buttons = ctrlPeek.buttons & ~ctrlPress.buttons;
|
||||
|
||||
if(ctrlPress.buttons == SCE_CTRL_SQUARE) {
|
||||
if (ma_device_is_started(&device)) {
|
||||
printf("STOPPING\n");
|
||||
ma_device_stop(&device);
|
||||
} else {
|
||||
printf("STARTING\n");
|
||||
ma_device_start(&device);
|
||||
}
|
||||
}
|
||||
|
||||
if(ctrlPress.buttons == SCE_CTRL_CROSS) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (ma_device_get_threading_mode(&device) == MA_THREADING_MODE_SINGLE_THREADED) {
|
||||
ma_device_step(&device, MA_BLOCKING_MODE_NON_BLOCKING);
|
||||
|
||||
/*
|
||||
I found that if I don't relax the CPU a bit I'll get glitching when running in vita3k. Maybe the loop is pinning the CPU
|
||||
at 100% and starving the audio system?
|
||||
*/
|
||||
ma_sleep(1);
|
||||
} else {
|
||||
ma_sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
ma_waveform_uninit(&waveform);
|
||||
ma_device_uninit(&device);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user