mirror of https://github.com/odrling/Aegisub
Add support for delay in FFmpegSourceAudioProvider as FFMS2 only handles it automatically in the avisynth plugin
Originally committed to SVN as r4828.
This commit is contained in:
parent
a73091ef5c
commit
50f8389615
|
@ -184,8 +184,9 @@ void FFmpegSourceAudioProvider::LoadAudio(wxString filename) {
|
||||||
|
|
||||||
channels = AudioInfo.Channels;
|
channels = AudioInfo.Channels;
|
||||||
sample_rate = AudioInfo.SampleRate;
|
sample_rate = AudioInfo.SampleRate;
|
||||||
num_samples = AudioInfo.NumSamples;
|
delay = AudioInfo.FirstTime * sample_rate;
|
||||||
if (channels <= 0 || sample_rate <= 0 || num_samples <= 0)
|
num_samples = AudioInfo.NumSamples + delay;
|
||||||
|
if (channels <= 0 || sample_rate <= 0 || num_samples <= 0 || delay < 0)
|
||||||
throw AudioOpenError("sanity check failed, consult your local psychiatrist");
|
throw AudioOpenError("sanity check failed, consult your local psychiatrist");
|
||||||
|
|
||||||
// FIXME: use the actual sample format too?
|
// FIXME: use the actual sample format too?
|
||||||
|
@ -222,7 +223,19 @@ void FFmpegSourceAudioProvider::Close() {
|
||||||
/// @param Count
|
/// @param Count
|
||||||
///
|
///
|
||||||
void FFmpegSourceAudioProvider::GetAudio(void *Buf, int64_t Start, int64_t Count) {
|
void FFmpegSourceAudioProvider::GetAudio(void *Buf, int64_t Start, int64_t Count) {
|
||||||
if (FFMS_GetAudio(AudioSource, Buf, Start, Count, &ErrInfo)) {
|
uint8_t *Buf2 = static_cast<uint8_t*>(Buf);
|
||||||
|
Start -= delay;
|
||||||
|
if (Start < 0) {
|
||||||
|
size_t Bytes = std::min(-Start, Count) * bytes_per_sample * channels;
|
||||||
|
memset(Buf2, 0, Bytes);
|
||||||
|
|
||||||
|
Count += Start;
|
||||||
|
if (Count <= 0) return;
|
||||||
|
|
||||||
|
Start = 0;
|
||||||
|
Buf2 += Bytes;
|
||||||
|
}
|
||||||
|
if (FFMS_GetAudio(AudioSource, Buf2, Start, Count, &ErrInfo)) {
|
||||||
throw AudioDecodeError(std::string("Failed to get audio samples: ") + ErrInfo.Buffer);
|
throw AudioDecodeError(std::string("Failed to get audio samples: ") + ErrInfo.Buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,15 +43,18 @@
|
||||||
/// @brief Implements audio loading with the FFMS library.
|
/// @brief Implements audio loading with the FFMS library.
|
||||||
class FFmpegSourceAudioProvider : public AudioProvider, FFmpegSourceProvider {
|
class FFmpegSourceAudioProvider : public AudioProvider, FFmpegSourceProvider {
|
||||||
private:
|
private:
|
||||||
FFMS_AudioSource *AudioSource; /// audio source object
|
FFMS_AudioSource *AudioSource; ///< audio source object
|
||||||
bool COMInited; /// COM initialization state
|
bool COMInited; ///< COM initialization state
|
||||||
|
|
||||||
char FFMSErrMsg[1024]; /// FFMS error message
|
char FFMSErrMsg[1024]; ///< FFMS error message
|
||||||
FFMS_ErrorInfo ErrInfo; /// FFMS error codes/messages
|
FFMS_ErrorInfo ErrInfo; ///< FFMS error codes/messages
|
||||||
|
|
||||||
void Close();
|
void Close();
|
||||||
void LoadAudio(wxString filename);
|
void LoadAudio(wxString filename);
|
||||||
|
|
||||||
|
/// Audio delay in samples
|
||||||
|
int64_t delay;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FFmpegSourceAudioProvider(wxString filename);
|
FFmpegSourceAudioProvider(wxString filename);
|
||||||
virtual ~FFmpegSourceAudioProvider();
|
virtual ~FFmpegSourceAudioProvider();
|
||||||
|
|
Loading…
Reference in New Issue