1 /*	MikMod sound library
2 	(c) 1998-2014 Miodrag Vallat and others - see file AUTHORS for
3 	complete list.
4 
5 	This library is free software; you can redistribute it and/or modify
6 	it under the terms of the GNU Library General Public License as
7 	published by the Free Software Foundation; either version 2 of
8 	the License, or (at your option) any later version.
9 
10 	This program is distributed in the hope that it will be useful,
11 	but WITHOUT ANY WARRANTY; without even the implied warranty of
12 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 	GNU Library General Public License for more details.
14 
15 	You should have received a copy of the GNU Library General Public
16 	License along with this library; if not, write to the Free Software
17 	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
18 	02111-1307, USA.
19 */
20 
21 /*==============================================================================
22 
23   drv_psp.c -- output data to PlayStation Portable audio device.
24   by sweetlilmre (12 November 2005, mikmod 3.1.11 port)
25   originally by Jim Shaw (mikmod-3.0.3 port, July 2005, Public Domain)
26 
27 ==============================================================================*/
28 
29 #ifdef HAVE_CONFIG_H
30 #include "config.h"
31 #endif
32 
33 #include "mikmod_internals.h"
34 
35 #ifdef DRV_PSP
36 
37 #include <pspkernel.h>
38 #include <pspaudio.h>
39 #include <pspaudiolib.h>
40 #include <string.h>
41 
42 
43 static int audio_ready = 0;
44 static int audio_handle = -1;
45 static volatile int audio_terminate = 0;
46 static volatile int bufidx = 0;
47 static volatile int playing = 0;
48 
49 static short mikmod_sndbuf[2][PSP_NUM_AUDIO_SAMPLES][2];
50 
51 
PSP_Update(void)52 static void PSP_Update(void)
53 {
54 	if (audio_terminate == 0) {
55 		void *bufptr = &mikmod_sndbuf[bufidx];
56 		if (playing) {
57 			VC_WriteBytes(bufptr, PSP_NUM_AUDIO_SAMPLES*4);
58 		}
59 		else {
60 			memset(bufptr, 0, PSP_NUM_AUDIO_SAMPLES*4);
61 		}
62 		if (audio_ready) {
63 			sceAudioOutputPannedBlocking(audio_handle, PSP_VOLUME_MAX, PSP_VOLUME_MAX, bufptr);
64 		}
65 		bufidx ^= 1;
66 	}
67 }
68 
PSP_IsThere(void)69 static BOOL PSP_IsThere(void)
70 {
71 	return 1;
72 }
73 
PSP_Init(void)74 static int PSP_Init(void)
75 {
76 	if (VC_Init())
77 		return 1;
78 
79 	audio_terminate = 0;
80 	audio_ready = 0;
81 	audio_handle = sceAudioChReserve(-1, PSP_NUM_AUDIO_SAMPLES, 0);
82 	if (audio_handle < 0) {
83 		audio_handle = -1;
84 		_mm_errno = MMERR_OPENING_AUDIO;
85 		return 1;
86 	}
87 
88 	audio_ready = 1;
89 	return 0;
90 }
91 
PSP_Exit(void)92 static void PSP_Exit(void)
93 {
94 	audio_ready = 0;
95 	audio_terminate = 1;
96 	if (audio_handle != -1) {
97 		sceAudioChRelease(audio_handle);
98 		audio_handle = -1;
99 	}
100 
101 	VC_Exit();
102 }
103 
PSP_Reset(void)104 static int PSP_Reset(void)
105 {
106 	VC_Exit();
107 	return VC_Init();
108 }
109 
PSP_PlayStart(void)110 static int PSP_PlayStart(void)
111 {
112 	VC_PlayStart();
113 	playing = 1;
114 	return 0;
115 }
116 
PSP_PlayStop(void)117 static void PSP_PlayStop(void)
118 {
119 	playing = 0;
120 	VC_PlayStop();
121 }
122 
123 MIKMODAPI MDRIVER drv_psp = {
124 	NULL,
125 	"PSP Audio",
126 	"PSP Output Driver v1.1 - by sweetlilmre, original by Jim Shaw",
127 	0,255,
128 	"pspdrv",
129 	NULL,
130 	NULL,
131 
132 	PSP_IsThere,
133 	VC_SampleLoad,
134 	VC_SampleUnload,
135 	VC_SampleSpace,
136 	VC_SampleLength,
137 	PSP_Init,
138 	PSP_Exit,
139 	PSP_Reset,
140 
141 	VC_SetNumVoices,
142 	PSP_PlayStart,
143 	PSP_PlayStop,
144 	PSP_Update,
145 	NULL,
146 
147 	VC_VoiceSetVolume,
148 	VC_VoiceGetVolume,
149 	VC_VoiceSetFrequency,
150 	VC_VoiceGetFrequency,
151 	VC_VoiceSetPanning,
152 	VC_VoiceGetPanning,
153 	VC_VoicePlay,
154 	VC_VoiceStop,
155 	VC_VoiceStopped,
156 	VC_VoiceGetPosition,
157 	VC_VoiceRealVolume
158 };
159 
160 #else
161 
162 MISSING(drv_psp);
163 
164 #endif
165 
166 /* ex:set ts=8: */
167