* Fix PSP compilation.
This commit is contained in:
jean.chalard
2009-01-04 08:19:36 +00:00
parent e69f5f3363
commit a85b6f69e8
2 changed files with 229 additions and 229 deletions
+1 -1
View File
@@ -15,7 +15,7 @@ GENERIC_OBJS = src/JApp.o src/JGBKFont.o \
src/tinyxml/tinyxmlparser.o src/tinyxml/tinyxmlerror.o \ src/tinyxml/tinyxmlparser.o src/tinyxml/tinyxmlerror.o \
src/Encoding.o src/JTTFont.o \ src/Encoding.o src/JTTFont.o \
src/JMD2Model.o src/JOBJModel.o src/vram.o src/JMD2Model.o src/JOBJModel.o src/vram.o
PSP_OBJS = src/JGfx.o src/JSfx.o src/main.o PSP_OBJS = src/JGfx.o src/JSfx.o src/JAudio.o src/JMP3.o src/decoder_prx.o src/main.o
LINUX_OBJS = src/linux/JGfx.o src/linux/JSfx.o src/Xmain.o LINUX_OBJS = src/linux/JGfx.o src/linux/JSfx.o src/Xmain.o
+228 -228
View File
@@ -3,231 +3,231 @@
#include <stdio.h> #include <stdio.h>
#include <pspaudio.h> #include <pspaudio.h>
#include <pspmp3.h> #include <pspmp3.h>
#include <psputility.h> #include <psputility.h>
#include "../include/JAudio.h" #include "../include/JAudio.h"
#include "../include/JFileSystem.h" #include "../include/JFileSystem.h"
#include "../include/JMP3.h" #include "../include/JMP3.h"
JMP3* JMP3::mInstance = NULL; JMP3* JMP3::mInstance = NULL;
void JMP3::init() { void JMP3::init() {
loadModules(); loadModules();
} }
JMP3::JMP3(const std::string& filename, int inBufferSize, int outBufferSize) : JMP3::JMP3(const std::string& filename, int inBufferSize, int outBufferSize) :
m_volume(PSP_AUDIO_VOLUME_MAX), m_paused(true), m_samplesPlayed(0) { m_volume(PSP_AUDIO_VOLUME_MAX), m_samplesPlayed(0), m_paused(true) {
load(filename, inBufferSize,outBufferSize); load(filename, inBufferSize,outBufferSize);
} }
JMP3::~JMP3() { JMP3::~JMP3() {
unload(); unload();
} }
bool JMP3::loadModules() { bool JMP3::loadModules() {
int loadAvCodec = sceUtilityLoadModule(PSP_MODULE_AV_AVCODEC); int loadAvCodec = sceUtilityLoadModule(PSP_MODULE_AV_AVCODEC);
if (loadAvCodec < 0) { if (loadAvCodec < 0) {
return false; return false;
} }
int loadMp3 = sceUtilityLoadModule(PSP_MODULE_AV_MP3); int loadMp3 = sceUtilityLoadModule(PSP_MODULE_AV_MP3);
if (loadMp3 < 0) { if (loadMp3 < 0) {
return false; return false;
} }
return true; return true;
} }
bool JMP3::fillBuffers() { bool JMP3::fillBuffers() {
SceUChar8* dest; SceUChar8* dest;
SceInt32 length; SceInt32 length;
SceInt32 pos; SceInt32 pos;
int ret = sceMp3GetInfoToAddStreamData(m_mp3Handle, &dest, &length, &pos); int ret = sceMp3GetInfoToAddStreamData(m_mp3Handle, &dest, &length, &pos);
if (ret < 0) if (ret < 0)
return false; return false;
if (sceIoLseek32(m_fileHandle, pos, SEEK_SET) < 0) { if (sceIoLseek32(m_fileHandle, pos, SEEK_SET) < 0) {
return false; return false;
} }
int readLength = sceIoRead(m_fileHandle, dest, length); int readLength = sceIoRead(m_fileHandle, dest, length);
if (readLength < 0) if (readLength < 0)
return false; return false;
ret = sceMp3NotifyAddStreamData(m_mp3Handle, readLength); ret = sceMp3NotifyAddStreamData(m_mp3Handle, readLength);
if (ret < 0) if (ret < 0)
return false; return false;
return true; return true;
} }
bool JMP3::load(const std::string& filename, int inBufferSize, int outBufferSize) { bool JMP3::load(const std::string& filename, int inBufferSize, int outBufferSize) {
printf("load\n"); printf("load\n");
m_inBufferSize = inBufferSize; m_inBufferSize = inBufferSize;
printf("1\n"); printf("1\n");
//m_inBuffer = new char[m_inBufferSize]; //m_inBuffer = new char[m_inBufferSize];
//if (!m_inBuffer) //if (!m_inBuffer)
// return false; // return false;
m_outBufferSize = outBufferSize; m_outBufferSize = outBufferSize;
printf("2\n"); printf("2\n");
//m_outBuffer = new short[outBufferSize]; //m_outBuffer = new short[outBufferSize];
//if (!m_outBuffer) //if (!m_outBuffer)
// return false; // return false;
printf("3:%s\n",filename.c_str()); printf("3:%s\n",filename.c_str());
m_fileHandle = sceIoOpen(filename.c_str(), PSP_O_RDONLY, 0777); m_fileHandle = sceIoOpen(filename.c_str(), PSP_O_RDONLY, 0777);
if (m_fileHandle < 0) if (m_fileHandle < 0)
return false; return false;
printf("4\n"); printf("4\n");
int ret = sceMp3InitResource(); int ret = sceMp3InitResource();
if (ret < 0) if (ret < 0)
return false; return false;
SceMp3InitArg initArgs; SceMp3InitArg initArgs;
int fileSize = sceIoLseek32(m_fileHandle, 0, SEEK_END); int fileSize = sceIoLseek32(m_fileHandle, 0, SEEK_END);
sceIoLseek32(m_fileHandle, 0, SEEK_SET); sceIoLseek32(m_fileHandle, 0, SEEK_SET);
unsigned char* testbuffer = new unsigned char[7456]; unsigned char* testbuffer = new unsigned char[7456];
sceIoRead(m_fileHandle, testbuffer, 7456); sceIoRead(m_fileHandle, testbuffer, 7456);
delete testbuffer; delete testbuffer;
initArgs.unk1 = 0; initArgs.unk1 = 0;
initArgs.unk2 = 0; initArgs.unk2 = 0;
initArgs.mp3StreamStart = 0; initArgs.mp3StreamStart = 0;
initArgs.mp3StreamEnd = fileSize; initArgs.mp3StreamEnd = fileSize;
initArgs.mp3BufSize = m_inBufferSize; initArgs.mp3BufSize = m_inBufferSize;
initArgs.mp3Buf = (SceVoid*) m_inBuffer; initArgs.mp3Buf = (SceVoid*) m_inBuffer;
initArgs.pcmBufSize = m_outBufferSize; initArgs.pcmBufSize = m_outBufferSize;
initArgs.pcmBuf = (SceVoid*) m_outBuffer; initArgs.pcmBuf = (SceVoid*) m_outBuffer;
printf("5\n"); printf("5\n");
m_mp3Handle = sceMp3ReserveMp3Handle(&initArgs); m_mp3Handle = sceMp3ReserveMp3Handle(&initArgs);
if (m_mp3Handle < 0) if (m_mp3Handle < 0)
return false; return false;
// Alright we are all set up, let's fill the first buffer. // Alright we are all set up, let's fill the first buffer.
printf("5.5\n"); printf("5.5\n");
bool _filled= fillBuffers(); bool _filled= fillBuffers();
if (! _filled) return false; if (! _filled) return false;
printf("end = %i, bufsize = %i, outSize = %i\n", fileSize, m_inBufferSize, m_outBufferSize); printf("end = %i, bufsize = %i, outSize = %i\n", fileSize, m_inBufferSize, m_outBufferSize);
// Start this bitch up! // Start this bitch up!
printf("6\n"); printf("6\n");
int start = sceMp3Init(m_mp3Handle); int start = sceMp3Init(m_mp3Handle);
if (start < 0) if (start < 0)
return false; return false;
printf("7\n"); printf("7\n");
m_numChannels = sceMp3GetMp3ChannelNum(m_mp3Handle); m_numChannels = sceMp3GetMp3ChannelNum(m_mp3Handle);
printf("8\n"); printf("8\n");
m_samplingRate = sceMp3GetSamplingRate(m_mp3Handle); m_samplingRate = sceMp3GetSamplingRate(m_mp3Handle);
return true; return true;
} }
bool JMP3::unload() { bool JMP3::unload() {
printf("unload 1\n"); printf("unload 1\n");
if (m_channel >= 0) if (m_channel >= 0)
sceAudioSRCChRelease(); sceAudioSRCChRelease();
printf("unload 2\n"); printf("unload 2\n");
sceMp3ReleaseMp3Handle(m_mp3Handle); sceMp3ReleaseMp3Handle(m_mp3Handle);
printf("unload 3\n"); printf("unload 3\n");
sceMp3TermResource(); sceMp3TermResource();
printf("unload 4\n"); printf("unload 4\n");
sceIoClose(m_fileHandle); sceIoClose(m_fileHandle);
printf("unload 5\n"); printf("unload 5\n");
//delete[] m_inBuffer; //delete[] m_inBuffer;
printf("unload 6\n"); printf("unload 6\n");
//delete[] m_outBuffer; //delete[] m_outBuffer;
printf("unload 7\n"); printf("unload 7\n");
return true; return true;
} }
bool JMP3::update() { bool JMP3::update() {
if (!m_paused) { if (!m_paused) {
if (sceMp3CheckStreamDataNeeded(m_mp3Handle) > 0) { if (sceMp3CheckStreamDataNeeded(m_mp3Handle) > 0) {
fillBuffers(); fillBuffers();
} }
short* tempBuffer; short* tempBuffer;
int numDecoded = 0; int numDecoded = 0;
while (true) { while (true) {
numDecoded = sceMp3Decode(m_mp3Handle, &tempBuffer); numDecoded = sceMp3Decode(m_mp3Handle, &tempBuffer);
if (numDecoded > 0) if (numDecoded > 0)
break; break;
int ret = sceMp3CheckStreamDataNeeded(m_mp3Handle); int ret = sceMp3CheckStreamDataNeeded(m_mp3Handle);
if (ret <= 0) if (ret <= 0)
break; break;
fillBuffers(); fillBuffers();
} }
// Okay, let's see if we can't get something outputted :/ // Okay, let's see if we can't get something outputted :/
if (numDecoded == 0 || numDecoded == 0x80671402) { if (numDecoded == 0 || ((unsigned)numDecoded == 0x80671402)) {
sceMp3ResetPlayPosition(m_mp3Handle); sceMp3ResetPlayPosition(m_mp3Handle);
if (!m_loop) if (!m_loop)
m_paused = true; m_paused = true;
m_samplesPlayed = 0; m_samplesPlayed = 0;
} else { } else {
if (m_channel < 0 || m_lastDecoded != numDecoded) { if (m_channel < 0 || m_lastDecoded != numDecoded) {
if (m_channel >= 0) if (m_channel >= 0)
sceAudioSRCChRelease(); sceAudioSRCChRelease();
m_channel = sceAudioSRCChReserve(numDecoded / (2 * m_numChannels), m_samplingRate, m_numChannels); m_channel = sceAudioSRCChReserve(numDecoded / (2 * m_numChannels), m_samplingRate, m_numChannels);
} }
// Output // Output
m_samplesPlayed += sceAudioSRCOutputBlocking(m_volume, tempBuffer); m_samplesPlayed += sceAudioSRCOutputBlocking(m_volume, tempBuffer);
m_playTime = (m_samplingRate > 0) ? (m_samplesPlayed / m_samplingRate) : 0; m_playTime = (m_samplingRate > 0) ? (m_samplesPlayed / m_samplingRate) : 0;
} }
} }
return true; return true;
} }
bool JMP3::play() { bool JMP3::play() {
return (m_paused = false); return (m_paused = false);
} }
bool JMP3::pause() { bool JMP3::pause() {
return (m_paused = true); return (m_paused = true);
} }
bool JMP3::setLoop(bool loop) { bool JMP3::setLoop(bool loop) {
sceMp3SetLoopNum(m_mp3Handle, (loop == true) ? -1 : 0); sceMp3SetLoopNum(m_mp3Handle, (loop == true) ? -1 : 0);
return (m_loop = loop); return (m_loop = loop);
} }
int JMP3::setVolume(int volume) { int JMP3::setVolume(int volume) {
return (m_volume = volume); return (m_volume = volume);
} }
int JMP3::playTime() const { int JMP3::playTime() const {
return m_playTime; return m_playTime;
} }
int JMP3::playTimeMinutes() { int JMP3::playTimeMinutes() {
return m_playTime / 60; return m_playTime / 60;
} }
int JMP3::playTimeSeconds() { int JMP3::playTimeSeconds() {
return m_playTime % 60; return m_playTime % 60;
} }