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 #pragma once
19 
20 #include <queue>
21 
22 #include "CommonTypes.h"
23 #include "sceKernel.h"
24 
25 class PointerWrap;
26 
27 enum PspAudioFormats { PSP_AUDIO_FORMAT_STEREO = 0, PSP_AUDIO_FORMAT_MONO = 0x10 };
28 enum PspAudioFrequencies { PSP_AUDIO_FREQ_44K = 44100, PSP_AUDIO_FREQ_48K = 48000 };
29 
30 #define SCE_ERROR_AUDIO_CHANNEL_NOT_INIT                        0x80260001
31 #define SCE_ERROR_AUDIO_CHANNEL_BUSY                            0x80260002
32 #define SCE_ERROR_AUDIO_INVALID_CHANNEL                         0x80260003
33 #define SCE_ERROR_AUDIO_PRIV_REQUIRED                           0x80260004
34 #define SCE_ERROR_AUDIO_NO_CHANNELS_AVAILABLE                   0x80260005
35 #define SCE_ERROR_AUDIO_OUTPUT_SAMPLE_DATA_SIZE_NOT_ALIGNED     0x80260006
36 #define SCE_ERROR_AUDIO_INVALID_FORMAT                          0x80260007
37 #define SCE_ERROR_AUDIO_CHANNEL_NOT_RESERVED                    0x80260008
38 #define SCE_ERROR_AUDIO_NOT_OUTPUT                              0x80260009
39 #define SCE_ERROR_AUDIO_INVALID_FREQUENCY                       0x8026000A
40 #define SCE_ERROR_AUDIO_INVALID_VOLUME                          0x8026000B
41 #define SCE_ERROR_AUDIO_CHANNEL_ALREADY_RESERVED                0x80268002
42 
43 
44 const u32 PSP_AUDIO_CHANNEL_MAX = 8;
45 
46 const int PSP_AUDIO_CHANNEL_SRC = 8;
47 const int PSP_AUDIO_CHANNEL_OUTPUT2 = 8;
48 const int PSP_AUDIO_CHANNEL_VAUDIO = 8;
49 
50 struct AudioChannelWaitInfo {
51 	SceUID threadID;
52 	int numSamples;
53 };
54 
55 struct AudioChannel {
56 	int index = 0;
57 	bool reserved = false;
58 
59 	// last sample address
60 	u32 sampleAddress = 0;
61 	u32 sampleCount = 0;  // Number of samples written in each OutputBlocking
62 	u32 leftVolume = 0;
63 	u32 rightVolume = 0;
64 	u32 format = 0;
65 
66 	std::vector<AudioChannelWaitInfo> waitingThreads;
67 
68 	void DoState(PointerWrap &p);
69 
70 	void reset();
71 	void clear();
72 };
73 
74 // The extra channel is for SRC/Output2/Vaudio (who all share, apparently.)
75 extern AudioChannel chans[PSP_AUDIO_CHANNEL_MAX + 1];
76 
77 void Register_sceAudio();
78 
79