~ppsspp/ppsspp/ppsspp-sdl-1.2.2

« back to all changes in this revision

Viewing changes to Core/HLE/sceVaudio.cpp

  • Committer: Sérgio Benjamim
  • Date: 2016-04-25 03:32:37 UTC
  • Revision ID: sergio_br2@yahoo.com.br-20160425033237-776ndjdvs3r5xuzd
1.2.2 source (for SDL).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) 2012- PPSSPP Project.
 
2
 
 
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.
 
6
 
 
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.
 
11
 
 
12
// A copy of the GPL 2.0 should have been included with the program.
 
13
// If not, see http://www.gnu.org/licenses/
 
14
 
 
15
// Official git repository and contact information can be found at
 
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
 
17
 
 
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"
 
25
 
 
26
// Ultra hacky Vaudio implementation. Not sure what the point of this API is.
 
27
 
 
28
bool vaudioReserved = false;
 
29
 
 
30
void __VaudioInit() {
 
31
        vaudioReserved = false;
 
32
}
 
33
 
 
34
void __VaudioDoState(PointerWrap &p) {
 
35
        auto s = p.Section("sceVaudio", 1);
 
36
        if (!s)
 
37
                return;
 
38
 
 
39
        p.Do(vaudioReserved);
 
40
}
 
41
 
 
42
static u32 sceVaudioChReserve(int sampleCount, int freq, int format) {
 
43
        if (vaudioReserved) {
 
44
                ERROR_LOG(SCEAUDIO, "sceVaudioChReserve(%i, %i, %i) - already reserved", sampleCount, freq, format);
 
45
                return SCE_KERNEL_ERROR_BUSY;
 
46
        }
 
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;
 
51
        }
 
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);
 
60
        return 0;
 
61
}
 
62
 
 
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;
 
67
        } else {
 
68
                chans[PSP_AUDIO_CHANNEL_VAUDIO].reset();
 
69
                chans[PSP_AUDIO_CHANNEL_VAUDIO].reserved = false;
 
70
                vaudioReserved = false;
 
71
                return 0;
 
72
        }
 
73
}
 
74
 
 
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);
 
82
}
 
83
 
 
84
static u32 sceVaudioSetEffectType(int effectType, int vol) {
 
85
        ERROR_LOG_REPORT(SCEAUDIO, "UNIMPL sceVaudioSetEffectType(%i, %i)", effectType, vol);
 
86
        return 0;
 
87
}
 
88
 
 
89
static u32 sceVaudioSetAlcMode(int alcMode) {
 
90
        ERROR_LOG_REPORT(SCEAUDIO, "UNIMPL sceVaudioSetAlcMode(%i)", alcMode);
 
91
        return 0;
 
92
}
 
93
 
 
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",          '?', ""   },
 
103
};
 
104
 
 
105
void Register_sceVaudio() {
 
106
        RegisterModule("sceVaudio",ARRAY_SIZE(sceVaudio), sceVaudio );
 
107
}