Linux+MacOS: a Fix for someone have problems with compiling on a Mac, few fixes for DSP LLE plugin, I don't have files to test though

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@100 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Sonicadvance1 2008-07-29 23:59:21 +00:00
parent c04011f117
commit 99d5b4f4c2
5 changed files with 229 additions and 21 deletions

View File

@ -139,12 +139,12 @@ CGameListCtrl::Update()
Show();
}
#ifdef _WIN32
wxColour blend50(const wxColour& c1, const wxColour& c2)
{
return(((c1.GetPixel() & 0xFEFEFE) >> 1) + ((c2.GetPixel() & 0xFEFEFE) >> 1) + 0x010101);
}
#endif
wxString NiceSizeFormat(s64 _size)
{

View File

@ -0,0 +1,126 @@
#include <ao/ao.h>
#include <pthread.h>
#include "AOSoundStream.h"
namespace AOSound
{
pthread_t thread;
StreamCallback callback;
char *buffer;
int buf_size;
ao_device *device;
ao_sample_format format;
int default_driver;
int bufferSize;
int totalRenderedBytes;
int sampleRate;
volatile int threadData;
int currentPos;
int lastPos;
short realtimeBuffer[1024 * 1024];
int AOSound_GetSampleRate()
{
return sampleRate;
}
bool WriteDataToBuffer(int dwOffset,char* soundData, int dwSoundBytes)
{
//void* ptr1, * ptr2;
//DWORD numBytes1, numBytes2;
// Obtain memory address of write block. This will be in two parts if the block wraps around.
//HRESULT hr = dsBuffer->Lock(dwOffset, dwSoundBytes, &ptr1, &numBytes1, &ptr2, &numBytes2, 0);
// If the buffer was lost, restore and retry lock.
/*if (DSERR_BUFFERLOST == hr)
{
dsBuffer->Restore();
hr = dsBuffer->Lock(dwOffset, dwSoundBytes, &ptr1, &numBytes1, &ptr2, &numBytes2, 0);
}
if (SUCCEEDED(hr))
{
memcpy(ptr1, soundData, numBytes1);
if (ptr2 != 0)
{
memcpy(ptr2, soundData + numBytes1, numBytes2);
}
// Release the data back to DirectSound.
dsBuffer->Unlock(ptr1, numBytes1, ptr2, numBytes2);
return(true);
}
return(false);*/
ao_play(device, soundData, dwSoundBytes);
return true;
}
void* soundThread(void*)
{
currentPos = 0;
lastPos = 0;
// Prefill buffer?
//writeDataToBuffer(0,realtimeBuffer,bufferSize);
// dsBuffer->Lock(0, bufferSize, (void **)&p1, &num1, (void **)&p2, &num2, 0);
//dsBuffer->Play(0, 0, DSBPLAY_LOOPING);
while (!threadData)
{
// No blocking inside the csection
//dsBuffer->GetCurrentPosition((DWORD*)&currentPos, 0);
int numBytesToRender = 256;
if (numBytesToRender >= 256)
{
(*callback)(realtimeBuffer, numBytesToRender >> 2, 16, 44100, 2);
WriteDataToBuffer(0, (char*)realtimeBuffer, numBytesToRender);
//currentPos = ModBufferSize(lastPos + numBytesToRender);
//totalRenderedBytes += numBytesToRender;
//lastPos = currentPos;
}
//WaitForSingleObject(soundSyncEvent, MAXWAIT);
}
//dsBuffer->Stop();
return(0); //hurra!
}
bool AOSound_StartSound(int _sampleRate, StreamCallback _callback)
{
callback = _callback;
threadData = 0;
sampleRate = _sampleRate;
//no security attributes, automatic resetting, init state nonset, untitled
//soundSyncEvent = CreateEvent(0, false, false, 0);
ao_initialize();
default_driver = ao_default_driver_id();
format.bits = 16;
format.channels = 2;
format.rate = sampleRate;
format.byte_format = AO_FMT_LITTLE;
//vi vill ha access till DSOUND så...
device = ao_open_live(default_driver, &format, NULL /* no options */);
if (device == NULL) {
fprintf(stderr, "Error opening device.\n");
return 1;
}
buf_size = format.bits/8 * format.channels * format.rate;
buffer = (char*)calloc(buf_size, sizeof(char));
pthread_create(&thread, NULL, soundThread, (void *)NULL);
return(true);
}
void AOSound_StopSound()
{
ao_close(device);
ao_shutdown();
}
}

View File

@ -0,0 +1,35 @@
// Copyright (C) 2003-2008 Dolphin Project.
// This program 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, version 2.0.
// This program 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 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#ifndef __AOSOUNDSTREAM_H__
#define __AOSOUNDSTREAM_H__
namespace AOSound
{
typedef void (*StreamCallback)(short* buffer, int numSamples, int bits, int rate, int channels);
bool AOSound_StartSound(int sampleRate, StreamCallback _callback);
void AOSound_UpdateSound();
void AOSound_StopSound();
float AOSound_GetTimer();
int AOSound_GetCurSample();
int AOSound_GetSampleRate();
}
#endif //__AOSOUNDSTREAM_H__

View File

@ -1,6 +1,7 @@
Import('env')
output = "../../../../Binary/linux/Plugins/dsplle.so"
files = ["disassemble.cpp",
files = ["AOSoundStream.cpp",
"disassemble.cpp",
"gdsp_aram.cpp",
"gdsp_ext_op.cpp",
"gdsp_interface.cpp",
@ -11,6 +12,7 @@ files = ["disassemble.cpp",
"Globals.cpp",
"opcodes.cpp",
"Tools.cpp",
"main.cpp",
]
#env.Append(LINKFLAGS = "-symbolic")
env.Append(LINKFLAGS = " `pkg-config --libs ao`")
env.SharedLibrary(output, files, LIBS = ["common"])

View File

@ -29,6 +29,16 @@ HINSTANCE g_hInstance = NULL;
HANDLE g_hDSPThread = NULL;
CRITICAL_SECTION g_CriticalSection;
CDisAsmDlg g_Dialog;
#else
#define WINAPI
#define LPVOID void*
#define __int16 short;
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include "AOSoundStream.h"
pthread_t g_hDSPThread = NULL;
#endif
DSPInitialize g_dspInitialize;
@ -39,7 +49,7 @@ DSPInitialize g_dspInitialize;
uint32 g_LastDMAAddress = 0;
uint32 g_LastDMASize = 0;
#ifdef _WIN32
BOOL APIENTRY DllMain(HINSTANCE hinstDLL, // DLL module handle
DWORD dwReason, // reason called
LPVOID lpvReserved) // reserved
@ -59,7 +69,7 @@ BOOL APIENTRY DllMain(HINSTANCE hinstDLL, // DLL module handle
g_hInstance = hinstDLL;
return(TRUE);
}
#endif
void GetDllInfo(PLUGIN_INFO* _PluginInfo)
{
@ -95,8 +105,11 @@ void DllDebugger(HWND _hParent)
}
#ifdef _WIN32
DWORD WINAPI dsp_thread(LPVOID lpParameter)
#else
void* dsp_thread(void* lpParameter)
#endif
{
while (1)
{
@ -112,6 +125,7 @@ DWORD WINAPI dsp_thread(LPVOID lpParameter)
DWORD WINAPI dsp_thread_debug(LPVOID lpParameter)
{
#ifdef _WIN32
while (1)
{
if (g_Dialog.CanDoStep())
@ -123,6 +137,7 @@ DWORD WINAPI dsp_thread_debug(LPVOID lpParameter)
Sleep(100);
}
}
#endif
}
@ -175,19 +190,23 @@ void DSP_Initialize(DSPInitialize _dspInitialize)
fclose(t); */
}
#ifdef _WIN32
#if _DEBUG
g_hDSPThread = CreateThread(NULL, 0, dsp_thread_debug, 0, 0, NULL);
#else
g_hDSPThread = CreateThread(NULL, 0, dsp_thread, 0, 0, NULL);
#endif
#else
pthread_create(&g_hDSPThread, NULL, dsp_thread, (void *)NULL);
#endif
InitializeCriticalSection(&g_CriticalSection);
DSound::DSound_StartSound((HWND)g_dspInitialize.hWnd, 32000, Mixer);
#ifdef _WIN32
InitializeCriticalSection(&g_CriticalSection);
DSound::DSound_StartSound((HWND)g_dspInitialize.hWnd, 32000, Mixer);
#else
AOSound::AOSound_StartSound(32000, Mixer);
#endif
}
@ -195,25 +214,38 @@ void DSP_Shutdown(void)
{
if (g_hDSPThread != NULL)
{
#ifdef _WIN32
TerminateThread(g_hDSPThread, 0);
#else
pthread_cancel(g_hDSPThread);
#endif
}
}
#ifdef _WIN32
unsigned __int16 DSP_WriteControlRegister(unsigned __int16 _uFlag)
#else
short unsigned int DSP_WriteControlRegister(short _uFlag)
#endif
{
gdsp_write_cr(_uFlag);
return(gdsp_read_cr());
}
#ifdef _WIN32
unsigned __int16 DSP_ReadControlRegister()
#else
short unsigned int DSP_ReadControlRegister()
#endif
{
return(gdsp_read_cr());
}
#ifdef _WIN32
unsigned __int16 DSP_ReadMailboxHigh(bool _CPUMailbox)
#else
short unsigned int DSP_ReadMailboxHigh(bool _CPUMailbox)
#endif
{
if (_CPUMailbox)
{
@ -225,8 +257,11 @@ unsigned __int16 DSP_ReadMailboxHigh(bool _CPUMailbox)
}
}
#ifdef _WIN32
unsigned __int16 DSP_ReadMailboxLow(bool _CPUMailbox)
#else
short unsigned int DSP_ReadMailboxLow(bool _CPUMailbox)
#endif
{
if (_CPUMailbox)
{
@ -238,8 +273,11 @@ unsigned __int16 DSP_ReadMailboxLow(bool _CPUMailbox)
}
}
#ifdef _WIN32
void DSP_WriteMailboxHigh(bool _CPUMailbox, unsigned __int16 _uHighMail)
#else
void DSP_WriteMailboxHigh(bool _CPUMailbox, short unsigned int _uHighMail)
#endif
{
if (_CPUMailbox)
{
@ -256,8 +294,11 @@ void DSP_WriteMailboxHigh(bool _CPUMailbox, unsigned __int16 _uHighMail)
}
}
#ifdef _WIN32
void DSP_WriteMailboxLow(bool _CPUMailbox, unsigned __int16 _uLowMail)
#else
void DSP_WriteMailboxLow(bool _CPUMailbox, short unsigned int _uLowMail)
#endif
{
if (_CPUMailbox)
{
@ -278,15 +319,19 @@ void DSP_Update()
{
return;
}
#ifdef _WIN32
if (g_Dialog.CanDoStep())
{
gdsp_runx(100);
}
#endif
}
#ifdef _WIN32
void DSP_SendAIBuffer(unsigned __int32 _Address, unsigned __int32 _Size)
#else
void DSP_SendAIBuffer(unsigned int _Address, unsigned int _Size)
#endif
{
uint32 Size = _Size * 16 * 2; // 16bit per sample, two channels