Merge pull request #956 from Nekotekina/master

cellAudio fixes, Linux fixes
This commit is contained in:
B1ackDaemon 2015-01-10 21:32:02 +02:00
commit afe221c29d
8 changed files with 165 additions and 99 deletions

View File

@ -370,8 +370,8 @@ void signal_handler(int sig, siginfo_t* info, void* uct)
}
}
// else some fatal error (not sure what will happen)
//exit(EXIT_FAILURE);
// else some fatal error
exit(EXIT_FAILURE);
}
const int sigaction_result = []() -> int

View File

@ -23,7 +23,7 @@
#define HLE_CALL_DEBUG
#endif
static u64 rotate_mask[64][64];
extern u64 rotate_mask[64][64]; // defined in PPUThread.cpp, static didn't work correctly in GCC 4.9 for some reason
inline void InitRotateMask()
{
static bool inited = false;

View File

@ -13,6 +13,8 @@
//#include "Emu/Cell/PPURecompiler.h"
#include "Emu/CPU/CPUThreadManager.h"
u64 rotate_mask[64][64];
PPUThread& GetCurrentPPUThread()
{
PPCThread* thread = GetCurrentPPCThread();

View File

@ -1,6 +1,8 @@
#include "stdafx.h"
#include "Utilities/Log.h"
#include "Emu/Memory/Memory.h"
#include "Emu/System.h"
#include "Emu/SysCalls/Callback.h"
#include "Emu/Cell/RawSPUThread.h"
@ -137,8 +139,14 @@ bool RawSPUThread::Write32(const u64 addr, const u32 value)
{
if (value == SPU_RUNCNTL_RUNNABLE)
{
SPU.Status.SetValue(SPU_STATUS_RUNNING);
Exec();
// calling Exec() directly in SIGSEGV handler may cause problems
// (probably because Exec() creates new thread, faults of this thread aren't handled by this handler anymore)
Emu.GetCallbackManager().Async([this]()
{
SPU.Status.SetValue(SPU_STATUS_RUNNING);
Exec();
});
}
else if (value == SPU_RUNCNTL_STOP)
{

View File

@ -10,7 +10,8 @@
std::vector<std::string> simplify_path_blocks(const std::string& path)
{
std::vector<std::string> path_blocks = std::move(fmt::split(fmt::tolower(path), { "/", "\\" }));
// fmt::tolower() removed
std::vector<std::string> path_blocks = std::move(fmt::split(path, { "/", "\\" }));
for (size_t i = 0; i < path_blocks.size(); ++i)
{
@ -28,7 +29,7 @@ std::vector<std::string> simplify_path_blocks(const std::string& path)
return path_blocks;
}
std::string simplify_path(const std::string& path, bool is_dir)
std::string simplify_path(const std::string& path, bool is_dir, bool is_ps3)
{
std::vector<std::string> path_blocks = simplify_path_blocks(path);
@ -36,8 +37,17 @@ std::string simplify_path(const std::string& path, bool is_dir)
return "";
std::string result = fmt::merge(path_blocks, "/");
#ifdef _WIN32
if (is_ps3)
#endif
{
result = "/" + result;
}
return is_dir ? result + "/" : result;
if (is_dir) result = result + "/";
return result;
}
VFS::~VFS()
@ -47,11 +57,11 @@ VFS::~VFS()
void VFS::Mount(const std::string& ps3_path, const std::string& local_path, vfsDevice* device)
{
std::string simpl_ps3_path = simplify_path(ps3_path, true);
std::string simpl_ps3_path = simplify_path(ps3_path, true, true);
UnMount(simpl_ps3_path);
device->SetPath(simpl_ps3_path, simplify_path(local_path, true));
device->SetPath(simpl_ps3_path, simplify_path(local_path, true, false));
m_devices.push_back(device);
if (m_devices.size() > 1)
@ -65,9 +75,9 @@ void VFS::Link(const std::string& mount_point, const std::string& ps3_path)
links[simplify_path_blocks(mount_point)] = simplify_path_blocks(ps3_path);
}
std::string VFS::GetLinked(std::string ps3_path) const
std::string VFS::GetLinked(const std::string& ps3_path) const
{
ps3_path = fmt::tolower(ps3_path);
// fmt::tolower removed
auto path_blocks = fmt::split(ps3_path, { "/", "\\" });
for (auto link : links)
@ -95,7 +105,7 @@ std::string VFS::GetLinked(std::string ps3_path) const
void VFS::UnMount(const std::string& ps3_path)
{
std::string simpl_ps3_path = simplify_path(ps3_path, true);
std::string simpl_ps3_path = simplify_path(ps3_path, true, true);
for (u32 i = 0; i < m_devices.size(); ++i)
{
@ -320,18 +330,21 @@ vfsDevice* VFS::GetDevice(const std::string& ps3_path, std::string& path) const
path += "/" + ps3_path_blocks[i];
}
path = simplify_path(path, false);
path = simplify_path(path, false, false);
return m_devices[max_i];
};
if (auto res = try_get_device(GetLinked(ps3_path)))
return res;
if (!ps3_path.size() || ps3_path[0] != '/')
{
return nullptr;
}
if (auto res = try_get_device(GetLinked(cwd + ps3_path)))
return res;
return try_get_device(GetLinked(ps3_path));
return nullptr;
// What is it? cwd is real path, ps3_path is ps3 path, but GetLinked accepts ps3 path
//if (auto res = try_get_device(GetLinked(cwd + ps3_path)))
// return res;
}
vfsDevice* VFS::GetDeviceLocal(const std::string& local_path, std::string& path) const
@ -374,14 +387,14 @@ vfsDevice* VFS::GetDeviceLocal(const std::string& local_path, std::string& path)
path += "/" + local_path_blocks[i];
}
path = simplify_path(path, false);
path = simplify_path(path, false, true);
return m_devices[max_i];
}
void VFS::Init(const std::string& path)
{
cwd = simplify_path(path, true);
cwd = simplify_path(path, true, false);
UnMountAll();

View File

@ -44,7 +44,7 @@ struct VFSManagerEntry
};
std::vector<std::string> simplify_path_blocks(const std::string& path);
std::string simplify_path(const std::string& path, bool is_dir);
std::string simplify_path(const std::string& path, bool is_dir, bool is_ps3);
struct VFS
{
@ -74,7 +74,7 @@ struct VFS
void UnMount(const std::string& ps3_path);
void UnMountAll();
std::string GetLinked(std::string ps3_path) const;
std::string GetLinked(const std::string& ps3_path) const;
vfsFileBase* OpenFile(const std::string& ps3_path, vfsOpenMode mode) const;
vfsDirBase* OpenDir(const std::string& ps3_path) const;

View File

@ -29,7 +29,7 @@ bool vfsDir::Open(const std::string& path)
DirEntryInfo info;
m_cwd = simplify_path(Emu.GetVFS().GetLinked(0 && m_stream && m_stream->IsOpened() ? m_stream->GetPath() : path), true);
m_cwd = simplify_path(Emu.GetVFS().GetLinked(0 && m_stream && m_stream->IsOpened() ? m_stream->GetPath() : path), true, true);
auto blocks = simplify_path_blocks(GetPath());

View File

@ -864,115 +864,151 @@ int cellAudioRemoveNotifyEventQueueEx(u64 key, u32 iFlags)
return CELL_OK;
}
int cellAudioAddData(u32 portNum, vm::ptr<float> src, u32 samples, float volume)
s32 cellAudioAddData(u32 portNum, vm::ptr<float> src, u32 samples, float volume)
{
cellAudio->Warning("cellAudioAddData(portNum=0x%x, src_addr=0x%x, samples=%d, volume=%f)", portNum, src.addr(), samples, volume);
cellAudio->Log("cellAudioAddData(portNum=%d, src_addr=0x%x, samples=%d, volume=%f)", portNum, src.addr(), samples, volume);
if (src.addr() % 16)
return CELL_AUDIO_ERROR_PARAM;
if (!m_config.m_is_audio_initialized)
{
return CELL_AUDIO_ERROR_NOT_INIT;
}
AudioPortConfig& port = m_config.m_ports[portNum];
if (portNum >= m_config.AUDIO_PORT_COUNT)
if (portNum >= m_config.AUDIO_PORT_COUNT || !src || src.addr() % 4)
{
return CELL_AUDIO_ERROR_PARAM;
}
if (!port.m_is_audio_port_opened)
if (samples != 256)
{
return CELL_AUDIO_ERROR_PORT_NOT_OPEN;
// despite the docs, seems that only fixed value is supported
cellAudio->Error("cellAudioAddData(): invalid samples value (0x%x)", samples);
return CELL_AUDIO_ERROR_PARAM;
}
if (!port.m_is_audio_port_started)
{
return CELL_AUDIO_ERROR_PORT_NOT_RUN;
}
std::lock_guard<std::mutex> lock(audioMutex);
const AudioPortConfig& port = m_config.m_ports[portNum];
u32 addr = port.addr;
u32 src_addr = src.addr();
const auto dst = vm::ptr<float>::make(port.addr + (port.tag % port.block) * port.channel * 256 * sizeof(float));
for (u32 i = 0; i < samples; i++)
for (u32 i = 0; i < samples * port.channel; i++)
{
// vm::write32(addr, (u32)((float)vm::read32(src_addr) * volume)); // TODO: use volume?
vm::write32(addr, vm::read32(src_addr));
src_addr += (port.size / samples);
addr += (port.size / samples);
dst[i] += src[i] * volume; // mix all channels
}
return CELL_OK;
}
int cellAudioAdd2chData(u32 portNum, vm::ptr<float> src, u32 samples, float volume)
s32 cellAudioAdd2chData(u32 portNum, vm::ptr<float> src, u32 samples, float volume)
{
cellAudio->Warning("cellAudioAdd2chData(portNum=0x%x, src_addr=0x%x, samples=%d, volume=%f)", portNum, src.addr(), samples, volume);
AudioPortConfig& port = m_config.m_ports[portNum];
cellAudio->Log("cellAudioAdd2chData(portNum=%d, src_addr=0x%x, samples=%d, volume=%f)", portNum, src.addr(), samples, volume);
if (!m_config.m_is_audio_initialized)
{
return CELL_AUDIO_ERROR_NOT_INIT;
}
if (portNum >= m_config.AUDIO_PORT_COUNT)
{
return CELL_AUDIO_ERROR_PARAM;
}
if (!port.m_is_audio_port_opened)
if (portNum >= m_config.AUDIO_PORT_COUNT || !src || src.addr() % 4)
{
return CELL_AUDIO_ERROR_PORT_NOT_OPEN;
return CELL_AUDIO_ERROR_PARAM;
}
if (!port.m_is_audio_port_started)
if (samples != 256)
{
return CELL_AUDIO_ERROR_PORT_NOT_RUN;
// despite the docs, seems that only fixed value is supported
cellAudio->Error("cellAudioAdd2chData(): invalid samples value (0x%x)", samples);
return CELL_AUDIO_ERROR_PARAM;
}
std::lock_guard<std::mutex> lock(audioMutex);
const AudioPortConfig& port = m_config.m_ports[portNum];
u32 addr = port.addr;
u32 src_addr = src.addr();
const auto dst = vm::ptr<float>::make(port.addr + (port.tag % port.block) * port.channel * 256 * sizeof(float));
for (u32 i = 0; i < samples; i++)
if (port.channel == 2)
{
// vm::write32(addr, (u32)((float)vm::read32(src_addr) * volume)); // TODO: use volume?
vm::write32(addr, vm::read32(src_addr));
src_addr += (2 * port.block * 256 * sizeof(float) / samples);
addr += (2 * port.block * 256 * sizeof(float) / samples);
cellAudio->Error("cellAudioAdd2chData(portNum=%d): port.channel = 2", portNum);
}
else if (port.channel == 6)
{
for (u32 i = 0; i < samples; i++)
{
dst[i * 6 + 0] += src[i * 2 + 0] * volume; // mix L ch
dst[i * 6 + 1] += src[i * 2 + 1] * volume; // mix R ch
//dst[i * 6 + 2] += 0.0f; // center
//dst[i * 6 + 3] += 0.0f; // LFE
//dst[i * 6 + 4] += 0.0f; // rear L
//dst[i * 6 + 5] += 0.0f; // rear R
}
}
else if (port.channel == 8)
{
for (u32 i = 0; i < samples; i++)
{
dst[i * 8 + 0] += src[i * 2 + 0] * volume; // mix L ch
dst[i * 8 + 1] += src[i * 2 + 1] * volume; // mix R ch
//dst[i * 8 + 2] += 0.0f; // center
//dst[i * 8 + 3] += 0.0f; // LFE
//dst[i * 8 + 4] += 0.0f; // rear L
//dst[i * 8 + 5] += 0.0f; // rear R
//dst[i * 8 + 6] += 0.0f; // side L
//dst[i * 8 + 7] += 0.0f; // side R
}
}
else
{
cellAudio->Error("cellAudioAdd2chData(portNum=%d): invalid port.channel value (%d)", portNum, port.channel);
}
return CELL_OK;
}
int cellAudioAdd6chData(u32 portNum, vm::ptr<float> src, float volume)
s32 cellAudioAdd6chData(u32 portNum, vm::ptr<float> src, float volume)
{
cellAudio->Warning("cellAudioAdd6chData(portNum=0x%x, src_addr=0x%x, volume=%f)", portNum, src.addr(), volume);
AudioPortConfig& port = m_config.m_ports[portNum];
cellAudio->Log("cellAudioAdd6chData(portNum=%d, src_addr=0x%x, volume=%f)", portNum, src.addr(), volume);
if (!m_config.m_is_audio_initialized)
{
return CELL_AUDIO_ERROR_NOT_INIT;
}
if (portNum >= m_config.AUDIO_PORT_COUNT)
{
return CELL_AUDIO_ERROR_PARAM;
}
if (!port.m_is_audio_port_opened)
if (portNum >= m_config.AUDIO_PORT_COUNT || !src || src.addr() % 4)
{
return CELL_AUDIO_ERROR_PORT_NOT_OPEN;
return CELL_AUDIO_ERROR_PARAM;
}
const AudioPortConfig& port = m_config.m_ports[portNum];
if (!port.m_is_audio_port_started)
const auto dst = vm::ptr<float>::make(port.addr + (port.tag % port.block) * port.channel * 256 * sizeof(float));
if (port.channel == 2 || port.channel == 6)
{
return CELL_AUDIO_ERROR_PORT_NOT_RUN;
cellAudio->Error("cellAudioAdd2chData(portNum=%d): port.channel = %d", portNum, port.channel);
}
std::lock_guard<std::mutex> lock(audioMutex);
u32 addr = port.addr;
u32 src_addr = src.addr();
for (u32 i = 0; i < 256; i++)
else if (port.channel == 8)
{
// vm::write32(addr, (u32)((float)vm::read32(src_addr) * volume)); // TODO: use volume?
vm::write32(addr, vm::read32(src_addr));
src_addr += (6 * port.block * sizeof(float));
addr += (6 * port.block * sizeof(float));
for (u32 i = 0; i < 256; i++)
{
dst[i * 8 + 0] += src[i * 6 + 0] * volume; // mix L ch
dst[i * 8 + 1] += src[i * 6 + 1] * volume; // mix R ch
dst[i * 8 + 2] += src[i * 6 + 2] * volume; // mix center
dst[i * 8 + 3] += src[i * 6 + 3] * volume; // mix LFE
dst[i * 8 + 4] += src[i * 6 + 4] * volume; // mix rear L
dst[i * 8 + 5] += src[i * 6 + 5] * volume; // mix rear R
//dst[i * 8 + 6] += 0.0f; // side L
//dst[i * 8 + 7] += 0.0f; // side R
}
}
else
{
cellAudio->Error("cellAudioAdd6chData(portNum=%d): invalid port.channel value (%d)", portNum, port.channel);
}
return CELL_OK;
@ -1006,20 +1042,27 @@ void cellAudio_init(Module *pxThis)
{
cellAudio = pxThis;
cellAudio->AddFunc(0x0b168f92, cellAudioInit);
cellAudio->AddFunc(0x4129fe2d, cellAudioPortClose);
cellAudio->AddFunc(0x5b1e2c73, cellAudioPortStop);
cellAudio->AddFunc(0x74a66af0, cellAudioGetPortConfig);
cellAudio->AddFunc(0x89be28f2, cellAudioPortStart);
cellAudio->AddFunc(0xca5ac370, cellAudioQuit);
cellAudio->AddFunc(0xcd7bc431, cellAudioPortOpen);
cellAudio->AddFunc(0x56dfe179, cellAudioSetPortLevel);
cellAudio->AddFunc(0x04af134e, cellAudioCreateNotifyEventQueue);
cellAudio->AddFunc(0x31211f6b, cellAudioMiscSetAccessoryVolume);
cellAudio->AddFunc(0x377e0cd9, cellAudioSetNotifyEventQueue);
cellAudio->AddFunc(0x4109d08c, cellAudioGetPortTimestamp);
cellAudio->AddFunc(0x9e4b1db8, cellAudioAdd2chData);
cellAudio->AddFunc(0xdab029aa, cellAudioAddData);
cellAudio->AddFunc(0xe4046afe, cellAudioGetPortBlockTag);
cellAudio->AddFunc(0xff3626fd, cellAudioRemoveNotifyEventQueue);
REG_FUNC(cellAudio, cellAudioInit);
REG_FUNC(cellAudio, cellAudioPortClose);
REG_FUNC(cellAudio, cellAudioPortStop);
REG_FUNC(cellAudio, cellAudioGetPortConfig);
REG_FUNC(cellAudio, cellAudioPortStart);
REG_FUNC(cellAudio, cellAudioQuit);
REG_FUNC(cellAudio, cellAudioPortOpen);
REG_FUNC(cellAudio, cellAudioSetPortLevel);
REG_FUNC(cellAudio, cellAudioCreateNotifyEventQueue);
REG_FUNC(cellAudio, cellAudioCreateNotifyEventQueueEx);
REG_FUNC(cellAudio, cellAudioMiscSetAccessoryVolume);
REG_FUNC(cellAudio, cellAudioSetNotifyEventQueue);
REG_FUNC(cellAudio, cellAudioSetNotifyEventQueueEx);
REG_FUNC(cellAudio, cellAudioGetPortTimestamp);
REG_FUNC(cellAudio, cellAudioAdd2chData);
REG_FUNC(cellAudio, cellAudioAdd6chData);
REG_FUNC(cellAudio, cellAudioAddData);
REG_FUNC(cellAudio, cellAudioGetPortBlockTag);
REG_FUNC(cellAudio, cellAudioRemoveNotifyEventQueue);
REG_FUNC(cellAudio, cellAudioRemoveNotifyEventQueueEx);
REG_FUNC(cellAudio, cellAudioSendAck);
REG_FUNC(cellAudio, cellAudioSetPersonalDevice);
REG_FUNC(cellAudio, cellAudioUnsetPersonalDevice);
}