Added debug-builds-only dummy audio provider (can provide either blank or noise audio.)

Originally committed to SVN as r1436.
This commit is contained in:
Niels Martin Hansen 2007-07-23 15:19:48 +00:00
parent 2134cb4ba8
commit 742240b5d8
6 changed files with 176 additions and 4 deletions

View file

@ -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();

View file

@ -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;
}
}

View file

@ -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);
};

View file

@ -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

View file

@ -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,

View file

@ -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