From 1cd44a438dae7c90a056d7682733776519a8ec02 Mon Sep 17 00:00:00 2001 From: Fredrik Mellbin Date: Sat, 21 Jan 2006 01:09:53 +0000 Subject: [PATCH] Audio crash in 1.09 fix(?) and small cleanup Originally committed to SVN as r17. --- core/audio_display.h | 2 +- core/audio_provider.cpp | 48 +++++++++++++++++++---------------------- core/audio_provider.h | 1 - 3 files changed, 23 insertions(+), 28 deletions(-) diff --git a/core/audio_display.h b/core/audio_display.h index 3dcd739a7..6b4ee48cc 100644 --- a/core/audio_display.h +++ b/core/audio_display.h @@ -66,7 +66,7 @@ private: __int64 PositionSample; float scale; int samples; - int Position; + __int64 Position; int samplesPercent; int oldCurPos; bool hasFocus; diff --git a/core/audio_provider.cpp b/core/audio_provider.cpp index 227afb64a..aa6b54272 100644 --- a/core/audio_provider.cpp +++ b/core/audio_provider.cpp @@ -40,6 +40,7 @@ #include #include #include "avisynth_wrap.h" +#include "utils.h" #include "audio_provider.h" #include "video_display.h" #include "options.h" @@ -51,15 +52,6 @@ extern "C" { #include } -//stupid msvc -#ifndef max -#define max(a,b) (((a) > (b)) ? (a) : (b)) -#endif - -#ifndef min -#define min(a,b) (((a) < (b)) ? (a) : (b)) -#endif - int AudioProvider::pa_refcount = 0; ////////////// @@ -222,30 +214,28 @@ void AudioProvider::ConvertToRAMCache(PClip &tempclip) { blockcache[i] = NULL; try { - for (int i = 0; i < blockcount - 1; i++) - blockcache[i] = new char[CacheBlockSize]; - blockcache[blockcount-1] = new char[ssize-(blockcount-1)*CacheBlockSize]; + for (int i = 0; i < blockcount; i++) + blockcache[i] = new char[MIN(CacheBlockSize,ssize-i*CacheBlockSize)]; } catch (...) { for (int i = 0; i < blockcount; i++) - if (blockcache[i]) - delete blockcache[i]; + delete blockcache[i]; delete blockcache; blockcache = NULL; blockcount = 0; if (wxMessageBox(_("Not enough ram available. Use disk cache instead?"),_("Audio Information"),wxICON_INFORMATION | wxYES_NO) == wxYES) { - ConvertToDiskCache(tempclip); - return; - } else - throw wxString(_T("Couldn't open audio, not enough ram available.")); + ConvertToDiskCache(tempclip); + return; + } else + throw wxString(_T("Couldn't open audio, not enough ram available.")); } // Start progress volatile bool canceled = false; DialogProgress *progress = new DialogProgress(NULL,_("Load audio"),&canceled,_("Reading into RAM"),0,num_samples); progress->Show(); - progress->SetProgress(0,blockcount-1); + progress->SetProgress(0,1); // Read cache int readsize = CacheBlockSize / bytes_per_sample; @@ -344,15 +334,21 @@ void AudioProvider::GetAudio(void *buf, __int64 start, __int64 count) { // RAM Cache if (type == AUDIO_PROVIDER_CACHE) { - int startblock = (start*bytes_per_sample) >> CacheBits; - int endblock = (min(start+count, num_samples)*bytes_per_sample) >> CacheBits; - __int64 start_offset = (start*bytes_per_sample) & (CacheBlockSize-1); + int i = (start*bytes_per_sample) >> CacheBits; + int start_offset = (start*bytes_per_sample) & (CacheBlockSize-1); + + __int64 bytesremaining = count*bytes_per_sample; + + while (bytesremaining) { + int readsize=MIN(bytesremaining,CacheBlockSize); + readsize = MIN(readsize,CacheBlockSize - start_offset); + + memcpy(charbuf,(char *)(blockcache[i++]+start_offset),readsize); - for (int i = startblock; i <= endblock; i++) { - int readsize = min((i+1)*CacheBlockSize,(start+count)*bytes_per_sample) - max(i*CacheBlockSize,start*bytes_per_sample); - memcpy(charbuf,(char *)blockcache[i]+start_offset,readsize); charbuf+=readsize; - start_offset = 0; + + start_offset=0; + bytesremaining-=readsize; } } diff --git a/core/audio_provider.h b/core/audio_provider.h index 46da3e9e9..5361ba4f5 100644 --- a/core/audio_provider.h +++ b/core/audio_provider.h @@ -56,7 +56,6 @@ class AudioDisplay; enum AudioProviderType { AUDIO_PROVIDER_NONE, AUDIO_PROVIDER_AVS, - AUDIO_PROVIDER_VIDEO, AUDIO_PROVIDER_CACHE, AUDIO_PROVIDER_DISK_CACHE };