fix audio, relax logs

vita
AAGaming 7 months ago
parent ceed705662
commit 19955e8226
Signed by: aa
GPG Key ID: 3050166AC290BDF5

@ -58,9 +58,18 @@ static void chiaki_opus_decoder_header(ChiakiAudioHeader *header, void *user)
CHIAKI_LOGI(decoder->log, "ChiakiOpusDecoder initialized");
size_t pcm_buf_size_required = chiaki_audio_header_frame_buf_size(header);
#ifdef __PSVITA__
// Vita only works with buffer sizes that are a multiple of 64
pcm_buf_size_required = 512 * header->channels * sizeof(int16_t);
#endif
int16_t *pcm_buf_old = decoder->pcm_buf;
if(!decoder->pcm_buf || decoder->pcm_buf_size != pcm_buf_size_required)
if(!decoder->pcm_buf || decoder->pcm_buf_size != pcm_buf_size_required) {
decoder->pcm_buf = realloc(decoder->pcm_buf, pcm_buf_size_required);
#ifdef __PSVITA__
// remove garbage data because we have to overallocate the buffer on Vita
memset(decoder->pcm_buf, 0, pcm_buf_size_required);
#endif
}
if(!decoder->pcm_buf)
{

@ -4,6 +4,7 @@
#include "context.h"
#define FRAME_SIZE 240
static int pcmBufferSize = 480*2*sizeof(int16_t);
int port = -1;
int decode_offset = 0;
int audioRate = 0;
@ -12,38 +13,41 @@ void vita_audio_init(unsigned int channels, unsigned int rate, void *user) {
if (port == -1) {
LOGD("vita audio init with %d channels at %dHz", channels, rate);
audioRate = rate;
port = sceAudioOutOpenPort(SCE_AUDIO_OUT_PORT_TYPE_MAIN, 480, rate, channels == 2 ? SCE_AUDIO_OUT_PARAM_FORMAT_S16_STEREO : SCE_AUDIO_OUT_PARAM_FORMAT_S16_MONO);
sceAudioOutSetVolume(port, SCE_AUDIO_VOLUME_FLAG_L_CH | SCE_AUDIO_VOLUME_FLAG_R_CH, (int[]){SCE_AUDIO_VOLUME_0DB,SCE_AUDIO_VOLUME_0DB});
port = sceAudioOutOpenPort(SCE_AUDIO_OUT_PORT_TYPE_MAIN, 512/*(pcmBufferSize/channels/sizeof(int16_t))*/, rate, channels == 2 ? SCE_AUDIO_OUT_PARAM_FORMAT_S16_STEREO : SCE_AUDIO_OUT_PARAM_FORMAT_S16_MONO);
if (port < 0) {
LOGD("AUDIO STARTUP ERROR 0x%x", port);
return;
}
sceAudioOutSetVolume(port, SCE_AUDIO_VOLUME_FLAG_L_CH | SCE_AUDIO_VOLUME_FLAG_R_CH, (int[]){SCE_AUDIO_VOLUME_0DB,SCE_AUDIO_VOLUME_0DB});
}
}
void vita_audio_cb(int16_t *buf, size_t samples_count) {
for(int x = 0; x < samples_count * 2; x++) {
// boost audio volume
int sample = buf[x] * 1.80;
// Hard clipping (audio compression)
// truncate value that overflow/underflow int16
if(sample > INT16_MAX) {
buf[x] = INT16_MAX;
LOGD("Audio Hard clipping INT16_MAX < %d", sample);
}
else if(sample < INT16_MIN) {
buf[x] = INT16_MIN;
LOGD("Audio Hard clipping INT16_MIN > %d", sample);
}
else
buf[x] = (int16_t)sample;
}
// for(int x = 0; x < samples_count * 2; x++) {
// // boost audio volume
// int sample = buf[x] * 1.80;
// // Hard clipping (audio compression)
// // truncate value that overflow/underflow int16
// if(sample > INT16_MAX) {
// buf[x] = INT16_MAX;
// LOGD("Audio Hard clipping INT16_MAX < %d", sample);
// }
// else if(sample < INT16_MIN) {
// buf[x] = INT16_MIN;
// LOGD("Audio Hard clipping INT16_MIN > %d", sample);
// }
// else
// buf[x] = (int16_t)sample;
// }
// if (samples_count > 0) {
LOGD("samples %d", samples_count);
// if (samples_count != FRAME_SIZE)
// return;
// decode_offset += samples_count;
// if (decode_offset == audioRate) {
// decode_offset = 0;
sceAudioOutOutput(port, NULL);
// sceAudioOutOutput(port, NULL);
sceAudioOutOutput(port, buf);
// }
// }

@ -37,10 +37,10 @@ bool vita_chiaki_init_context() {
context.config.auto_discovery = true;
context.config.disconnect_action = DISCONNECT_ACTION_ASK;
context.config.resolution = CHIAKI_VIDEO_RESOLUTION_PRESET_540p;
context.config.fps = CHIAKI_VIDEO_FPS_PRESET_30;
context.config.fps = CHIAKI_VIDEO_FPS_PRESET_60;
// TODO: Load log level from config
// TODO: Custom logging callback that logs to a file
chiaki_log_init(&(context.log), CHIAKI_LOG_ALL, &log_cb_debugnet, NULL);
chiaki_log_init(&(context.log), CHIAKI_LOG_ALL & ~(CHIAKI_LOG_VERBOSE | CHIAKI_LOG_DEBUG), &log_cb_debugnet, NULL);
return true;
}
Loading…
Cancel
Save