1
// Copyright (c) 2012- PPSSPP Project.
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
18
#include "Common/ChunkFile.h"
19
#include "Core/Reporting.h"
20
#include "Core/HLE/HLE.h"
21
#include "Core/HLE/FunctionWrappers.h"
22
#include "Core/HLE/sceVaudio.h"
23
#include "Core/HLE/sceAudio.h"
24
#include "Core/HLE/__sceAudio.h"
26
// Ultra hacky Vaudio implementation. Not sure what the point of this API is.
28
bool vaudioReserved = false;
31
vaudioReserved = false;
34
void __VaudioDoState(PointerWrap &p) {
35
auto s = p.Section("sceVaudio", 1);
42
static u32 sceVaudioChReserve(int sampleCount, int freq, int format) {
44
ERROR_LOG(SCEAUDIO, "sceVaudioChReserve(%i, %i, %i) - already reserved", sampleCount, freq, format);
45
return SCE_KERNEL_ERROR_BUSY;
47
// We still have to check the channel also, which gives a different error.
48
if (chans[PSP_AUDIO_CHANNEL_VAUDIO].reserved) {
49
ERROR_LOG(SCEAUDIO, "sceVaudioChReserve(%i, %i, %i) - channel already reserved", sampleCount, freq, format);
50
return SCE_ERROR_AUDIO_CHANNEL_ALREADY_RESERVED;
52
DEBUG_LOG(SCEAUDIO, "sceVaudioChReserve(%i, %i, %i)", sampleCount, freq, format);
53
chans[PSP_AUDIO_CHANNEL_VAUDIO].reserved = true;
54
chans[PSP_AUDIO_CHANNEL_VAUDIO].sampleCount = sampleCount;
55
chans[PSP_AUDIO_CHANNEL_VAUDIO].format = format == 2 ? PSP_AUDIO_FORMAT_STEREO : PSP_AUDIO_FORMAT_MONO;
56
chans[PSP_AUDIO_CHANNEL_VAUDIO].leftVolume = 0;
57
chans[PSP_AUDIO_CHANNEL_VAUDIO].rightVolume = 0;
58
vaudioReserved = true;
59
__AudioSetOutputFrequency(freq);
63
static u32 sceVaudioChRelease() {
64
DEBUG_LOG(SCEAUDIO, "sceVaudioChRelease(...)");
65
if (!chans[PSP_AUDIO_CHANNEL_VAUDIO].reserved) {
66
return SCE_ERROR_AUDIO_CHANNEL_NOT_RESERVED;
68
chans[PSP_AUDIO_CHANNEL_VAUDIO].reset();
69
chans[PSP_AUDIO_CHANNEL_VAUDIO].reserved = false;
70
vaudioReserved = false;
75
static u32 sceVaudioOutputBlocking(int vol, u32 buffer) {
76
DEBUG_LOG(SCEAUDIO, "sceVaudioOutputBlocking(%i, %08x)", vol, buffer);
77
chans[PSP_AUDIO_CHANNEL_OUTPUT2].leftVolume = vol;
78
chans[PSP_AUDIO_CHANNEL_OUTPUT2].rightVolume = vol;
79
// TODO: This may be wrong, not sure if's in a different format?
80
chans[PSP_AUDIO_CHANNEL_OUTPUT2].sampleAddress = buffer;
81
return __AudioEnqueue(chans[PSP_AUDIO_CHANNEL_VAUDIO], PSP_AUDIO_CHANNEL_VAUDIO, true);
84
static u32 sceVaudioSetEffectType(int effectType, int vol) {
85
ERROR_LOG_REPORT(SCEAUDIO, "UNIMPL sceVaudioSetEffectType(%i, %i)", effectType, vol);
89
static u32 sceVaudioSetAlcMode(int alcMode) {
90
ERROR_LOG_REPORT(SCEAUDIO, "UNIMPL sceVaudioSetAlcMode(%i)", alcMode);
94
const HLEFunction sceVaudio[] = {
95
{0X8986295E, &WrapU_IU<sceVaudioOutputBlocking>, "sceVaudioOutputBlocking", 'x', "ix" },
96
{0X03B6807D, &WrapU_III<sceVaudioChReserve>, "sceVaudioChReserve", 'x', "iii"},
97
{0X67585DFD, &WrapU_V<sceVaudioChRelease>, "sceVaudioChRelease", 'x', "" },
98
{0X346FBE94, &WrapU_II<sceVaudioSetEffectType>, "sceVaudioSetEffectType", 'x', "ii" },
99
{0XCBD4AC51, &WrapU_I<sceVaudioSetAlcMode>, "sceVaudioSetAlcMode", 'x', "i" },
100
{0X504E4745, nullptr, "sceVaudio_504E4745", '?', "" },
101
{0X27ACC20B, nullptr, "sceVaudioChReserveBuffering", '?', "" },
102
{0XE8E78DC8, nullptr, "sceVaudio_E8E78DC8", '?', "" },
105
void Register_sceVaudio() {
106
RegisterModule("sceVaudio",ARRAY_SIZE(sceVaudio), sceVaudio );