From 742240b5d8a311c4fcb6bc6ab390f988cb8e2d52 Mon Sep 17 00:00:00 2001 From: Niels Martin Hansen Date: Mon, 23 Jul 2007 15:19:48 +0000 Subject: [PATCH] Added debug-builds-only dummy audio provider (can provide either blank or noise audio.) Originally committed to SVN as r1436. --- aegisub/audio_display.cpp | 26 ++++++++++-- aegisub/audio_provider_dummy.cpp | 73 ++++++++++++++++++++++++++++++++ aegisub/audio_provider_dummy.h | 56 ++++++++++++++++++++++++ aegisub/frame_main.cpp | 4 ++ aegisub/frame_main.h | 8 ++++ aegisub/frame_main_events.cpp | 13 ++++++ 6 files changed, 176 insertions(+), 4 deletions(-) create mode 100644 aegisub/audio_provider_dummy.cpp create mode 100644 aegisub/audio_provider_dummy.h diff --git a/aegisub/audio_display.cpp b/aegisub/audio_display.cpp index 276c3c215..2c21994e4 100644 --- a/aegisub/audio_display.cpp +++ b/aegisub/audio_display.cpp @@ -58,6 +58,9 @@ #include "utils.h" #include "timeedit_ctrl.h" #include "standard_paths.h" +#ifdef _DEBUG +#include "audio_provider_dummy.h" +#endif /////////////// @@ -827,7 +830,20 @@ void AudioDisplay::SetFile(wxString file) { try { // Get provider wxLogDebug(_T("AudioDisplay::SetFile: get audio provider")); + bool is_dummy = false; +#ifdef _DEBUG + if (file == _T("?dummy")) { + is_dummy = true; + provider = new DummyAudioProvider(150*60*1000, false); // 150 minutes non-noise + } else if (file == _T("?noise")) { + is_dummy = true; + provider = new DummyAudioProvider(150*60*1000, true); // 150 minutes noise + } else { + provider = AudioProviderFactory::GetAudioProvider(file); + } +#else provider = AudioProviderFactory::GetAudioProvider(file); +#endif // Get player wxLogDebug(_T("AudioDisplay::SetFile: get audio player")); @@ -838,10 +854,12 @@ void AudioDisplay::SetFile(wxString file) { loaded = true; // Add to recent - wxLogDebug(_T("AudioDisplay::SetFile: add to recent")); - Options.AddToRecentList(file,_T("Recent aud")); - wxFileName fn(file); - StandardPaths::SetPathValue(_T("?audio"),fn.GetPath()); + if (!is_dummy) { + wxLogDebug(_T("AudioDisplay::SetFile: add to recent")); + Options.AddToRecentList(file,_T("Recent aud")); + wxFileName fn(file); + StandardPaths::SetPathValue(_T("?audio"),fn.GetPath()); + } // Update UpdateImage(); diff --git a/aegisub/audio_provider_dummy.cpp b/aegisub/audio_provider_dummy.cpp new file mode 100644 index 000000000..40384b068 --- /dev/null +++ b/aegisub/audio_provider_dummy.cpp @@ -0,0 +1,73 @@ +// Copyright (c) 2005-2006, Rodrigo Braz Monteiro, Fredrik Mellbin +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of the Aegisub Group nor the names of its contributors +// may be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB +// +// Website: http://aegisub.cellosoft.com +// Contact: mailto:zeratul@cellosoft.com +// + + +/////////// +// Headers +#include "audio_provider_dummy.h" +#include "utils.h" + + +/////////////// +// Constructor +DummyAudioProvider::DummyAudioProvider(unsigned long dur_ms, bool _noise) { + noise = _noise; + channels = 1; + sample_rate = 44100; + bytes_per_sample = 2; + num_samples = (__int64)dur_ms * sample_rate / 1000; +} + + +////////////// +// Destructor +DummyAudioProvider::~DummyAudioProvider() { +} + + +///////////// +// Get audio +void DummyAudioProvider::GetAudio(void *buf, __int64 start, __int64 count) { + short *workbuf = (short*)buf; + + if (noise) { + while (--count > 0) + *workbuf++ = (rand() - RAND_MAX/2) * 10000 / RAND_MAX; + } + else { + while (--count > 0) + *workbuf++ = 0; + } +} diff --git a/aegisub/audio_provider_dummy.h b/aegisub/audio_provider_dummy.h new file mode 100644 index 000000000..4a977861d --- /dev/null +++ b/aegisub/audio_provider_dummy.h @@ -0,0 +1,56 @@ +// Copyright (c) 2006, Niels Martin Hansen +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of the Aegisub Group nor the names of its contributors +// may be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB +// +// Website: http://aegisub.cellosoft.com +// Contact: mailto:zeratul@cellosoft.com +// + + +#pragma once + + +/////////// +// Headers +#include "audio_provider.h" + + +//////////////////////// +// Audio provider class +class DummyAudioProvider : public AudioProvider { +private: + bool noise; + +public: + DummyAudioProvider(unsigned long dur_ms, bool _noise); + ~DummyAudioProvider(); + + void GetAudio(void *buf, __int64 start, __int64 count); +}; diff --git a/aegisub/frame_main.cpp b/aegisub/frame_main.cpp index 507e6f4d6..318e4fa89 100644 --- a/aegisub/frame_main.cpp +++ b/aegisub/frame_main.cpp @@ -409,6 +409,10 @@ void FrameMain::InitMenu() { audioMenu->Append(Menu_Audio_Close, _("&Close Audio"), _("Closes the currently open audio file")); wxMenuItem *RecentAudParent = new wxMenuItem(audioMenu, Menu_File_Recent_Auds_Parent, _("Recent"), _T(""), wxITEM_NORMAL, RecentAuds); audioMenu->Append(RecentAudParent); +#ifdef _DEBUG + audioMenu->Append(Menu_Audio_Open_Dummy, _T("Open 2h30 blank audio"), _T("Open a 150 minutes blank audio clip, for debugging")); + audioMenu->Append(Menu_Audio_Open_Dummy_Noise, _T("Open 2h30 noise audio"), _T("Open a 150 minutes noise-filled audio clip, for debugging")); +#endif MenuBar->Append(audioMenu, _("&Audio")); // Create Automation menu diff --git a/aegisub/frame_main.h b/aegisub/frame_main.h index 681f3d7f3..16c67eed2 100644 --- a/aegisub/frame_main.h +++ b/aegisub/frame_main.h @@ -166,6 +166,10 @@ private: void OnOpenAudio (wxCommandEvent &event); void OnOpenAudioFromVideo (wxCommandEvent &event); void OnCloseAudio (wxCommandEvent &event); +#ifdef _DEBUG + void OnOpenDummyAudio(wxCommandEvent &event); + void OnOpenDummyNoiseAudio(wxCommandEvent &event); +#endif void OnChooseLanguage (wxCommandEvent &event); void OnPickAssociations (wxCommandEvent &event); @@ -326,6 +330,10 @@ enum { Menu_Audio_Open_File, Menu_Audio_Open_From_Video, Menu_Audio_Close, +#ifdef _DEBUG + Menu_Audio_Open_Dummy, + Menu_Audio_Open_Dummy_Noise, +#endif Menu_Edit_Select, Menu_Edit_Undo, diff --git a/aegisub/frame_main_events.cpp b/aegisub/frame_main_events.cpp index 818e407a6..bacff13b5 100644 --- a/aegisub/frame_main_events.cpp +++ b/aegisub/frame_main_events.cpp @@ -140,6 +140,10 @@ BEGIN_EVENT_TABLE(FrameMain, wxFrame) EVT_MENU(Menu_Audio_Open_File, FrameMain::OnOpenAudio) EVT_MENU(Menu_Audio_Open_From_Video, FrameMain::OnOpenAudioFromVideo) EVT_MENU(Menu_Audio_Close, FrameMain::OnCloseAudio) +#ifdef _DEBUG + EVT_MENU(Menu_Audio_Open_Dummy, FrameMain::OnOpenDummyAudio) + EVT_MENU(Menu_Audio_Open_Dummy_Noise, FrameMain::OnOpenDummyNoiseAudio) +#endif EVT_MENU(Menu_Edit_Undo, FrameMain::OnUndo) EVT_MENU(Menu_Edit_Redo, FrameMain::OnRedo) @@ -614,6 +618,15 @@ void FrameMain::OnCloseAudio (wxCommandEvent& WXUNUSED(event)) { LoadAudio(_T("")); } +#ifdef _DEBUG +void FrameMain::OnOpenDummyAudio (wxCommandEvent& WXUNUSED(event)) { + LoadAudio(_T("?dummy")); +} +void FrameMain::OnOpenDummyNoiseAudio (wxCommandEvent& WXUNUSED(event)) { + LoadAudio(_T("?noise")); +} +#endif + ////////////////// // Open subtitles