Avisynth audio provider will now never deliver audio under 32 kHz, fixing the dsound playback bug.

Originally committed to SVN as r1776.
This commit is contained in:
Rodrigo Braz Monteiro 2008-01-19 02:38:31 +00:00
parent dd3047e571
commit dc6aa3f161
3 changed files with 16 additions and 4 deletions

View File

@ -220,6 +220,9 @@ AudioProvider *AudioProviderFactory::GetAudioProvider(wxString filename, int cac
// Failed
if (!provider) throw error;
// Give it a conversor if needed
if (provider->GetBytesPerSample() != 2) provider = new ConvertAudioProvider(provider);
// Change provider to RAM/HD cache if needed
if (cache == -1) cache = Options.AsInt(_T("Audio Cache"));
if (cache) {
@ -238,9 +241,6 @@ AudioProvider *AudioProviderFactory::GetAudioProvider(wxString filename, int cac
}
}
// Give it a conversor if needed
if (provider && provider->GetBytesPerSample() != 2) provider = new ConvertAudioProvider(provider);
// Return
return provider;
}

View File

@ -175,9 +175,11 @@ void AvisynthAudioProvider::LoadFromClip(AVSValue _clip) {
// Convert to 16 bits per sample
script = env->Invoke("ConvertAudioTo16bit", script);
vi = script.AsClip()->GetVideoInfo();
// Convert sample rate
int setsample = Options.AsInt(_T("Audio Sample Rate"));
if (vi.SamplesPerSecond() < 32000) setsample = 44100;
if (setsample != 0) {
AVSValue args[2] = { script, setsample };
script = env->Invoke("ResampleAudio", AVSValue(args,2));

View File

@ -63,8 +63,11 @@ ConvertAudioProvider::~ConvertAudioProvider() {
/////////////
// Get audio
void ConvertAudioProvider::GetAudio(void *destination, int64_t start, int64_t count) {
// Bits per sample
int srcBps = source->GetBytesPerSample();
// Convert from 8-bit to 16-bit
if (source->GetBytesPerSample() == 1) {
if (srcBps == 1) {
unsigned char *buffer = new unsigned char[count];
source->GetAudio(buffer,start,count);
short temp;
@ -73,5 +76,12 @@ void ConvertAudioProvider::GetAudio(void *destination, int64_t start, int64_t co
temp = (short) buffer[i];
dst[i] = (temp-128)*256+temp;
}
delete [] buffer;
}
// No conversion needed
else if (srcBps == 2) source->GetAudio(destination,start,count);
// Unsupported
else throw _T("Unknown bits per sample value.");
}