Some code cleanup

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2768 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
omegadox
2009-03-28 08:57:34 +00:00
parent bdabcd4bf5
commit eb0cab140f
258 changed files with 936 additions and 1275 deletions

View File

@ -15,8 +15,8 @@
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#ifndef __AOSOUNDSTREAM_H__
#define __AOSOUNDSTREAM_H__
#ifndef _AOSOUNDSTREAM_H_
#define _AOSOUNDSTREAM_H_
#include "SoundStream.h"
@ -69,4 +69,4 @@ public:
#endif
};
#endif //__AOSOUNDSTREAM_H__
#endif //_AOSOUNDSTREAM_H_

View File

@ -1,87 +1,104 @@
#include "AudioCommon.h"
#include "Mixer.h"
#include "AOSoundStream.h"
#include "DSoundStream.h"
#include "NullSoundStream.h"
#include "OpenALStream.h"
namespace AudioCommon {
SoundStream *InitSoundStream(std::string backend, CMixer *mixer) {
if (!mixer) {
mixer = new CMixer();
}
if (backend == "DSound") {
if (DSound::isValid())
soundStream = new DSound(mixer, g_dspInitialize.hWnd);
}
else if (backend == "AOSound") {
if (AOSound::isValid())
soundStream = new AOSound(mixer);
}
else if (backend == "OpenAL") {
if (OpenALStream::isValid())
soundStream = new OpenALStream(mixer);
}
else if (backend == "NullSound") {
soundStream = new NullSound(mixer);
}
else {
PanicAlert("Cannot recognize backend %s", backend.c_str());
return NULL;
}
if (soundStream) {
if (!soundStream->Start()) {
PanicAlert("Could not initialize backend %s, falling back to NULL",
backend.c_str());
delete soundStream;
soundStream = new NullSound(mixer);
soundStream->Start();
}
}
else {
PanicAlert("Sound backend %s is not valid, falling back to NULL",
backend.c_str());
delete soundStream;
soundStream = new NullSound(mixer);
soundStream->Start();
}
return soundStream;
}
void ShutdownSoundStream() {
NOTICE_LOG(DSPHLE, "Shutting down sound stream");
if (soundStream) {
soundStream->Stop();
soundStream->StopLogAudio();
delete soundStream;
soundStream = NULL;
}
// Check that soundstream already is stopped.
while (soundStream) {
ERROR_LOG(DSPHLE, "Waiting for sound stream");
Common::SleepCurrentThread(2000);
}
INFO_LOG(DSPHLE, "Done shutting down sound stream");
}
std::vector<std::string> GetSoundBackends() {
std::vector<std::string> backends;
// Add avaliable output options
if (DSound::isValid())
backends.push_back("DSound");
if (AOSound::isValid())
backends.push_back("AOSound");
if (OpenALStream::isValid())
backends.push_back("OpenAL");
backends.push_back("NullSound");
return backends;
}
} // Namespace
// Copyright (C) 2003-2009 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/
#include "AudioCommon.h"
#include "Mixer.h"
#include "AOSoundStream.h"
#include "DSoundStream.h"
#include "NullSoundStream.h"
#include "OpenALStream.h"
namespace AudioCommon
{
SoundStream *InitSoundStream(std::string backend, CMixer *mixer) {
if (!mixer) {
mixer = new CMixer();
}
if (backend == "DSound") {
if (DSound::isValid())
soundStream = new DSound(mixer, g_dspInitialize.hWnd);
}
else if (backend == "AOSound") {
if (AOSound::isValid())
soundStream = new AOSound(mixer);
}
else if (backend == "OpenAL") {
if (OpenALStream::isValid())
soundStream = new OpenALStream(mixer);
}
else if (backend == "NullSound") {
soundStream = new NullSound(mixer);
}
else {
PanicAlert("Cannot recognize backend %s", backend.c_str());
return NULL;
}
if (soundStream) {
if (!soundStream->Start()) {
PanicAlert("Could not initialize backend %s, falling back to NULL",
backend.c_str());
delete soundStream;
soundStream = new NullSound(mixer);
soundStream->Start();
}
}
else {
PanicAlert("Sound backend %s is not valid, falling back to NULL",
backend.c_str());
delete soundStream;
soundStream = new NullSound(mixer);
soundStream->Start();
}
return soundStream;
}
void ShutdownSoundStream() {
NOTICE_LOG(DSPHLE, "Shutting down sound stream");
if (soundStream) {
soundStream->Stop();
soundStream->StopLogAudio();
delete soundStream;
soundStream = NULL;
}
// Check that soundstream already is stopped.
while (soundStream) {
ERROR_LOG(DSPHLE, "Waiting for sound stream");
Common::SleepCurrentThread(2000);
}
INFO_LOG(DSPHLE, "Done shutting down sound stream");
}
std::vector<std::string> GetSoundBackends() {
std::vector<std::string> backends;
// Add avaliable output options
if (DSound::isValid())
backends.push_back("DSound");
if (AOSound::isValid())
backends.push_back("AOSound");
if (OpenALStream::isValid())
backends.push_back("OpenAL");
backends.push_back("NullSound");
return backends;
}
} // Namespace

View File

@ -1,5 +1,22 @@
#ifndef _AUDIO_COMMON_H
#define _AUDIO_COMMON_H
// Copyright (C) 2003-2009 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 _AUDIO_COMMON_H_
#define _AUDIO_COMMON_H_
#include "Common.h"
#include "../../../PluginSpecs/pluginspecs_dsp.h"
@ -17,4 +34,4 @@ namespace AudioCommon {
std::vector<std::string> GetSoundBackends();
} // Namespace
#endif // AUDIO_COMMON
#endif // _AUDIO_COMMON_H_

View File

@ -15,26 +15,22 @@
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#ifndef __DSOUNDSTREAM_H__
#define __DSOUNDSTREAM_H__
#include "SoundStream.h"
#ifndef _DSOUNDSTREAM_H_
#define _DSOUNDSTREAM_H_
#include "SoundStream.h"
#include "Thread.h"
#ifdef _WIN32
#include "stdafx.h"
#include <mmsystem.h>
#include <dsound.h>
#define BUFSIZE 32768
#define MAXWAIT 70 //ms
#define MAXWAIT 70 // miliseconds
#endif
class DSound : public SoundStream
{
#ifdef _WIN32
Common::Thread *thread;
Common::CriticalSection soundCriticalSection;
Common::Event soundSyncEvent;
@ -77,12 +73,6 @@ public:
static bool isValid() { return true; }
virtual bool usesMixer() const { return true; }
virtual void Update();
#else
public:
DSound(CMixer *mixer, void *hWnd = NULL) :
SoundStream(mixer) {}
#endif
};
#endif //__DSOUNDSTREAM_H__
#endif //_DSOUNDSTREAM_H_

View File

@ -1,4 +1,4 @@
// Copyright (C) 2003-2008 Dolphin Project.
// Copyright (C) 2003-2009 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
@ -162,4 +162,3 @@ void CMixer::PushSamples(short *samples, int num_stereo_samples)
}
push_sync.Leave();
}

View File

@ -1,4 +1,4 @@
// Copyright (C) 2003-2008 Dolphin Project.
// Copyright (C) 2003-2009 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
@ -15,8 +15,8 @@
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#ifndef _MIXER_H
#define _MIXER_H
#ifndef _MIXER_H_
#define _MIXER_H_
#include "FixedSizeQueue.h"
@ -42,10 +42,10 @@ public:
void SetThrottle(bool use) { m_throttle = use;}
// FIXME do we need this
// TODO: do we need this
bool IsHLEReady() { return m_HLEready;}
void SetHLEReady(bool ready) { m_HLEready = ready;}
//////
// ---------------------
protected:
int m_sampleRate;
@ -63,5 +63,4 @@ private:
};
#endif
#endif // _MIXER_H_

View File

@ -15,8 +15,8 @@
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#ifndef __NULLSOUNDSTREAM_H__
#define __NULLSOUNDSTREAM_H__
#ifndef _NULLSOUNDSTREAM_H_
#define _NULLSOUNDSTREAM_H_
#include "SoundStream.h"
@ -39,4 +39,4 @@ public:
}
};
#endif //__NULLSOUNDSTREAM_H__
#endif //_NULLSOUNDSTREAM_H_

View File

@ -44,4 +44,4 @@ void OpenALStream::Update()
void OpenALStream::SoundThread()
{
}
}

View File

@ -15,8 +15,9 @@
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#ifndef __OPENALSTREAM_H__
#define __OPENALSTREAM_H__
#ifndef _OPENALSTREAM_H_
#define _OPENALSTREAM_H_
#include "SoundStream.h"
#include "Thread.h"
@ -49,4 +50,4 @@ private:
Common::Event soundSyncEvent;
};
#endif
#endif

View File

@ -15,8 +15,8 @@
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#ifndef __SOUNDSTREAM_H__
#define __SOUNDSTREAM_H__
#ifndef _SOUNDSTREAM_H_
#define _SOUNDSTREAM_H_
#include "Common.h"
#include "Mixer.h"
@ -65,4 +65,4 @@ public:
}
};
#endif
#endif // _SOUNDSTREAM_H_

View File

@ -1,4 +1,4 @@
// Copyright (C) 2003-2008 Dolphin Project.
// Copyright (C) 2003-2009 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
@ -51,26 +51,29 @@ bool WaveFileWriter::Start(const char *filename)
return false;
}
// ---------------------------------------------------------
// -----------------
// Write file header
// ---------------
// -----------------
Write4("RIFF");
Write(100 * 1000 * 1000); // write big value in case the file gets truncated
Write4("WAVE");
Write4("fmt ");
Write(16); // size of fmt block
Write(0x00020001); //two channels, uncompressed
//const u32 sample_rate = 32000;
const u32 sample_rate = 48000;
Write(sample_rate);
Write(sample_rate * 2 * 2); //two channels, 16bit
Write(0x00100004);
Write4("data");
Write(100 * 1000 * 1000 - 32);
// We are now at offset 44
if (ftell(file) != 44)
PanicAlert("wrong offset: %i", ftell(file));
// ---------------------------
return true;
}
@ -79,11 +82,14 @@ void WaveFileWriter::Stop()
{
if (!file)
return;
// u32 file_size = (u32)ftell(file);
// u32 file_size = (u32)ftell(file);
fseek(file, 4, SEEK_SET);
Write(audio_size + 36);
fseek(file, 40, SEEK_SET);
Write(audio_size);
fclose(file);
file = 0;
}
@ -116,9 +122,12 @@ void WaveFileWriter::AddStereoSamplesBE(const short *sample_data, int count)
{
if (!file)
PanicAlert("WaveFileWriter - file not open.");
if (count > BUF_SIZE * 2)
PanicAlert("WaveFileWriter - buffer too small (count = %i).", count);
if (skip_silence) {
if (skip_silence)
{
bool all_zero = true;
for (int i = 0; i < count * 2; i++)
if (sample_data[i])
@ -126,9 +135,10 @@ void WaveFileWriter::AddStereoSamplesBE(const short *sample_data, int count)
if (all_zero)
return;
}
for (int i = 0; i < count * 2; i++) {
for (int i = 0; i < count * 2; i++)
conv_buffer[i] = Common::swap16((u16)sample_data[i]);
}
fwrite(conv_buffer, count * 4, 1, file);
audio_size += count * 4;
}

View File

@ -15,17 +15,18 @@
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
// WaveFileWriter
// Simple utility class to make it easy to write long 16-bit stereo
// ---------------------------------------------------------------------------------
// Class: WaveFileWriter
// Description: Simple utility class to make it easy to write long 16-bit stereo
// audio streams to disk.
// Use Start() to start recording to a file, and AddStereoSamples to add wave data.
// The float variant will convert from -1.0-1.0 range and clamp.
// Alternatively, AddSamplesBE for big endian wave data.
// If Stop is not called when it destructs, the destructor will call Stop().
// ---------------------------------------------------------------------------------
#ifndef _WAVEFILE_H
#define _WAVEFILE_H
#ifndef _WAVEFILE_H_
#define _WAVEFILE_H_
#include <stdio.h>
@ -52,4 +53,4 @@ public:
u32 GetAudioSize() { return audio_size; }
};
#endif // _WAVEFILE_H
#endif // _WAVEFILE_H_