zenilib: zenilib/jni/external/sdl/src/audio/psp/SDL_pspaudio.c Source File

zenilib 0.5.3.0

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SDL_pspaudio.c
Go to the documentation of this file.
1 /*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20 */
21
22 #include <stdio.h>
23 #include <string.h>
24 #include <stdlib.h>
25 #include <malloc.h>
26
27 #include "SDL_audio.h"
28 #include "SDL_error.h"
29 #include "SDL_timer.h"
30 #include "../SDL_audiomem.h"
31 #include "../SDL_audio_c.h"
32 #include "../SDL_audiodev_c.h"
33 #include "../SDL_sysaudio.h"
34 #include "SDL_pspaudio.h"
35
36 #include <pspaudio.h>
37 #include <pspthreadman.h>
38
39 /* The tag name used by PSP audio */
40 #define PSPAUD_DRIVER_NAME "psp"
41
42 static int
43 PSPAUD_OpenDevice(_THIS, const char *devname, int iscapture)
44 {
45 int format, mixlen, i;
46 this->hidden = (struct SDL_PrivateAudioData *)
47 SDL_malloc(sizeof(*this->hidden));
48 if (this->hidden == NULL) {
49 return SDL_OutOfMemory();
50 }
51 SDL_memset(this->hidden, 0, sizeof(*this->hidden));
52 switch (this->spec.format & 0xff) {
53 case 8:
54 case 16:
55 this->spec.format = AUDIO_S16LSB;
56 break;
57 default:
58 return SDL_SetError("Unsupported audio format");
59 }
60
61 /* The sample count must be a multiple of 64. */
62 this->spec.samples = PSP_AUDIO_SAMPLE_ALIGN(this->spec.samples);
63 this->spec.freq = 44100;
64
65 /* Update the fragment size as size in bytes. */
66 /* SDL_CalculateAudioSpec(this->spec); MOD */
67 switch (this->spec.format) {
68 case AUDIO_U8:
69 this->spec.silence = 0x80;
70 break;
71 default:
72 this->spec.silence = 0x00;
73 break;
74 }
75 this->spec.size = SDL_AUDIO_BITSIZE(this->spec.format) / 8;
76 this->spec.size *= this->spec.channels;
77 this->spec.size *= this->spec.samples;
78
79 /* ========================================== */
80
81 /* Allocate the mixing buffer. Its size and starting address must
82 be a multiple of 64 bytes. Our sample count is already a multiple of
83 64, so spec->size should be a multiple of 64 as well. */
84 mixlen = this->spec.size * NUM_BUFFERS;
85 this->hidden->rawbuf = (Uint8 *) memalign(64, mixlen);
86 if (this->hidden->rawbuf == NULL) {
87 return SDL_SetError("Couldn't allocate mixing buffer");
88 }
89
90 /* Setup the hardware channel. */
91 if (this->spec.channels == 1) {
92 format = PSP_AUDIO_FORMAT_MONO;
93 } else {
94 format = PSP_AUDIO_FORMAT_STEREO;
95 }
96 this->hidden->channel = sceAudioChReserve(PSP_AUDIO_NEXT_CHANNEL, this->spec.samples, format);
97 if (this->hidden->channel < 0) {
98 free(this->hidden->rawbuf);
99 this->hidden->rawbuf = NULL;
100 return SDL_SetError("Couldn't reserve hardware channel");
101 }
102
103 memset(this->hidden->rawbuf, 0, mixlen);
104 for (i = 0; i < NUM_BUFFERS; i++) {
105 this->hidden->mixbufs[i] = &this->hidden->rawbuf[i * this->spec.size];
106 }
107
108 this->hidden->next_buffer = 0;
109 return 0;
110 }
111
112 static void PSPAUD_PlayDevice(_THIS)
113 {
114 Uint8 *mixbuf = this->hidden->mixbufs[this->hidden->next_buffer];
115
116 if (this->spec.channels == 1) {
117 sceAudioOutputBlocking(this->hidden->channel, PSP_AUDIO_VOLUME_MAX, mixbuf);
118 } else {
119 sceAudioOutputPannedBlocking(this->hidden->channel, PSP_AUDIO_VOLUME_MAX, PSP_AUDIO_VOLUME_MAX, mixbuf);
120 }
121
122 this->hidden->next_buffer = (this->hidden->next_buffer + 1) % NUM_BUFFERS;
123 }
124
125 /* This function waits until it is possible to write a full sound buffer */
126 static void PSPAUD_WaitDevice(_THIS)
127 {
128 /* Because we block when sending audio, there's no need for this function to do anything. */
129 }
130 static Uint8 *PSPAUD_GetDeviceBuf(_THIS)
131 {
132 return this->hidden->mixbufs[this->hidden->next_buffer];
133 }
134
135 static void PSPAUD_CloseDevice(_THIS)
136 {
137 if (this->hidden->channel >= 0) {
138 sceAudioChRelease(this->hidden->channel);
139 this->hidden->channel = -1;
140 }
141
142 if (this->hidden->rawbuf != NULL) {
143 free(this->hidden->rawbuf);
144 this->hidden->rawbuf = NULL;
145 }
146 }
147 static void PSPAUD_ThreadInit(_THIS)
148 {
149 /* Increase the priority of this audio thread by 1 to put it
150 ahead of other SDL threads. */
151 SceUID thid;
152 SceKernelThreadInfo status;
153 thid = sceKernelGetThreadId();
154 status.size = sizeof(SceKernelThreadInfo);
155 if (sceKernelReferThreadStatus(thid, &status) == 0) {
156 sceKernelChangeThreadPriority(thid, status.currentPriority - 1);
157 }
158 }
159
160
161 static int
162 PSPAUD_Init(SDL_AudioDriverImpl * impl)
163 {
164
165 /* Set the function pointers */
166 impl->OpenDevice = PSPAUD_OpenDevice;
167 impl->PlayDevice = PSPAUD_PlayDevice;
168 impl->WaitDevice = PSPAUD_WaitDevice;
169 impl->GetDeviceBuf = PSPAUD_GetDeviceBuf;
170 impl->WaitDone = PSPAUD_WaitDevice;
171 impl->CloseDevice = PSPAUD_CloseDevice;
172 impl->ThreadInit = PSPAUD_ThreadInit;
173
174 /* PSP audio device */
175 impl->OnlyHasDefaultOutputDevice = 1;
176 /*
177 impl->HasCaptureSupport = 1;
178
179 impl->OnlyHasDefaultInputDevice = 1;
180 */
181 /*
182 impl->DetectDevices = DSOUND_DetectDevices;
183 impl->Deinitialize = DSOUND_Deinitialize;
184 */
185 return 1; /* this audio target is available. */
186 }
187
188 AudioBootStrap PSPAUD_bootstrap = {
189 "psp", "PSP audio driver", PSPAUD_Init, 0
190 };
191
192 /* SDL_AUDI */
193
194
195
PSPAUD_PlayDevice
static void PSPAUD_PlayDevice(_THIS)
Definition: SDL_pspaudio.c:112
SDL_AudioDriverImpl::CloseDevice
void(* CloseDevice)(_THIS)
Definition: SDL_sysaudio.h:45
NUM_BUFFERS
#define NUM_BUFFERS
Definition: alstream.c:48
PSPAUD_bootstrap
AudioBootStrap PSPAUD_bootstrap
Definition: SDL_pspaudio.c:188
SDL_AudioDriverImpl::WaitDevice
void(* WaitDevice)(_THIS)
Definition: SDL_sysaudio.h:41
NULL
#define NULL
Definition: ftobjs.h:61
PSPAUD_ThreadInit
static void PSPAUD_ThreadInit(_THIS)
Definition: SDL_pspaudio.c:147
SDL_AudioDriverImpl::GetDeviceBuf
Uint8 *(* GetDeviceBuf)(_THIS)
Definition: SDL_sysaudio.h:43
free
SDL_EventEntry * free
Definition: SDL_events.c:80
SDL_pspaudio.h
memset
#define memset
Definition: SDL_malloc.c:633
SDL_AudioDriverImpl::WaitDone
void(* WaitDone)(_THIS)
Definition: SDL_sysaudio.h:44
SDL_AudioDriverImpl::OpenDevice
int(* OpenDevice)(_THIS, const char *devname, int iscapture)
Definition: SDL_sysaudio.h:39
SDL_PrivateAudioData
Definition: SDL_alsa_audio.h:33
PSPAUD_CloseDevice
static void PSPAUD_CloseDevice(_THIS)
Definition: SDL_pspaudio.c:135
PSPAUD_OpenDevice
static int PSPAUD_OpenDevice(_THIS, const char *devname, int iscapture)
Definition: SDL_pspaudio.c:43
SDL_AudioDriverImpl::PlayDevice
void(* PlayDevice)(_THIS)
Definition: SDL_sysaudio.h:42
AUDIO_U8
#define AUDIO_U8
Definition: SDL_audio.h:89
PSPAUD_Init
static int PSPAUD_Init(SDL_AudioDriverImpl *impl)
Definition: SDL_pspaudio.c:162
AudioBootStrap
Definition: SDL_sysaudio.h:128
SDL_AudioDriverImpl::OnlyHasDefaultOutputDevice
int OnlyHasDefaultOutputDevice
Definition: SDL_sysaudio.h:56
_THIS
#define _THIS
Definition: SDL_alsa_audio.h:31
SDL_AUDIO_BITSIZE
#define SDL_AUDIO_BITSIZE(x)
Definition: SDL_audio.h:75
SDL_AudioDriverImpl
Definition: SDL_sysaudio.h:36
SDL_memset
DECLSPEC void *SDLCALL SDL_memset(void *dst, int c, size_t len)
Definition: SDL_string.c:261
format
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl2ext.h:845
SDL_SetError
DECLSPEC int SDLCALL SDL_SetError(const char *fmt,...)
Definition: SDL_error.c:53
SDL_malloc
DECLSPEC void *SDLCALL SDL_malloc(size_t size)
PSPAUD_WaitDevice
static void PSPAUD_WaitDevice(_THIS)
Definition: SDL_pspaudio.c:126
SDL_OutOfMemory
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
SDL_AudioDriverImpl::ThreadInit
void(* ThreadInit)(_THIS)
Definition: SDL_sysaudio.h:40
SDL_audio.h
Uint8
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:129
AUDIO_S16LSB
#define AUDIO_S16LSB
Definition: SDL_audio.h:92
String.h
PSPAUD_GetDeviceBuf
static Uint8 * PSPAUD_GetDeviceBuf(_THIS)
Definition: SDL_pspaudio.c:130
SDL_PrivateAudioData::mixbuf
Uint8 * mixbuf
Definition: SDL_alsa_audio.h:39
i
int i
Definition: pngrutil.c:1377
SDL_timer.h
SDL_error.h