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:
John Peterson
2009-02-14 01:07:20 +00:00
parent 94ee9afdb2
commit 94583cbab0
17 changed files with 215 additions and 167 deletions

View File

@ -411,10 +411,6 @@
RelativePath=".\Src\Main.h" RelativePath=".\Src\Main.h"
> >
</File> </File>
<File
RelativePath=".\Src\Setup.h"
>
</File>
</Files> </Files>
<Globals> <Globals>
</Globals> </Globals>

View File

@ -1,23 +0,0 @@
// 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/
////////////////////////////////////////////////////////////////////////////////////////
// Build with music modification
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//#define MUSICMOD
//////////////////////////

View File

@ -18,7 +18,7 @@
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
// File description // File description
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Compilation settings. This file can be kept on the ignore list in your SVN program. It Compilation settings. This file can be kept on the ignore list in your SVN program. It
allows local optional settings depending on what works on your computer. allows local optional settings depending on what works on your computer.
@ -29,7 +29,7 @@
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
// Settings // Settings
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// This may fix a problem with Stop and Start that I described in the comments to revision 2,139 // This may fix a problem with Stop and Start that I described in the comments to revision 2,139
//#define SETUP_FREE_PLUGIN_ON_BOOT //#define SETUP_FREE_PLUGIN_ON_BOOT
@ -37,4 +37,10 @@
// This may fix a semi-frequent hanging that occured when I used single core and render to main frame // This may fix a semi-frequent hanging that occured when I used single core and render to main frame
//#define SETUP_AVOID_SINGLE_CORE_HANG_ON_STOP //#define SETUP_AVOID_SINGLE_CORE_HANG_ON_STOP
////////////////////////// // This may remove sound artifacts in Wario Land Shake It and perhaps other games
//#define SETUP_AVOID_SOUND_ARTIFACTS
// Build with music modification
//#define MUSICMOD
///////////////////////////

View File

@ -37,19 +37,31 @@ bool WaveFileWriter::Start(const char *filename)
if (!conv_buffer) if (!conv_buffer)
conv_buffer = new short[BUF_SIZE]; conv_buffer = new short[BUF_SIZE];
// Check if the file is already open
if (file) if (file)
{
PanicAlert("The file %s was alrady open, the file header will not be written.", filename);
return false; return false;
}
file = fopen(filename, "wb"); file = fopen(filename, "wb");
if (!file) if (!file)
{
PanicAlert("The file %s could not be opened for writing. Please check if it's already opened by another program.", filename);
return false; return false;
}
// ---------------------------------------------------------
// Write file header
// ---------------
Write4("RIFF"); Write4("RIFF");
Write(100 * 1000 * 1000); // write big value in case the file gets truncated Write(100 * 1000 * 1000); // write big value in case the file gets truncated
Write4("WAVE"); Write4("WAVE");
Write4("fmt "); Write4("fmt ");
Write(16); // size of fmt block Write(16); // size of fmt block
Write(0x00020001); //two channels, uncompressed Write(0x00020001); //two channels, uncompressed
const u32 sample_rate = 32000; //const u32 sample_rate = 32000;
const u32 sample_rate = 48000;
Write(sample_rate); Write(sample_rate);
Write(sample_rate * 2 * 2); //two channels, 16bit Write(sample_rate * 2 * 2); //two channels, 16bit
Write(0x00100004); Write(0x00100004);
@ -58,8 +70,9 @@ bool WaveFileWriter::Start(const char *filename)
// We are now at offset 44 // We are now at offset 44
if (ftell(file) != 44) if (ftell(file) != 44)
PanicAlert("wrong offset: %i", ftell(file)); PanicAlert("wrong offset: %i", ftell(file));
// ---------------------------
return true; return true;
} }
void WaveFileWriter::Stop() void WaveFileWriter::Stop()
@ -92,10 +105,8 @@ void WaveFileWriter::AddStereoSamples(const short *sample_data, int count)
if (skip_silence) { if (skip_silence) {
bool all_zero = true; bool all_zero = true;
for (int i = 0; i < count * 2; i++) for (int i = 0; i < count * 2; i++)
if (sample_data[i]) if (sample_data[i]) all_zero = false;
all_zero = false; if (all_zero) return;
if (all_zero)
return;
} }
fwrite(sample_data, count * 4, 1, file); fwrite(sample_data, count * 4, 1, file);
audio_size += count * 4; audio_size += count * 4;

View File

@ -37,7 +37,7 @@
////////////////////////////////////////////////// //////////////////////////////////////////////////
// Music mod // Music mod
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#include "../../../../Externals/MusicMod/Main/Src/Setup.h" // Define MUSICMOD here #include "Setup.h" // Define MUSICMOD here
#ifdef MUSICMOD #ifdef MUSICMOD
#include "../../../../Externals/MusicMod/Main/Src/Main.h" #include "../../../../Externals/MusicMod/Main/Src/Main.h"
#endif #endif

View File

@ -23,7 +23,7 @@
////////////////////////////////////////////////// //////////////////////////////////////////////////
// Music mod // Music mod
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#include "../../../../Externals/MusicMod/Main/Src/Setup.h" // Define MUSICMOD here #include "Setup.h" // Define MUSICMOD here
#ifdef MUSICMOD #ifdef MUSICMOD
#include "../../../../Externals/MusicMod/Main/Src/Main.h" #include "../../../../Externals/MusicMod/Main/Src/Main.h"
#endif #endif

View File

@ -57,7 +57,7 @@
#include "ConfigMain.h" #include "ConfigMain.h"
#include "Frame.h" #include "Frame.h"
#include "CodeWindow.h" #include "CodeWindow.h"
#include "../../../Externals/MusicMod/Main/Src/Setup.h" #include "Setup.h"
#ifdef MUSICMOD #ifdef MUSICMOD
#include "../../../Externals/MusicMod/Main/Src/Main.h" // MusicMod #include "../../../Externals/MusicMod/Main/Src/Main.h" // MusicMod
#endif #endif

View File

@ -22,7 +22,7 @@
#define _GLOBALS_H #define _GLOBALS_H
#include "Common.h" #include "Common.h"
#include "../../../Externals/MusicMod/Main/Src/Setup.h" // Build with music modification. Define MUSICMOD here. #include "Setup.h" // Build with music modification. Define MUSICMOD here.
// Constant Colors // Constant Colors
const unsigned long COLOR_GRAY = 0xDCDCDC; const unsigned long COLOR_GRAY = 0xDCDCDC;

View File

@ -56,6 +56,7 @@ EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DolphinWX", "Core\DolphinWX\DolphinWX.vcproj", "{A72606EF-C5C1-4954-90AD-F0F93A8D97D9}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DolphinWX", "Core\DolphinWX\DolphinWX.vcproj", "{A72606EF-C5C1-4954-90AD-F0F93A8D97D9}"
ProjectSection(ProjectDependencies) = postProject ProjectSection(ProjectDependencies) = postProject
{48AD7E0A-25B1-4974-A1E3-03F8C438D34F} = {48AD7E0A-25B1-4974-A1E3-03F8C438D34F} {48AD7E0A-25B1-4974-A1E3-03F8C438D34F} = {48AD7E0A-25B1-4974-A1E3-03F8C438D34F}
{D6E56527-BBB9-4EAD-A6EC-49D4BF6AFCD8} = {D6E56527-BBB9-4EAD-A6EC-49D4BF6AFCD8}
{0318BA30-EF48-441A-9E10-DC85EFAE39F0} = {0318BA30-EF48-441A-9E10-DC85EFAE39F0} {0318BA30-EF48-441A-9E10-DC85EFAE39F0} = {0318BA30-EF48-441A-9E10-DC85EFAE39F0}
{8D612734-FAA5-4B8A-804F-4DEA2367D495} = {8D612734-FAA5-4B8A-804F-4DEA2367D495} {8D612734-FAA5-4B8A-804F-4DEA2367D495} = {8D612734-FAA5-4B8A-804F-4DEA2367D495}
{71B16F46-0B00-4EDA-B253-D6D9D03A215C} = {71B16F46-0B00-4EDA-B253-D6D9D03A215C} {71B16F46-0B00-4EDA-B253-D6D9D03A215C} = {71B16F46-0B00-4EDA-B253-D6D9D03A215C}
@ -301,6 +302,7 @@ Global
{D6E56527-BBB9-4EAD-A6EC-49D4BF6AFCD8}.DebugFast|x64.ActiveCfg = DebugFast|x64 {D6E56527-BBB9-4EAD-A6EC-49D4BF6AFCD8}.DebugFast|x64.ActiveCfg = DebugFast|x64
{D6E56527-BBB9-4EAD-A6EC-49D4BF6AFCD8}.DebugFast|x64.Build.0 = DebugFast|x64 {D6E56527-BBB9-4EAD-A6EC-49D4BF6AFCD8}.DebugFast|x64.Build.0 = DebugFast|x64
{D6E56527-BBB9-4EAD-A6EC-49D4BF6AFCD8}.Release|Win32.ActiveCfg = Release|Win32 {D6E56527-BBB9-4EAD-A6EC-49D4BF6AFCD8}.Release|Win32.ActiveCfg = Release|Win32
{D6E56527-BBB9-4EAD-A6EC-49D4BF6AFCD8}.Release|Win32.Build.0 = Release|Win32
{D6E56527-BBB9-4EAD-A6EC-49D4BF6AFCD8}.Release|x64.ActiveCfg = Release|x64 {D6E56527-BBB9-4EAD-A6EC-49D4BF6AFCD8}.Release|x64.ActiveCfg = Release|x64
{33546D62-7F34-4EA6-A88E-D538B36E16BF}.Debug|Win32.ActiveCfg = Debug|Win32 {33546D62-7F34-4EA6-A88E-D538B36E16BF}.Debug|Win32.ActiveCfg = Debug|Win32
{33546D62-7F34-4EA6-A88E-D538B36E16BF}.Debug|x64.ActiveCfg = Debug|x64 {33546D62-7F34-4EA6-A88E-D538B36E16BF}.Debug|x64.ActiveCfg = Debug|x64

View File

@ -36,13 +36,11 @@ void CConfig::Load()
file.Get("Config", "EnableHLEAudio", &m_EnableHLEAudio, true); // Sound Settings file.Get("Config", "EnableHLEAudio", &m_EnableHLEAudio, true); // Sound Settings
file.Get("Config", "EnableDTKMusic", &m_EnableDTKMusic, true); file.Get("Config", "EnableDTKMusic", &m_EnableDTKMusic, true);
file.Get("Config", "EnableThrottle", &m_EnableThrottle, true); file.Get("Config", "EnableThrottle", &m_EnableThrottle, true);
#ifdef _WIN32 #ifdef _WIN32
file.Get("Config", "Backend", &temp, "DSound"); file.Get("Config", "Backend", &sBackend, "DSound");
#else #else
file.Get("Config", "Backend", &temp, "AOSound"); file.Get("Config", "Backend", &sBackend, "AOSound");
#endif #endif
strncpy(sBackend, temp.c_str(), 16);
} }
void CConfig::Save() void CConfig::Save()
@ -52,7 +50,7 @@ void CConfig::Save()
file.Set("Config", "EnableHLEAudio", m_EnableHLEAudio); // Sound Settings file.Set("Config", "EnableHLEAudio", m_EnableHLEAudio); // Sound Settings
file.Set("Config", "EnableDTKMusic", m_EnableDTKMusic); file.Set("Config", "EnableDTKMusic", m_EnableDTKMusic);
file.Set("Config", "EnableThrottle", m_EnableThrottle); 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"); file.Save(FULL_CONFIG_DIR "DSP.ini");
} }

View File

@ -25,7 +25,7 @@ struct CConfig
bool m_EnableHLEAudio; bool m_EnableHLEAudio;
bool m_EnableDTKMusic; bool m_EnableDTKMusic;
bool m_EnableThrottle; bool m_EnableThrottle;
char sBackend[10]; std::string sBackend;
CConfig(); CConfig();

View File

@ -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_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); 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); 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 // Update values
m_buttonEnableHLEAudio->SetValue(g_Config.m_EnableHLEAudio ? true : false); m_buttonEnableHLEAudio->SetValue(g_Config.m_EnableHLEAudio ? true : false);
m_buttonEnableDTKMusic->SetValue(g_Config.m_EnableDTKMusic ? true : false); m_buttonEnableDTKMusic->SetValue(g_Config.m_EnableDTKMusic ? true : false);
m_buttonEnableThrottle->SetValue(g_Config.m_EnableThrottle ? true : false); m_buttonEnableThrottle->SetValue(g_Config.m_EnableThrottle ? true : false);
m_BackendSelection->SetValue(wxString::FromAscii(g_Config.sBackend));
// Add tooltips // Add tooltips
m_buttonEnableHLEAudio->SetToolTip(wxT("This is the most common sound type")); 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); 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)); m_BackendSelection->Append(wxString::FromAscii(backend));
// Update value
m_BackendSelection->SetValue(wxString::FromAscii(g_Config.sBackend.c_str()));
} }
ConfigDialog::~ConfigDialog() ConfigDialog::~ConfigDialog()
@ -91,7 +93,7 @@ void ConfigDialog::SettingsChanged(wxCommandEvent& event)
g_Config.m_EnableHLEAudio = m_buttonEnableHLEAudio->GetValue(); g_Config.m_EnableHLEAudio = m_buttonEnableHLEAudio->GetValue();
g_Config.m_EnableDTKMusic = m_buttonEnableDTKMusic->GetValue(); g_Config.m_EnableDTKMusic = m_buttonEnableDTKMusic->GetValue();
g_Config.m_EnableThrottle = m_buttonEnableThrottle->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(); g_Config.Save();
if (event.GetId() == wxID_OK) if (event.GetId() == wxID_OK)

View File

@ -20,6 +20,8 @@
#include "Common.h" #include "Common.h"
#include "pluginspecs_dsp.h" #include "pluginspecs_dsp.h"
#include "ConsoleWindow.h"
#include "StringUtil.h"
extern DSPInitialize g_dspInitialize; extern DSPInitialize g_dspInitialize;
void DebugLog(const char* _fmt, ...); void DebugLog(const char* _fmt, ...);

View File

@ -15,10 +15,14 @@
// Official SVN repository and contact information can be found at // Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
#include <dxerr.h>
#include "DSoundStream.h" #include "DSoundStream.h"
#include "../main.h" #include "../main.h"
#include "WaveFile.h"
#include <dxerr.h> extern bool log_ai;
extern WaveFileWriter g_wave_writer;
bool DSound::CreateBuffer() bool DSound::CreateBuffer()
{ {
@ -59,6 +63,11 @@ bool DSound::WriteDataToBuffer(DWORD dwOffset, // Our own write
char* soundData, // Start of our data. char* soundData, // Start of our data.
DWORD dwSoundBytes) // Size of block to copy. 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; void* ptr1, * ptr2;
DWORD numBytes1, numBytes2; DWORD numBytes1, numBytes2;
// Obtain memory address of write block. This will be in two parts if the block wraps around. // Obtain memory address of write block. This will be in two parts if the block wraps around.

View File

@ -48,9 +48,11 @@ volatile bool mixer_HLEready = false;
volatile int queue_size = 0; volatile int queue_size = 0;
bool bThrottling = false; bool bThrottling = false;
void UpdateThrottle(bool update) { /* What is this for?
void UpdateThrottle(bool update)
{
bThrottling = update; bThrottling = update;
} }*/
void Mixer(short *buffer, int numSamples, int bits, int rate, int channels) 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; // static FILE *f;
// if (!f) // if (!f)
// f = fopen("d:\\hello.raw", "wb"); // f = fopen("d:\\hello.raw", "wb");
// fwrite(buffer, num_stereo_samples * 4, 1, f); // fwrite(buffer, num_stereo_samples * 4, 1, f);
if (queue_size == 0) if (queue_size == 0)
{ {
queue_size = queue_minlength; 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 PV1r=0,PV2r=0,PV3r=0,PV4r=0;
static int acc=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
/* This is only needed for non-AX sound, currently directly AXTask() for example. */
streamed and DTK sound. For AX we call SoundStream::Update in while (queue_size > queue_maxlength / 2) {
AXTask() for example. */ soundStream->Update();
while (queue_size > queue_maxlength / 2) { Common::SleepCurrentThread(0);
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();
} }
//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();
}
} }

View File

@ -32,6 +32,8 @@ CDebugger* m_frame = NULL;
#include "PCHW/Mixer.h" #include "PCHW/Mixer.h"
#include "DSPHandler.h" #include "DSPHandler.h"
#include "Config.h" #include "Config.h"
#include "Setup.h"
#include "StringUtil.h"
#include "PCHW/AOSoundStream.h" #include "PCHW/AOSoundStream.h"
#include "PCHW/DSoundStream.h" #include "PCHW/DSoundStream.h"
@ -45,10 +47,10 @@ std::string gpName;
SoundStream *soundStream = NULL; 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 // Mailbox utility
@ -194,17 +196,23 @@ void DllConfig(HWND _hParent)
#if defined(HAVE_WX) && HAVE_WX #if defined(HAVE_WX) && HAVE_WX
// (shuffle2) TODO: reparent dlg with DolphinApp // (shuffle2) TODO: reparent dlg with DolphinApp
ConfigDialog dlg(NULL); ConfigDialog dlg(NULL);
// Add avaliable output options
if (DSound::isValid()) if (DSound::isValid())
dlg.AddBackend("DSound"); dlg.AddBackend("DSound");
if (AOSound::isValid()) if (AOSound::isValid())
dlg.AddBackend("AOSound"); dlg.AddBackend("AOSound");
dlg.AddBackend("NullSound"); dlg.AddBackend("NullSound");
// Show the window
dlg.ShowModal(); dlg.ShowModal();
#endif #endif
} }
void Initialize(void *init) void Initialize(void *init)
{ {
//Console::Open(80, 5000);
g_Config.Load(); g_Config.Load();
g_dspInitialize = *(DSPInitialize*)init; g_dspInitialize = *(DSPInitialize*)init;
@ -224,16 +232,22 @@ void Initialize(void *init)
CDSPHandler::CreateInstance(); CDSPHandler::CreateInstance();
if (strncasecmp(g_Config.sBackend, "DSound", 10) == 0) { if (g_Config.sBackend == "DSound")
if (DSound::isValid()) { {
if (DSound::isValid())
soundStream = new DSound(48000, Mixer, g_dspInitialize.hWnd); 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()) if (AOSound::isValid())
soundStream = new AOSound(48000, Mixer); 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); soundStream = new NullSound(48000, Mixer_MixUCode);
} else { }
else
{
PanicAlert("Cannot recognize backend %s", g_Config.sBackend); PanicAlert("Cannot recognize backend %s", g_Config.sBackend);
return; return;
} }
@ -260,36 +274,47 @@ void Initialize(void *init)
soundStream->Start(); soundStream->Start();
} }
// Start the sound recording
if (log_ai)
{
g_wave_writer.Start("ai_log.wav");
g_wave_writer.SetSkipSilence(false);
}
} }
void Shutdown() void Shutdown()
{ {
if (log_ai) // Stop the sound recording
g_wave_writer.Stop(); if (log_ai) g_wave_writer.Stop();
// delete the UCodes
// Delete the UCodes
soundStream->Stop(); soundStream->Stop();
delete soundStream; delete soundStream;
soundStream = NULL; soundStream = NULL;
CDSPHandler::Destroy(); CDSPHandler::Destroy();
#if defined(HAVE_WX) && HAVE_WX #if defined(HAVE_WX) && HAVE_WX
// Reset mails // Reset mails
if(m_frame) if(m_frame)
{ {
sMailLog.clear(); sMailLog.clear();
sMailTime.clear(); sMailTime.clear();
m_frame->sMail.clear(); m_frame->sMail.clear();
m_frame->sMailEnd.clear(); m_frame->sMailEnd.clear();
} }
#endif #endif
} }
void DoState(unsigned char **ptr, int mode) { void DoState(unsigned char **ptr, int mode)
{
PointerWrap p(ptr, mode); PointerWrap p(ptr, mode);
} }
////////////////////////////////////////////////////////////////////////////////////////
// Mailbox fuctions // Mailbox fuctions
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
unsigned short DSP_ReadMailboxHigh(bool _CPUMailbox) unsigned short DSP_ReadMailboxHigh(bool _CPUMailbox)
{ {
if (_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); PanicAlert("CPU can't write %08x to DSP mailbox", _Value);
} }
} }
/////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
// Other DSP fuctions // Other DSP fuctions
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
unsigned short DSP_WriteControlRegister(unsigned short _Value) unsigned short DSP_WriteControlRegister(unsigned short _Value)
{ {
return CDSPHandler::GetInstance().WriteControlRegister(_Value); return CDSPHandler::GetInstance().WriteControlRegister(_Value);
@ -371,28 +400,38 @@ void DSP_Update(int cycles)
CDSPHandler::GetInstance().Update(); 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) void DSP_SendAIBuffer(unsigned int address, int sample_rate)
{ {
if(soundStream->usesMixer()) { if(soundStream->usesMixer())
{
short samples[16] = {0}; // interleaved stereo short samples[16] = {0}; // interleaved stereo
if (address) { if (address)
for (int i = 0; i < 16; i++) { {
for (int i = 0; i < 16; i++)
{
samples[i] = Memory_Read_U16(address + i * 2); 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); Mixer_PushSamples(samples, 32 / 4, sample_rate);
} }
/*static int counter = 0; /* If I don't use this in Wario Land Shake It I get bad sound, it's a lot of static and noise
counter++; in the sound. It's the same both with an without Enable Other Audio. I can't really say why
if ((counter & 255) == 0)*/ 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 // SoundStream is updated only when necessary (there is no 70 ms limit
// so each sample now triggers the sound stream) // so each sample now triggers the sound stream)
soundStream->Update(); soundStream->Update();
} }
/////////////////////////////////////

View File

@ -17,12 +17,13 @@
#ifndef __MAIN_H__ #ifndef __MAIN_H__
#define __MAIN_H__ #define __MAIN_H__
#include "PCHW/SoundStream.h" #include "PCHW/SoundStream.h"
#include "Globals.h" // Local #include "Globals.h" // Local
#if defined(HAVE_WX) && HAVE_WX #if defined(HAVE_WX) && HAVE_WX
#include "Debugger/Debugger.h" #include "Debugger/Debugger.h"
extern CDebugger* m_frame; extern CDebugger* m_frame;
#endif #endif
extern SoundStream *soundStream; extern SoundStream *soundStream;