Audio HD cache improvements

Originally committed to SVN as r621.
This commit is contained in:
Rodrigo Braz Monteiro 2006-12-26 03:00:15 +00:00
parent 4a1c778595
commit b54198b721
4 changed files with 39 additions and 15 deletions

View file

@ -37,6 +37,8 @@
///////////
// Headers
#include <wx/filename.h>
#include <wx/file.h>
#include <wx/filefn.h>
#include "dialog_progress.h"
#include "audio_provider_hd.h"
#include "main.h"
@ -63,10 +65,10 @@ HDAudioProvider::HDAudioProvider(AudioProvider *source) {
}
// Open output file
std::ofstream file;
char filename[512];
strcpy(filename,DiskCacheName().mb_str(wxConvLocal));
file.open(filename,std::ios::binary | std::ios::out | std::ios::trunc);
diskCacheFilename = DiskCacheName();
file_cache.Create(diskCacheFilename,true,wxS_DEFAULT);
file_cache.Open(diskCacheFilename,wxFile::read_write);
if (!file_cache.IsOpened()) throw _T("Unable to write to disk cache.");
// Start progress
volatile bool canceled = false;
@ -79,17 +81,17 @@ HDAudioProvider::HDAudioProvider(AudioProvider *source) {
for (__int64 i=0;i<num_samples && !canceled; i+=block) {
if (block+i > num_samples) block = num_samples - i;
source->GetAudio(temp,i,block);
file.write(temp,block * channels * bytes_per_sample);
file_cache.Write(temp,block * channels * bytes_per_sample);
progress->SetProgress(i,num_samples);
}
file.close();
file_cache.Seek(0);
// Finish
if (!canceled) {
progress->Destroy();
file_cache.open(filename,std::ios::binary | std::ios::in);
}
else {
file_cache.Close();
throw wxString(_T("Audio loading cancelled by user"));
}
}
@ -98,8 +100,8 @@ HDAudioProvider::HDAudioProvider(AudioProvider *source) {
//////////////
// Destructor
HDAudioProvider::~HDAudioProvider() {
file_cache.close();
wxRemoveFile(DiskCacheName());
file_cache.Close();
wxRemoveFile(diskCacheFilename);
}
@ -129,8 +131,8 @@ void HDAudioProvider::GetAudio(void *buf, __int64 start, __int64 count) {
if (count) {
wxMutexLocker disklock(diskmutex);
file_cache.seekg(start*bytes_per_sample);
file_cache.read((char*)buf,count*bytes_per_sample*channels);
file_cache.Seek(start*bytes_per_sample);
file_cache.Read((char*)buf,count*bytes_per_sample*channels);
}
}
@ -150,5 +152,24 @@ wxString HDAudioProvider::DiskCachePath() {
///////////////////////////
// Get disk cache filename
wxString HDAudioProvider::DiskCacheName() {
return DiskCachePath() + _T("audio.tmp");
// Get pattern
wxString pattern = Options.AsText(_T("Audio HD Cache Name"));
if (pattern.Find(_T("%02i")) == wxNOT_FOUND) pattern = _T("audio%02i.tmp");
// Try from 00 to 99
for (int i=0;i<100;i++) {
// File exists?
wxString curStringTry = DiskCachePath() + wxString::Format(pattern.c_str(),i);
if (!wxFile::Exists(curStringTry)) return curStringTry;
// Exists, see if it can be opened (disabled because wx doesn't seem to lock the files...)
if (false) {
wxFile test(curStringTry,wxFile::write);
if (test.IsOpened()) {
test.Close();
return curStringTry;
}
}
}
return _T("");
}

View file

@ -40,7 +40,7 @@
///////////
// Headers
#include "audio_provider.h"
#include <fstream>
#include <wx/file.h>
////////////////////////
@ -48,7 +48,8 @@
class HDAudioProvider : public AudioProvider {
private:
wxMutex diskmutex;
std::ifstream file_cache;
wxFile file_cache;
wxString diskCacheFilename;
static wxString DiskCachePath();
static wxString DiskCacheName();

View file

@ -43,7 +43,8 @@ Please visit http://aegisub.net to download latest version
- Improved Syntax Highlighter to include more features of ASS. (AMZ)
- Added an inline Hunspell-based Spell Checker. (AMZ)
- Added an inline MyThes-based Thesaurus. (AMZ)
- Added an option ("Audio HD Cache Location") that allows you to specify where to keep the audio cache. (AMZ)
- Added two options ("Audio HD Cache Location" and "Audio HD Cache Name") that allows you to specify where to keep the audio cache. (AMZ)
- Flexibible audio cache names now allow you to have more than one copy of Aegisub open with audio loaded to HD cache. (AMZ)
= 1.10 beta - 2006.08.07 ===========================

View file

@ -244,6 +244,7 @@ void OptionsManager::LoadDefaults() {
SetInt(_T("Audio Display Height"),100);
SetBool(_T("Audio Spectrum"),false);
SetText(_T("Audio HD Cache Location"),_T("default"));
SetText(_T("Audio HD Cache Name"),_T("audio%02i.tmp"));
SetInt(_T("Timing processor key start before thres"),5);
SetInt(_T("Timing processor key start after thres"),4);