mirror of https://github.com/odrling/Aegisub
Audio crash in 1.09 fix(?) and small cleanup
Originally committed to SVN as r17.
This commit is contained in:
parent
a1bf8a221e
commit
1cd44a438d
|
@ -66,7 +66,7 @@ private:
|
||||||
__int64 PositionSample;
|
__int64 PositionSample;
|
||||||
float scale;
|
float scale;
|
||||||
int samples;
|
int samples;
|
||||||
int Position;
|
__int64 Position;
|
||||||
int samplesPercent;
|
int samplesPercent;
|
||||||
int oldCurPos;
|
int oldCurPos;
|
||||||
bool hasFocus;
|
bool hasFocus;
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
#include <wx/filename.h>
|
#include <wx/filename.h>
|
||||||
#include <Mmreg.h>
|
#include <Mmreg.h>
|
||||||
#include "avisynth_wrap.h"
|
#include "avisynth_wrap.h"
|
||||||
|
#include "utils.h"
|
||||||
#include "audio_provider.h"
|
#include "audio_provider.h"
|
||||||
#include "video_display.h"
|
#include "video_display.h"
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
|
@ -51,15 +52,6 @@ extern "C" {
|
||||||
#include <portaudio.h>
|
#include <portaudio.h>
|
||||||
}
|
}
|
||||||
|
|
||||||
//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;
|
int AudioProvider::pa_refcount = 0;
|
||||||
|
|
||||||
//////////////
|
//////////////
|
||||||
|
@ -222,30 +214,28 @@ void AudioProvider::ConvertToRAMCache(PClip &tempclip) {
|
||||||
blockcache[i] = NULL;
|
blockcache[i] = NULL;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (int i = 0; i < blockcount - 1; i++)
|
for (int i = 0; i < blockcount; i++)
|
||||||
blockcache[i] = new char[CacheBlockSize];
|
blockcache[i] = new char[MIN(CacheBlockSize,ssize-i*CacheBlockSize)];
|
||||||
blockcache[blockcount-1] = new char[ssize-(blockcount-1)*CacheBlockSize];
|
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
for (int i = 0; i < blockcount; i++)
|
for (int i = 0; i < blockcount; i++)
|
||||||
if (blockcache[i])
|
delete blockcache[i];
|
||||||
delete blockcache[i];
|
|
||||||
delete blockcache;
|
delete blockcache;
|
||||||
|
|
||||||
blockcache = NULL;
|
blockcache = NULL;
|
||||||
blockcount = 0;
|
blockcount = 0;
|
||||||
|
|
||||||
if (wxMessageBox(_("Not enough ram available. Use disk cache instead?"),_("Audio Information"),wxICON_INFORMATION | wxYES_NO) == wxYES) {
|
if (wxMessageBox(_("Not enough ram available. Use disk cache instead?"),_("Audio Information"),wxICON_INFORMATION | wxYES_NO) == wxYES) {
|
||||||
ConvertToDiskCache(tempclip);
|
ConvertToDiskCache(tempclip);
|
||||||
return;
|
return;
|
||||||
} else
|
} else
|
||||||
throw wxString(_T("Couldn't open audio, not enough ram available."));
|
throw wxString(_T("Couldn't open audio, not enough ram available."));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start progress
|
// Start progress
|
||||||
volatile bool canceled = false;
|
volatile bool canceled = false;
|
||||||
DialogProgress *progress = new DialogProgress(NULL,_("Load audio"),&canceled,_("Reading into RAM"),0,num_samples);
|
DialogProgress *progress = new DialogProgress(NULL,_("Load audio"),&canceled,_("Reading into RAM"),0,num_samples);
|
||||||
progress->Show();
|
progress->Show();
|
||||||
progress->SetProgress(0,blockcount-1);
|
progress->SetProgress(0,1);
|
||||||
|
|
||||||
// Read cache
|
// Read cache
|
||||||
int readsize = CacheBlockSize / bytes_per_sample;
|
int readsize = CacheBlockSize / bytes_per_sample;
|
||||||
|
@ -344,15 +334,21 @@ void AudioProvider::GetAudio(void *buf, __int64 start, __int64 count) {
|
||||||
|
|
||||||
// RAM Cache
|
// RAM Cache
|
||||||
if (type == AUDIO_PROVIDER_CACHE) {
|
if (type == AUDIO_PROVIDER_CACHE) {
|
||||||
int startblock = (start*bytes_per_sample) >> CacheBits;
|
int i = (start*bytes_per_sample) >> CacheBits;
|
||||||
int endblock = (min(start+count, num_samples)*bytes_per_sample) >> CacheBits;
|
int start_offset = (start*bytes_per_sample) & (CacheBlockSize-1);
|
||||||
__int64 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;
|
charbuf+=readsize;
|
||||||
start_offset = 0;
|
|
||||||
|
start_offset=0;
|
||||||
|
bytesremaining-=readsize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,6 @@ class AudioDisplay;
|
||||||
enum AudioProviderType {
|
enum AudioProviderType {
|
||||||
AUDIO_PROVIDER_NONE,
|
AUDIO_PROVIDER_NONE,
|
||||||
AUDIO_PROVIDER_AVS,
|
AUDIO_PROVIDER_AVS,
|
||||||
AUDIO_PROVIDER_VIDEO,
|
|
||||||
AUDIO_PROVIDER_CACHE,
|
AUDIO_PROVIDER_CACHE,
|
||||||
AUDIO_PROVIDER_DISK_CACHE
|
AUDIO_PROVIDER_DISK_CACHE
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue