Skip to content

Latest commit

 

History

History
181 lines (152 loc) · 5.47 KB

SDL_pspaudio.c

File metadata and controls

181 lines (152 loc) · 5.47 KB
 
1
2
/*
Simple DirectMedia Layer
Jan 3, 2018
Jan 3, 2018
3
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_AUDIO_DRIVER_PSP
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <malloc.h>
#include "SDL_audio.h"
#include "SDL_error.h"
#include "SDL_timer.h"
#include "../SDL_audio_c.h"
#include "../SDL_audiodev_c.h"
#include "../SDL_sysaudio.h"
#include "SDL_pspaudio.h"
#include <pspaudio.h>
#include <pspthreadman.h>
/* The tag name used by PSP audio */
Aug 12, 2016
Aug 12, 2016
42
#define PSPAUDIO_DRIVER_NAME "psp"
Aug 12, 2016
Aug 12, 2016
45
PSPAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
46
47
48
49
50
51
52
{
int format, mixlen, i;
this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc(sizeof(*this->hidden));
if (this->hidden == NULL) {
return SDL_OutOfMemory();
}
Aug 5, 2016
Aug 5, 2016
53
SDL_zerop(this->hidden);
54
55
56
57
58
59
60
61
62
63
64
65
66
67
switch (this->spec.format & 0xff) {
case 8:
case 16:
this->spec.format = AUDIO_S16LSB;
break;
default:
return SDL_SetError("Unsupported audio format");
}
/* The sample count must be a multiple of 64. */
this->spec.samples = PSP_AUDIO_SAMPLE_ALIGN(this->spec.samples);
this->spec.freq = 44100;
/* Update the fragment size as size in bytes. */
Jan 27, 2016
Jan 27, 2016
68
SDL_CalculateAudioSpec(&this->spec);
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/* Allocate the mixing buffer. Its size and starting address must
be a multiple of 64 bytes. Our sample count is already a multiple of
64, so spec->size should be a multiple of 64 as well. */
mixlen = this->spec.size * NUM_BUFFERS;
this->hidden->rawbuf = (Uint8 *) memalign(64, mixlen);
if (this->hidden->rawbuf == NULL) {
return SDL_SetError("Couldn't allocate mixing buffer");
}
/* Setup the hardware channel. */
if (this->spec.channels == 1) {
format = PSP_AUDIO_FORMAT_MONO;
} else {
Aug 4, 2017
Aug 4, 2017
83
this->spec.channels = 2;
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
format = PSP_AUDIO_FORMAT_STEREO;
}
this->hidden->channel = sceAudioChReserve(PSP_AUDIO_NEXT_CHANNEL, this->spec.samples, format);
if (this->hidden->channel < 0) {
free(this->hidden->rawbuf);
this->hidden->rawbuf = NULL;
return SDL_SetError("Couldn't reserve hardware channel");
}
memset(this->hidden->rawbuf, 0, mixlen);
for (i = 0; i < NUM_BUFFERS; i++) {
this->hidden->mixbufs[i] = &this->hidden->rawbuf[i * this->spec.size];
}
this->hidden->next_buffer = 0;
return 0;
}
Aug 12, 2016
Aug 12, 2016
102
static void PSPAUDIO_PlayDevice(_THIS)
103
104
105
106
107
108
109
110
111
112
113
114
115
{
Uint8 *mixbuf = this->hidden->mixbufs[this->hidden->next_buffer];
if (this->spec.channels == 1) {
sceAudioOutputBlocking(this->hidden->channel, PSP_AUDIO_VOLUME_MAX, mixbuf);
} else {
sceAudioOutputPannedBlocking(this->hidden->channel, PSP_AUDIO_VOLUME_MAX, PSP_AUDIO_VOLUME_MAX, mixbuf);
}
this->hidden->next_buffer = (this->hidden->next_buffer + 1) % NUM_BUFFERS;
}
/* This function waits until it is possible to write a full sound buffer */
Aug 12, 2016
Aug 12, 2016
116
static void PSPAUDIO_WaitDevice(_THIS)
117
118
119
{
/* Because we block when sending audio, there's no need for this function to do anything. */
}
Aug 12, 2016
Aug 12, 2016
120
static Uint8 *PSPAUDIO_GetDeviceBuf(_THIS)
121
122
123
124
{
return this->hidden->mixbufs[this->hidden->next_buffer];
}
Aug 12, 2016
Aug 12, 2016
125
static void PSPAUDIO_CloseDevice(_THIS)
126
127
128
129
{
if (this->hidden->channel >= 0) {
sceAudioChRelease(this->hidden->channel);
}
Aug 5, 2016
Aug 5, 2016
130
131
free(this->hidden->rawbuf); /* this uses memalign(), not SDL_malloc(). */
SDL_free(this->hidden);
Aug 5, 2016
Aug 5, 2016
133
Aug 12, 2016
Aug 12, 2016
134
static void PSPAUDIO_ThreadInit(_THIS)
135
136
137
138
139
140
141
142
143
144
145
146
147
148
{
/* Increase the priority of this audio thread by 1 to put it
ahead of other SDL threads. */
SceUID thid;
SceKernelThreadInfo status;
thid = sceKernelGetThreadId();
status.size = sizeof(SceKernelThreadInfo);
if (sceKernelReferThreadStatus(thid, &status) == 0) {
sceKernelChangeThreadPriority(thid, status.currentPriority - 1);
}
}
static int
Aug 12, 2016
Aug 12, 2016
149
PSPAUDIO_Init(SDL_AudioDriverImpl * impl)
150
151
{
/* Set the function pointers */
Aug 12, 2016
Aug 12, 2016
152
153
154
155
156
157
impl->OpenDevice = PSPAUDIO_OpenDevice;
impl->PlayDevice = PSPAUDIO_PlayDevice;
impl->WaitDevice = PSPAUDIO_WaitDevice;
impl->GetDeviceBuf = PSPAUDIO_GetDeviceBuf;
impl->CloseDevice = PSPAUDIO_CloseDevice;
impl->ThreadInit = PSPAUDIO_ThreadInit;
158
159
160
161
162
163
/* PSP audio device */
impl->OnlyHasDefaultOutputDevice = 1;
/*
impl->HasCaptureSupport = 1;
Aug 5, 2016
Aug 5, 2016
164
impl->OnlyHasDefaultCaptureDevice = 1;
165
166
167
168
169
170
171
172
*/
/*
impl->DetectDevices = DSOUND_DetectDevices;
impl->Deinitialize = DSOUND_Deinitialize;
*/
return 1; /* this audio target is available. */
}
Aug 12, 2016
Aug 12, 2016
173
174
AudioBootStrap PSPAUDIO_bootstrap = {
"psp", "PSP audio driver", PSPAUDIO_Init, 0
175
176
177
178
179
180
181
};
/* SDL_AUDI */
#endif /* SDL_AUDIO_DRIVER_PSP */
/* vi: set ts=4 sw=4 expandtab: */