Skip to content

Commit

Permalink
Implemented sceMeBootStart500, sceMpegBasePESpacketCopy,
Browse files Browse the repository at this point in the history
sceAudioSetFrequency500.
Added support for AAC and MP3 codecs in sceAudiocodecInit and
sceAudiocodecDecode.
  • Loading branch information
gid15 committed Apr 20, 2015
1 parent 5c90f1b commit 34dc015
Show file tree
Hide file tree
Showing 15 changed files with 366 additions and 94 deletions.
4 changes: 4 additions & 0 deletions src/jpcsp/HLE/Modules.java
Expand Up @@ -52,9 +52,11 @@
import jpcsp.HLE.modules.sceImpose;
import jpcsp.HLE.modules.sceJpeg;
import jpcsp.HLE.modules.sceMd5;
import jpcsp.HLE.modules.sceMeCore_driver;
import jpcsp.HLE.modules.sceMp3;
import jpcsp.HLE.modules.sceMp4;
import jpcsp.HLE.modules.sceMpeg;
import jpcsp.HLE.modules.sceMpegbase;
import jpcsp.HLE.modules.sceMt19937;
import jpcsp.HLE.modules.sceNet;
import jpcsp.HLE.modules.sceNetAdhoc;
Expand Down Expand Up @@ -119,6 +121,7 @@ public class Modules {
public static Kernel_Library Kernel_LibraryModule = new Kernel_Library();
public static ModuleMgrForUser ModuleMgrForUserModule = new ModuleMgrForUser();
public static sceMpeg sceMpegModule = new sceMpeg();
public static sceMpegbase sceMpegbaseModule = new sceMpegbase();
public static LoadCoreForKernel LoadCoreForKernelModule = new LoadCoreForKernel();
public static sceAtrac3plus sceAtrac3plusModule = new sceAtrac3plus();
public static sceAudio sceAudioModule = new sceAudio();
Expand Down Expand Up @@ -175,6 +178,7 @@ public class Modules {
public static sceAdler sceAdlerModule = new sceAdler();
public static sceSha1 sceSha1Module = new sceSha1();
public static sceSha256 sceSha256Module = new sceSha256();
public static sceMeCore_driver sceMeCore_driverModule = new sceMeCore_driver();

public static Logger log = Logger.getLogger("hle");

Expand Down
5 changes: 0 additions & 5 deletions src/jpcsp/HLE/SyscallIgnore.java
Expand Up @@ -67,11 +67,6 @@ public enum SyscallIgnore {
sceKernelSetIntrLevel(0xB5A15B30),
sceKernelSetPrimarySyscallHandler(0x0FC68A56),
sceKernelSuspendIntr(0x750E2507),
sceMpegAvcCopyYCbCr(0x0558B075),
sceMpegbase_driver_0530BE4E(0x0530BE4E),
sceMpegBaseCscAvc(0x91929A21),
sceMpegBaseCscInit(0x492B5E4B),
sceMpegBasePESpacketCopy(0xBEA18F91),
sceNetApDialogDummyConnect(0x3811281E),
sceNetApDialogDummyGetState(0xCA9BE5BF),
sceNetApDialogDummyInit(0xBB73FF67),
Expand Down
6 changes: 4 additions & 2 deletions src/jpcsp/HLE/modules/HLEModuleManager.java
Expand Up @@ -101,7 +101,8 @@ private enum DefaultModule {
sceHprm(Modules.sceHprmModule), // check if loaded by default
sceAtrac3plus(Modules.sceAtrac3plusModule, new String[] { "libatrac3plus", "PSP_AV_MODULE_ATRAC3PLUS", "PSP_MODULE_AV_ATRAC3PLUS", "sceATRAC3plus_Library" }),
sceSasCore(Modules.sceSasCoreModule, new String[] { "sc_sascore", "PSP_AV_MODULE_SASCORE", "PSP_MODULE_AV_SASCORE", "sceSAScore" } ),
sceMpeg(Modules.sceMpegModule, new String[] { "mpeg", "mpeg_vsh", "PSP_AV_MODULE_MPEGBASE", "PSP_MODULE_AV_MPEGBASE", "sceMpeg_library" }),
sceMpeg (Modules.sceMpegModule, new String[] { "mpeg", "mpeg_vsh", "mpeg_vsh370", "PSP_AV_MODULE_MPEGBASE", "PSP_MODULE_AV_MPEGBASE", "sceMpeg_library" }),
sceMpegbase(Modules.sceMpegbaseModule, new String[] { "mpeg", "mpeg_vsh", "mpeg_vsh370", "PSP_AV_MODULE_MPEGBASE", "PSP_MODULE_AV_MPEGBASE", "sceMpeg_library" }),
sceFont(Modules.sceFontModule, new String[] { "libfont", "sceFont_Library" }),
scePsmfPlayer(Modules.scePsmfPlayerModule, new String[] { "libpsmfplayer", "psmf_jk", "scePsmfP_library" }),
scePsmf(Modules.scePsmfModule, new String[] { "psmf", "scePsmf_library" }),
Expand Down Expand Up @@ -149,7 +150,8 @@ private enum DefaultModule {
sceAudiocodec(Modules.sceAudiocodecModule, new String[] { "PSP_AV_MODULE_AVCODEC", "PSP_MODULE_AV_AVCODEC", "avcodec" }),
sceAdler(Modules.sceAdlerModule, new String[] { "libadler" }),
sceSha1(Modules.sceSha1Module, new String[] { "libsha1" }),
sceSha256(Modules.sceSha256Module, new String[] { "libsha256" });
sceSha256(Modules.sceSha256Module, new String[] { "libsha256" }),
sceMeCore_drive(Modules.sceMeCore_driverModule);

private HLEModule module;
private int firmwareVersionAsDefault; // FirmwareVersion where the module is loaded by default
Expand Down
2 changes: 1 addition & 1 deletion src/jpcsp/HLE/modules/sceAudio.java
Expand Up @@ -16,5 +16,5 @@
*/
package jpcsp.HLE.modules;

public class sceAudio extends jpcsp.HLE.modules150.sceAudio {
public class sceAudio extends jpcsp.HLE.modules500.sceAudio {
}
20 changes: 20 additions & 0 deletions src/jpcsp/HLE/modules/sceMeCore_driver.java
@@ -0,0 +1,20 @@
/*
This file is part of jpcsp.
Jpcsp is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Jpcsp is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Jpcsp. If not, see <http://www.gnu.org/licenses/>.
*/
package jpcsp.HLE.modules;

public class sceMeCore_driver extends jpcsp.HLE.modules500.sceMeCore_driver {
}
20 changes: 20 additions & 0 deletions src/jpcsp/HLE/modules/sceMpegbase.java
@@ -0,0 +1,20 @@
/*
This file is part of jpcsp.
Jpcsp is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Jpcsp is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Jpcsp. If not, see <http://www.gnu.org/licenses/>.
*/
package jpcsp.HLE.modules;

public class sceMpegbase extends jpcsp.HLE.modules150.sceMpegbase {
}
36 changes: 10 additions & 26 deletions src/jpcsp/HLE/modules150/sceAtrac3plus.java
Expand Up @@ -46,8 +46,8 @@
import jpcsp.HLE.modules.HLEModule;
import jpcsp.HLE.modules.SysMemUserForUser;
import jpcsp.HLE.modules150.SysMemUserForUser.SysMemInfo;
import jpcsp.HLE.modules150.sceAudiocodec.AudiocodecInfo;
import jpcsp.media.codec.CodecFactory;
import jpcsp.media.codec.ICodec;
import jpcsp.media.codec.atrac3.Atrac3Decoder;
import jpcsp.media.codec.atrac3plus.Atrac3plusDecoder;
import jpcsp.util.Utilities;
Expand Down Expand Up @@ -151,12 +151,10 @@ public static class AtracFileInfo {
public LoopInfo[] loops;
}

public static class AtracID {
public static class AtracID extends AudiocodecInfo {
// Internal info.
private final int id;
protected int codecType;
protected ICodec codec;
protected boolean codecInitialized;
protected boolean inUse;
protected int currentReadPosition;
// Context (used only from firmware 6.00)
Expand Down Expand Up @@ -192,7 +190,8 @@ public AtracID(int id) {
info = new AtracFileInfo();
}

public void release() {
@Override
public void release() {
setInUse(false);
releaseContext();
releaseInternalBuffer();
Expand Down Expand Up @@ -689,26 +688,6 @@ public void setOutputChannels(int outputChannels) {
this.outputChannels = outputChannels;
}

public ICodec getCodec() {
return codec;
}

public void setCodec(ICodec codec) {
this.codec = codec;
}

public boolean isCodecInitialized() {
return codecInitialized;
}

public void setCodecInitialized(boolean codecInitialized) {
this.codecInitialized = codecInitialized;
}

public void setCodecInitialized() {
setCodecInitialized(true);
}

public int getNumberOfSamples() {
return codec.getNumberOfSamples() - skippedSamples;
}
Expand All @@ -721,12 +700,17 @@ public void setInUse(boolean inUse) {
this.inUse = inUse;

if (inUse) {
codec = CodecFactory.getCodec(getCodecType());
initCodec();
} else {
codec = null;
}
}

@Override
public void initCodec() {
codec = CodecFactory.getCodec(getCodecType());
}

@Override
public String toString() {
return String.format("AtracID[id=%d, inputBuffer=%s, channels=%d, outputChannels=%d]", id, inputBuffer, getChannels(), getOutputChannels());
Expand Down
10 changes: 5 additions & 5 deletions src/jpcsp/HLE/modules150/sceAudio.java
Expand Up @@ -508,18 +508,18 @@ public int hleAudioInputBlocking(int maxSamples, int frequency, TPointer buffer)
}

@HLEUnimplemented
@HLEFunction(nid = 0x80F1F7E0, version = 150, moduleName = "sceAudio_driver", checkInsideInterrupt = true)
@HLEFunction(nid = 0x80F1F7E0, version = 150, checkInsideInterrupt = true)
public int sceAudioInit() {
return 0;
}

@HLEUnimplemented
@HLEFunction(nid = 0x210567F7, version = 150, moduleName = "sceAudio_driver", checkInsideInterrupt = true)
@HLEFunction(nid = 0x210567F7, version = 150, checkInsideInterrupt = true)
public int sceAudioEnd() {
return 0;
}

@HLEFunction(nid = 0xA2BEAA6C, version = 150, moduleName = "sceAudio_driver", checkInsideInterrupt = true)
@HLEFunction(nid = 0xA2BEAA6C, version = 150, checkInsideInterrupt = true)
public int sceAudioSetFrequency(int frequency) {
if (frequency != 44100 && frequency != 48000) {
return SceKernelErrors.ERROR_AUDIO_INVALID_FREQUENCY;
Expand All @@ -533,13 +533,13 @@ public int sceAudioSetFrequency(int frequency) {
}

@HLEUnimplemented
@HLEFunction(nid = 0xB61595C0, version = 150, moduleName = "sceAudio_driver", checkInsideInterrupt = true)
@HLEFunction(nid = 0xB61595C0, version = 150, checkInsideInterrupt = true)
public int sceAudioLoopbackTest() {
return 0;
}

@HLEUnimplemented
@HLEFunction(nid = 0x927AC32B, version = 150, moduleName = "sceAudio_driver", checkInsideInterrupt = true)
@HLEFunction(nid = 0x927AC32B, version = 150, checkInsideInterrupt = true)
public int sceAudioSetVolumeOffset() {
return 0;
}
Expand Down
92 changes: 75 additions & 17 deletions src/jpcsp/HLE/modules150/sceAudiocodec.java
Expand Up @@ -25,7 +25,6 @@
import jpcsp.HLE.TPointer;
import jpcsp.HLE.kernel.types.SceKernelErrors;
import jpcsp.HLE.modules.HLEModule;
import jpcsp.HLE.modules150.sceAtrac3plus.AtracID;
import jpcsp.media.codec.ICodec;
import jpcsp.util.Utilities;

Expand All @@ -38,8 +37,32 @@ public class sceAudiocodec extends HLEModule {
public static final int PSP_CODEC_MP3 = 0x00001002;
public static final int PSP_CODEC_AAC = 0x00001003;

private AtracID id;
private int atID;
public static abstract class AudiocodecInfo {
protected ICodec codec;
protected boolean codecInitialized;

public ICodec getCodec() {
return codec;
}

public boolean isCodecInitialized() {
return codecInitialized;
}

public void setCodecInitialized(boolean codecInitialized) {
this.codecInitialized = codecInitialized;
}

public void setCodecInitialized() {
setCodecInitialized(true);
}

public abstract void release();
public abstract void initCodec();
}

private int id;
private AudiocodecInfo info;
private boolean edramAllocated;

@Override
Expand All @@ -54,7 +77,8 @@ public int getMemoryUsage() {

@Override
public void start() {
id = null;
id = -1;
info = null;
edramAllocated = false;

super.start();
Expand All @@ -69,16 +93,42 @@ public int sceAudiocodecCheckNeedMem(TPointer workArea, int codecType) {
@HLELogging(level = "info")
@HLEFunction(nid = 0x5B37EB1D, version = 150)
public int sceAudiocodecInit(TPointer workArea, int codecType) {
if (id != null) {
Modules.sceAtrac3plusModule.hleReleaseAtracID(atID);
atID = -1;
id = null;
if (info != null) {
info.release();
info = null;
}
atID = Modules.sceAtrac3plusModule.hleGetAtracID(codecType);
if (atID < 0) {
return atID;
id = -1;

switch (codecType) {
case PSP_CODEC_AT3:
case PSP_CODEC_AT3PLUS:
id = Modules.sceAtrac3plusModule.hleGetAtracID(codecType);
if (id < 0) {
return id;
}
info = Modules.sceAtrac3plusModule.getAtracID(id);
break;
case PSP_CODEC_AAC:
Modules.sceAacModule.hleAacInit(1);
id = Modules.sceAacModule.getFreeAacId();
if (id < 0) {
return id;
}
info = Modules.sceAacModule.getAacInfo(id);
info.initCodec();
break;
case PSP_CODEC_MP3:
id = Modules.sceMp3Module.getFreeMp3Id();
if (id < 0) {
return id;
}
info = Modules.sceMp3Module.getMp3Info(id);
info.initCodec();
break;
default:
log.warn(String.format("sceAudiocodecInit unimplemented codecType=0x%X", codecType));
return -1;
}
id = Modules.sceAtrac3plusModule.getAtracID(atID);

return 0;
}
Expand Down Expand Up @@ -159,13 +209,21 @@ public int sceAudiocodecDecode(TPointer workArea, int codecType) {
}
}

ICodec codec = id.getCodec();

if (!id.isCodecInitialized()) {
ICodec codec = info.getCodec();
if (!info.isCodecInitialized()) {
codec.init(inputBufferSize, channels, outputChannels, codingMode);
id.setCodecInitialized();
info.setCodecInitialized();
}
codec.decode(inputBuffer, inputBufferSize, outputBuffer);

if (codec == null) {
log.warn(String.format("sceAudiocodecDecode no codec available for codecType=0x%X", codecType));
return -1;
}

int bytesConsumed = codec.decode(inputBuffer, inputBufferSize, outputBuffer);
if (log.isDebugEnabled()) {
log.debug(String.format("sceAudiocodecDecode bytesConsumed=0x%X", bytesConsumed));
}

workArea.setValue32(28, inputBufferSize);

Expand Down

0 comments on commit 34dc015

Please sign in to comment.