mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-24 14:49:42 -06:00
DSP HLE: Fixed a sound problem with a new Setup.h option. For some reason all the SoundSyncEvent->Set() caused a lot of static for me in Wario Land.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2236 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
@ -36,13 +36,11 @@ void CConfig::Load()
|
||||
file.Get("Config", "EnableHLEAudio", &m_EnableHLEAudio, true); // Sound Settings
|
||||
file.Get("Config", "EnableDTKMusic", &m_EnableDTKMusic, true);
|
||||
file.Get("Config", "EnableThrottle", &m_EnableThrottle, true);
|
||||
|
||||
#ifdef _WIN32
|
||||
file.Get("Config", "Backend", &temp, "DSound");
|
||||
file.Get("Config", "Backend", &sBackend, "DSound");
|
||||
#else
|
||||
file.Get("Config", "Backend", &temp, "AOSound");
|
||||
file.Get("Config", "Backend", &sBackend, "AOSound");
|
||||
#endif
|
||||
strncpy(sBackend, temp.c_str(), 16);
|
||||
}
|
||||
|
||||
void CConfig::Save()
|
||||
@ -52,7 +50,7 @@ void CConfig::Save()
|
||||
file.Set("Config", "EnableHLEAudio", m_EnableHLEAudio); // Sound Settings
|
||||
file.Set("Config", "EnableDTKMusic", m_EnableDTKMusic);
|
||||
file.Set("Config", "EnableThrottle", m_EnableThrottle);
|
||||
file.Set("Config", "Backend", sBackend);
|
||||
file.Set("Config", "Backend", sBackend.c_str());
|
||||
|
||||
file.Save(FULL_CONFIG_DIR "DSP.ini");
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ struct CConfig
|
||||
bool m_EnableHLEAudio;
|
||||
bool m_EnableDTKMusic;
|
||||
bool m_EnableThrottle;
|
||||
char sBackend[10];
|
||||
std::string sBackend;
|
||||
|
||||
CConfig();
|
||||
|
||||
|
@ -42,14 +42,12 @@ ConfigDialog::ConfigDialog(wxWindow *parent, wxWindowID id, const wxString &titl
|
||||
m_buttonEnableDTKMusic = new wxCheckBox(this, ID_ENABLE_DTK_MUSIC, wxT("Enable DTK Music"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
|
||||
m_buttonEnableThrottle = new wxCheckBox(this, ID_ENABLE_THROTTLE, wxT("Enable Other Audio (Throttle)"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
|
||||
wxStaticText *BackendText = new wxStaticText(this, wxID_ANY, wxT("Audio Backend"), wxDefaultPosition, wxDefaultSize, 0);
|
||||
m_BackendSelection = new wxComboBox(this, ID_BACKEND, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxArrayBackends, 0, wxDefaultValidator);
|
||||
m_BackendSelection = new wxComboBox(this, ID_BACKEND, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxArrayBackends, wxCB_READONLY, wxDefaultValidator);
|
||||
|
||||
|
||||
// Update values
|
||||
m_buttonEnableHLEAudio->SetValue(g_Config.m_EnableHLEAudio ? true : false);
|
||||
m_buttonEnableDTKMusic->SetValue(g_Config.m_EnableDTKMusic ? true : false);
|
||||
m_buttonEnableThrottle->SetValue(g_Config.m_EnableThrottle ? true : false);
|
||||
m_BackendSelection->SetValue(wxString::FromAscii(g_Config.sBackend));
|
||||
|
||||
// Add tooltips
|
||||
m_buttonEnableHLEAudio->SetToolTip(wxT("This is the most common sound type"));
|
||||
@ -78,8 +76,12 @@ ConfigDialog::ConfigDialog(wxWindow *parent, wxWindowID id, const wxString &titl
|
||||
this->SetSizerAndFit(sMain);
|
||||
}
|
||||
|
||||
void ConfigDialog::AddBackend(const char* backend) {
|
||||
// Add audio output options
|
||||
void ConfigDialog::AddBackend(const char* backend)
|
||||
{
|
||||
m_BackendSelection->Append(wxString::FromAscii(backend));
|
||||
// Update value
|
||||
m_BackendSelection->SetValue(wxString::FromAscii(g_Config.sBackend.c_str()));
|
||||
}
|
||||
|
||||
ConfigDialog::~ConfigDialog()
|
||||
@ -91,7 +93,7 @@ void ConfigDialog::SettingsChanged(wxCommandEvent& event)
|
||||
g_Config.m_EnableHLEAudio = m_buttonEnableHLEAudio->GetValue();
|
||||
g_Config.m_EnableDTKMusic = m_buttonEnableDTKMusic->GetValue();
|
||||
g_Config.m_EnableThrottle = m_buttonEnableThrottle->GetValue();
|
||||
strcpy(g_Config.sBackend, m_BackendSelection->GetValue().mb_str());
|
||||
g_Config.sBackend = m_BackendSelection->GetValue().mb_str();
|
||||
g_Config.Save();
|
||||
|
||||
if (event.GetId() == wxID_OK)
|
||||
|
@ -20,6 +20,8 @@
|
||||
|
||||
#include "Common.h"
|
||||
#include "pluginspecs_dsp.h"
|
||||
#include "ConsoleWindow.h"
|
||||
#include "StringUtil.h"
|
||||
|
||||
extern DSPInitialize g_dspInitialize;
|
||||
void DebugLog(const char* _fmt, ...);
|
||||
|
@ -15,10 +15,14 @@
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#include <dxerr.h>
|
||||
|
||||
#include "DSoundStream.h"
|
||||
#include "../main.h"
|
||||
#include "WaveFile.h"
|
||||
|
||||
#include <dxerr.h>
|
||||
extern bool log_ai;
|
||||
extern WaveFileWriter g_wave_writer;
|
||||
|
||||
bool DSound::CreateBuffer()
|
||||
{
|
||||
@ -59,6 +63,11 @@ bool DSound::WriteDataToBuffer(DWORD dwOffset, // Our own write
|
||||
char* soundData, // Start of our data.
|
||||
DWORD dwSoundBytes) // Size of block to copy.
|
||||
{
|
||||
// I want to record the regular audio to, how do I do that?
|
||||
//std::string Data = ArrayToString((const u8*)soundData, dwSoundBytes);
|
||||
//Console::Print("Data: %s\n\n", Data.c_str());
|
||||
//if (log_ai) g_wave_writer.AddStereoSamples((const short*)soundData, dwSoundBytes);
|
||||
|
||||
void* ptr1, * ptr2;
|
||||
DWORD numBytes1, numBytes2;
|
||||
// Obtain memory address of write block. This will be in two parts if the block wraps around.
|
||||
|
@ -48,9 +48,11 @@ volatile bool mixer_HLEready = false;
|
||||
volatile int queue_size = 0;
|
||||
bool bThrottling = false;
|
||||
|
||||
void UpdateThrottle(bool update) {
|
||||
/* What is this for?
|
||||
void UpdateThrottle(bool update)
|
||||
{
|
||||
bThrottling = update;
|
||||
}
|
||||
}*/
|
||||
|
||||
void Mixer(short *buffer, int numSamples, int bits, int rate, int channels)
|
||||
{
|
||||
@ -101,11 +103,14 @@ void Mixer_MixUCode(short *buffer, int numSamples, int bits, int rate,
|
||||
}
|
||||
}
|
||||
|
||||
void Mixer_PushSamples(short *buffer, int num_stereo_samples, int sample_rate) {
|
||||
void Mixer_PushSamples(short *buffer, int num_stereo_samples, int sample_rate)
|
||||
{
|
||||
// We alredady do this with the WaveFileWriter right? So no need for this to?
|
||||
// static FILE *f;
|
||||
// if (!f)
|
||||
// f = fopen("d:\\hello.raw", "wb");
|
||||
// fwrite(buffer, num_stereo_samples * 4, 1, f);
|
||||
|
||||
if (queue_size == 0)
|
||||
{
|
||||
queue_size = queue_minlength;
|
||||
@ -117,83 +122,83 @@ void Mixer_PushSamples(short *buffer, int num_stereo_samples, int sample_rate) {
|
||||
static int PV1r=0,PV2r=0,PV3r=0,PV4r=0;
|
||||
static int acc=0;
|
||||
|
||||
bThrottling = g_Config.m_EnableThrottle;
|
||||
// Write Other Audio
|
||||
//bThrottling = g_Config.m_EnableThrottle;
|
||||
if(g_Config.m_EnableThrottle)
|
||||
{
|
||||
|
||||
if(bThrottling) {
|
||||
|
||||
/* This is only needed for non-AX sound, currently directly
|
||||
streamed and DTK sound. For AX we call SoundStream::Update in
|
||||
AXTask() for example. */
|
||||
while (queue_size > queue_maxlength / 2) {
|
||||
soundStream->Update();
|
||||
Common::SleepCurrentThread(0);
|
||||
}
|
||||
|
||||
//convert into config option?
|
||||
const int mode = 2;
|
||||
|
||||
push_sync.Enter();
|
||||
while (num_stereo_samples)
|
||||
{
|
||||
acc += sample_rate;
|
||||
while (num_stereo_samples && (acc >= 48000))
|
||||
{
|
||||
PV4l=PV3l;
|
||||
PV3l=PV2l;
|
||||
PV2l=PV1l;
|
||||
PV1l=*(buffer++); //32bit processing
|
||||
PV4r=PV3r;
|
||||
PV3r=PV2r;
|
||||
PV2r=PV1r;
|
||||
PV1r=*(buffer++); //32bit processing
|
||||
num_stereo_samples--;
|
||||
acc-=48000;
|
||||
}
|
||||
|
||||
// defaults to nearest
|
||||
s32 DataL = PV1l;
|
||||
s32 DataR = PV1r;
|
||||
|
||||
if (mode == 1) //linear
|
||||
{
|
||||
DataL = PV1l + ((PV2l - PV1l)*acc)/48000;
|
||||
DataR = PV1r + ((PV2r - PV1r)*acc)/48000;
|
||||
}
|
||||
else if (mode == 2) //cubic
|
||||
{
|
||||
s32 a0l = PV1l - PV2l - PV4l + PV3l;
|
||||
s32 a0r = PV1r - PV2r - PV4r + PV3r;
|
||||
s32 a1l = PV4l - PV3l - a0l;
|
||||
s32 a1r = PV4r - PV3r - a0r;
|
||||
s32 a2l = PV1l - PV4l;
|
||||
s32 a2r = PV1r - PV4r;
|
||||
s32 a3l = PV2l;
|
||||
s32 a3r = PV2r;
|
||||
|
||||
s32 t0l = ((a0l )*acc)/48000;
|
||||
s32 t0r = ((a0r )*acc)/48000;
|
||||
s32 t1l = ((t0l+a1l)*acc)/48000;
|
||||
s32 t1r = ((t0r+a1r)*acc)/48000;
|
||||
s32 t2l = ((t1l+a2l)*acc)/48000;
|
||||
s32 t2r = ((t1r+a2r)*acc)/48000;
|
||||
s32 t3l = ((t2l+a3l));
|
||||
s32 t3r = ((t2r+a3r));
|
||||
|
||||
DataL = t3l;
|
||||
DataR = t3r;
|
||||
}
|
||||
|
||||
int l = DataL, r = DataR;
|
||||
if (l < -32767) l = -32767;
|
||||
if (r < -32767) r = -32767;
|
||||
if (l > 32767) l = 32767;
|
||||
if (r > 32767) r = 32767;
|
||||
sample_queue.push(l);
|
||||
sample_queue.push(r);
|
||||
queue_size += 2;
|
||||
}
|
||||
push_sync.Leave();
|
||||
/* This is only needed for non-AX sound, currently directly
|
||||
streamed and DTK sound. For AX we call SoundStream::Update in
|
||||
AXTask() for example. */
|
||||
while (queue_size > queue_maxlength / 2) {
|
||||
soundStream->Update();
|
||||
Common::SleepCurrentThread(0);
|
||||
}
|
||||
|
||||
//convert into config option?
|
||||
const int mode = 2;
|
||||
|
||||
push_sync.Enter();
|
||||
while (num_stereo_samples)
|
||||
{
|
||||
acc += sample_rate;
|
||||
while (num_stereo_samples && (acc >= 48000))
|
||||
{
|
||||
PV4l=PV3l;
|
||||
PV3l=PV2l;
|
||||
PV2l=PV1l;
|
||||
PV1l=*(buffer++); //32bit processing
|
||||
PV4r=PV3r;
|
||||
PV3r=PV2r;
|
||||
PV2r=PV1r;
|
||||
PV1r=*(buffer++); //32bit processing
|
||||
num_stereo_samples--;
|
||||
acc-=48000;
|
||||
}
|
||||
|
||||
// defaults to nearest
|
||||
s32 DataL = PV1l;
|
||||
s32 DataR = PV1r;
|
||||
|
||||
if (mode == 1) //linear
|
||||
{
|
||||
DataL = PV1l + ((PV2l - PV1l)*acc)/48000;
|
||||
DataR = PV1r + ((PV2r - PV1r)*acc)/48000;
|
||||
}
|
||||
else if (mode == 2) //cubic
|
||||
{
|
||||
s32 a0l = PV1l - PV2l - PV4l + PV3l;
|
||||
s32 a0r = PV1r - PV2r - PV4r + PV3r;
|
||||
s32 a1l = PV4l - PV3l - a0l;
|
||||
s32 a1r = PV4r - PV3r - a0r;
|
||||
s32 a2l = PV1l - PV4l;
|
||||
s32 a2r = PV1r - PV4r;
|
||||
s32 a3l = PV2l;
|
||||
s32 a3r = PV2r;
|
||||
|
||||
s32 t0l = ((a0l )*acc)/48000;
|
||||
s32 t0r = ((a0r )*acc)/48000;
|
||||
s32 t1l = ((t0l+a1l)*acc)/48000;
|
||||
s32 t1r = ((t0r+a1r)*acc)/48000;
|
||||
s32 t2l = ((t1l+a2l)*acc)/48000;
|
||||
s32 t2r = ((t1r+a2r)*acc)/48000;
|
||||
s32 t3l = ((t2l+a3l));
|
||||
s32 t3r = ((t2r+a3r));
|
||||
|
||||
DataL = t3l;
|
||||
DataR = t3r;
|
||||
}
|
||||
|
||||
int l = DataL, r = DataR;
|
||||
if (l < -32767) l = -32767;
|
||||
if (r < -32767) r = -32767;
|
||||
if (l > 32767) l = 32767;
|
||||
if (r > 32767) r = 32767;
|
||||
sample_queue.push(l);
|
||||
sample_queue.push(r);
|
||||
queue_size += 2;
|
||||
}
|
||||
push_sync.Leave();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,8 @@ CDebugger* m_frame = NULL;
|
||||
#include "PCHW/Mixer.h"
|
||||
#include "DSPHandler.h"
|
||||
#include "Config.h"
|
||||
#include "Setup.h"
|
||||
#include "StringUtil.h"
|
||||
|
||||
#include "PCHW/AOSoundStream.h"
|
||||
#include "PCHW/DSoundStream.h"
|
||||
@ -45,10 +47,10 @@ std::string gpName;
|
||||
|
||||
SoundStream *soundStream = NULL;
|
||||
|
||||
// Set this if you want to log audio. search for log_ai in this file to see the filename.
|
||||
static bool log_ai = false;
|
||||
static WaveFileWriter g_wave_writer;
|
||||
|
||||
// Set this if you want to log audio. search for log_ai in this file to see the filename.
|
||||
bool log_ai = false;
|
||||
WaveFileWriter g_wave_writer;
|
||||
|
||||
|
||||
// Mailbox utility
|
||||
@ -194,17 +196,23 @@ void DllConfig(HWND _hParent)
|
||||
#if defined(HAVE_WX) && HAVE_WX
|
||||
// (shuffle2) TODO: reparent dlg with DolphinApp
|
||||
ConfigDialog dlg(NULL);
|
||||
|
||||
// Add avaliable output options
|
||||
if (DSound::isValid())
|
||||
dlg.AddBackend("DSound");
|
||||
if (AOSound::isValid())
|
||||
dlg.AddBackend("AOSound");
|
||||
dlg.AddBackend("NullSound");
|
||||
|
||||
// Show the window
|
||||
dlg.ShowModal();
|
||||
#endif
|
||||
}
|
||||
|
||||
void Initialize(void *init)
|
||||
{
|
||||
//Console::Open(80, 5000);
|
||||
|
||||
g_Config.Load();
|
||||
|
||||
g_dspInitialize = *(DSPInitialize*)init;
|
||||
@ -224,16 +232,22 @@ void Initialize(void *init)
|
||||
|
||||
CDSPHandler::CreateInstance();
|
||||
|
||||
if (strncasecmp(g_Config.sBackend, "DSound", 10) == 0) {
|
||||
if (DSound::isValid()) {
|
||||
if (g_Config.sBackend == "DSound")
|
||||
{
|
||||
if (DSound::isValid())
|
||||
soundStream = new DSound(48000, Mixer, g_dspInitialize.hWnd);
|
||||
}
|
||||
} else if(strncasecmp(g_Config.sBackend, "AOSound", 10) == 0) {
|
||||
}
|
||||
else if(g_Config.sBackend == "AOSound")
|
||||
{
|
||||
if (AOSound::isValid())
|
||||
soundStream = new AOSound(48000, Mixer);
|
||||
} else if(strncasecmp(g_Config.sBackend, "NullSound", 10) == 0) {
|
||||
}
|
||||
else if(g_Config.sBackend == "NullSound")
|
||||
{
|
||||
soundStream = new NullSound(48000, Mixer_MixUCode);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
PanicAlert("Cannot recognize backend %s", g_Config.sBackend);
|
||||
return;
|
||||
}
|
||||
@ -260,36 +274,47 @@ void Initialize(void *init)
|
||||
soundStream->Start();
|
||||
}
|
||||
|
||||
// Start the sound recording
|
||||
if (log_ai)
|
||||
{
|
||||
g_wave_writer.Start("ai_log.wav");
|
||||
g_wave_writer.SetSkipSilence(false);
|
||||
}
|
||||
}
|
||||
|
||||
void Shutdown()
|
||||
{
|
||||
if (log_ai)
|
||||
g_wave_writer.Stop();
|
||||
// delete the UCodes
|
||||
// Stop the sound recording
|
||||
if (log_ai) g_wave_writer.Stop();
|
||||
|
||||
// Delete the UCodes
|
||||
soundStream->Stop();
|
||||
delete soundStream;
|
||||
soundStream = NULL;
|
||||
|
||||
CDSPHandler::Destroy();
|
||||
|
||||
#if defined(HAVE_WX) && HAVE_WX
|
||||
// Reset mails
|
||||
if(m_frame)
|
||||
{
|
||||
sMailLog.clear();
|
||||
sMailTime.clear();
|
||||
m_frame->sMail.clear();
|
||||
m_frame->sMailEnd.clear();
|
||||
}
|
||||
#endif
|
||||
#if defined(HAVE_WX) && HAVE_WX
|
||||
// Reset mails
|
||||
if(m_frame)
|
||||
{
|
||||
sMailLog.clear();
|
||||
sMailTime.clear();
|
||||
m_frame->sMail.clear();
|
||||
m_frame->sMailEnd.clear();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void DoState(unsigned char **ptr, int mode) {
|
||||
void DoState(unsigned char **ptr, int mode)
|
||||
{
|
||||
PointerWrap p(ptr, mode);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Mailbox fuctions
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
unsigned short DSP_ReadMailboxHigh(bool _CPUMailbox)
|
||||
{
|
||||
if (_CPUMailbox)
|
||||
@ -354,8 +379,12 @@ void DSP_WriteMailboxLow(bool _CPUMailbox, unsigned short _Value)
|
||||
PanicAlert("CPU can't write %08x to DSP mailbox", _Value);
|
||||
}
|
||||
}
|
||||
/////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Other DSP fuctions
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
unsigned short DSP_WriteControlRegister(unsigned short _Value)
|
||||
{
|
||||
return CDSPHandler::GetInstance().WriteControlRegister(_Value);
|
||||
@ -371,28 +400,38 @@ void DSP_Update(int cycles)
|
||||
CDSPHandler::GetInstance().Update();
|
||||
}
|
||||
|
||||
/* Other Audio will pass through here. The kind of audio that sometimes are used together with pre-drawn
|
||||
movies. This audio can be disabled further inside Mixer_PushSamples(), the reason that we don't disable
|
||||
this entire function when Other Audio is disabled is that then we can't turn it back on again once the
|
||||
game has started. */
|
||||
void DSP_SendAIBuffer(unsigned int address, int sample_rate)
|
||||
{
|
||||
if(soundStream->usesMixer()) {
|
||||
if(soundStream->usesMixer())
|
||||
{
|
||||
short samples[16] = {0}; // interleaved stereo
|
||||
if (address) {
|
||||
for (int i = 0; i < 16; i++) {
|
||||
if (address)
|
||||
{
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
samples[i] = Memory_Read_U16(address + i * 2);
|
||||
}
|
||||
if (log_ai)
|
||||
g_wave_writer.AddStereoSamples(samples, 8);
|
||||
|
||||
// Write the audio to a file
|
||||
if (log_ai) g_wave_writer.AddStereoSamples(samples, 8);
|
||||
}
|
||||
Mixer_PushSamples(samples, 32 / 4, sample_rate);
|
||||
}
|
||||
|
||||
/*static int counter = 0;
|
||||
counter++;
|
||||
if ((counter & 255) == 0)*/
|
||||
|
||||
|
||||
/* If I don't use this in Wario Land Shake It I get bad sound, it's a lot of static and noise
|
||||
in the sound. It's the same both with an without Enable Other Audio. I can't really say why
|
||||
this occurs because I don't know what SoundSyncEvent->Set() does. */
|
||||
#ifdef SETUP_AVOID_SOUND_ARTIFACTS
|
||||
static int counter = 0;
|
||||
counter++;
|
||||
if ((counter & 255) == 0)
|
||||
#endif
|
||||
// SoundStream is updated only when necessary (there is no 70 ms limit
|
||||
// so each sample now triggers the sound stream)
|
||||
soundStream->Update();
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////
|
||||
|
@ -17,12 +17,13 @@
|
||||
|
||||
#ifndef __MAIN_H__
|
||||
#define __MAIN_H__
|
||||
|
||||
#include "PCHW/SoundStream.h"
|
||||
#include "Globals.h" // Local
|
||||
|
||||
#if defined(HAVE_WX) && HAVE_WX
|
||||
#include "Debugger/Debugger.h"
|
||||
extern CDebugger* m_frame;
|
||||
#include "Debugger/Debugger.h"
|
||||
extern CDebugger* m_frame;
|
||||
#endif
|
||||
|
||||
extern SoundStream *soundStream;
|
||||
|
Reference in New Issue
Block a user