From eb0cab140f4aa4e17cb60e39e7467a36d6bfa97d Mon Sep 17 00:00:00 2001 From: omegadox Date: Sat, 28 Mar 2009 08:57:34 +0000 Subject: Some code cleanup git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2768 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/AudioCommon/Src/AOSoundStream.h | 6 +- Source/Core/AudioCommon/Src/AudioCommon.cpp | 191 ++++++++++++++------------ Source/Core/AudioCommon/Src/AudioCommon.h | 23 +++- Source/Core/AudioCommon/Src/DSoundStream.h | 20 +-- Source/Core/AudioCommon/Src/Mixer.cpp | 3 +- Source/Core/AudioCommon/Src/Mixer.h | 13 +- Source/Core/AudioCommon/Src/NullSoundStream.h | 6 +- Source/Core/AudioCommon/Src/OpenALStream.cpp | 2 +- Source/Core/AudioCommon/Src/OpenALStream.h | 7 +- Source/Core/AudioCommon/Src/SoundStream.h | 6 +- Source/Core/AudioCommon/Src/WaveFile.cpp | 26 ++-- Source/Core/AudioCommon/Src/WaveFile.h | 13 +- 12 files changed, 175 insertions(+), 141 deletions(-) (limited to 'Source/Core/AudioCommon') diff --git a/Source/Core/AudioCommon/Src/AOSoundStream.h b/Source/Core/AudioCommon/Src/AOSoundStream.h index 91f8b12dad..805bd3f9e9 100644 --- a/Source/Core/AudioCommon/Src/AOSoundStream.h +++ b/Source/Core/AudioCommon/Src/AOSoundStream.h @@ -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_ diff --git a/Source/Core/AudioCommon/Src/AudioCommon.cpp b/Source/Core/AudioCommon/Src/AudioCommon.cpp index d9e8f18b3a..fae1a405e0 100644 --- a/Source/Core/AudioCommon/Src/AudioCommon.cpp +++ b/Source/Core/AudioCommon/Src/AudioCommon.cpp @@ -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 GetSoundBackends() { - std::vector 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 GetSoundBackends() { + std::vector 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 diff --git a/Source/Core/AudioCommon/Src/AudioCommon.h b/Source/Core/AudioCommon/Src/AudioCommon.h index a773d8389a..ad043eb6c4 100644 --- a/Source/Core/AudioCommon/Src/AudioCommon.h +++ b/Source/Core/AudioCommon/Src/AudioCommon.h @@ -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 GetSoundBackends(); } // Namespace -#endif // AUDIO_COMMON +#endif // _AUDIO_COMMON_H_ diff --git a/Source/Core/AudioCommon/Src/DSoundStream.h b/Source/Core/AudioCommon/Src/DSoundStream.h index 2c46d81529..e4ceb14143 100644 --- a/Source/Core/AudioCommon/Src/DSoundStream.h +++ b/Source/Core/AudioCommon/Src/DSoundStream.h @@ -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 #include #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_ diff --git a/Source/Core/AudioCommon/Src/Mixer.cpp b/Source/Core/AudioCommon/Src/Mixer.cpp index 5c716e842d..02cea2659c 100644 --- a/Source/Core/AudioCommon/Src/Mixer.cpp +++ b/Source/Core/AudioCommon/Src/Mixer.cpp @@ -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(); } - diff --git a/Source/Core/AudioCommon/Src/Mixer.h b/Source/Core/AudioCommon/Src/Mixer.h index 3106a758f9..433c70c61c 100644 --- a/Source/Core/AudioCommon/Src/Mixer.h +++ b/Source/Core/AudioCommon/Src/Mixer.h @@ -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_ diff --git a/Source/Core/AudioCommon/Src/NullSoundStream.h b/Source/Core/AudioCommon/Src/NullSoundStream.h index 3a129b2cf0..b8a9807725 100644 --- a/Source/Core/AudioCommon/Src/NullSoundStream.h +++ b/Source/Core/AudioCommon/Src/NullSoundStream.h @@ -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_ diff --git a/Source/Core/AudioCommon/Src/OpenALStream.cpp b/Source/Core/AudioCommon/Src/OpenALStream.cpp index 2a929a61e9..306188b10b 100644 --- a/Source/Core/AudioCommon/Src/OpenALStream.cpp +++ b/Source/Core/AudioCommon/Src/OpenALStream.cpp @@ -44,4 +44,4 @@ void OpenALStream::Update() void OpenALStream::SoundThread() { -} \ No newline at end of file +} diff --git a/Source/Core/AudioCommon/Src/OpenALStream.h b/Source/Core/AudioCommon/Src/OpenALStream.h index 98a51504a9..9f9a42819c 100644 --- a/Source/Core/AudioCommon/Src/OpenALStream.h +++ b/Source/Core/AudioCommon/Src/OpenALStream.h @@ -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 \ No newline at end of file +#endif diff --git a/Source/Core/AudioCommon/Src/SoundStream.h b/Source/Core/AudioCommon/Src/SoundStream.h index b107e9be59..0bc8383bd7 100644 --- a/Source/Core/AudioCommon/Src/SoundStream.h +++ b/Source/Core/AudioCommon/Src/SoundStream.h @@ -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_ diff --git a/Source/Core/AudioCommon/Src/WaveFile.cpp b/Source/Core/AudioCommon/Src/WaveFile.cpp index 500cce8fbc..94653300de 100644 --- a/Source/Core/AudioCommon/Src/WaveFile.cpp +++ b/Source/Core/AudioCommon/Src/WaveFile.cpp @@ -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; } diff --git a/Source/Core/AudioCommon/Src/WaveFile.h b/Source/Core/AudioCommon/Src/WaveFile.h index b9a6528155..34b3d21373 100644 --- a/Source/Core/AudioCommon/Src/WaveFile.h +++ b/Source/Core/AudioCommon/Src/WaveFile.h @@ -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 @@ -52,4 +53,4 @@ public: u32 GetAudioSize() { return audio_size; } }; -#endif // _WAVEFILE_H +#endif // _WAVEFILE_H_ -- cgit v1.2.3