forked from mia/Aegisub
Very early abstraction of audio classes
Originally committed to SVN as r167.
This commit is contained in:
parent
3063d40e5f
commit
68431d0c1a
5 changed files with 187 additions and 45 deletions
85
core/audio_player.cpp
Normal file
85
core/audio_player.cpp
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
// Copyright (c) 2005, Rodrigo Braz Monteiro
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without
|
||||||
|
// modification, are permitted provided that the following conditions are met:
|
||||||
|
//
|
||||||
|
// * Redistributions of source code must retain the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer.
|
||||||
|
// * Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer in the documentation
|
||||||
|
// and/or other materials provided with the distribution.
|
||||||
|
// * Neither the name of the Aegisub Group nor the names of its contributors
|
||||||
|
// may be used to endorse or promote products derived from this software
|
||||||
|
// without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||||
|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
// POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// AEGISUB
|
||||||
|
//
|
||||||
|
// Website: http://aegisub.cellosoft.com
|
||||||
|
// Contact: mailto:zeratul@cellosoft.com
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
///////////
|
||||||
|
// Headers
|
||||||
|
#include <wx/wxprec.h>
|
||||||
|
#include "audio_player.h"
|
||||||
|
#include "audio_provider.h"
|
||||||
|
|
||||||
|
|
||||||
|
///////////////
|
||||||
|
// Constructor
|
||||||
|
AudioPlayer::AudioPlayer() {
|
||||||
|
provider = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//////////////
|
||||||
|
// Destructor
|
||||||
|
AudioPlayer::~AudioPlayer() {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////
|
||||||
|
// Set provider
|
||||||
|
void AudioPlayer::SetProvider(AudioProvider *_provider) {
|
||||||
|
provider = _provider;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////
|
||||||
|
// Ask to stop later
|
||||||
|
void AudioPlayer::RequestStop() {
|
||||||
|
wxCommandEvent event(wxEVT_STOP_AUDIO, 1000);
|
||||||
|
event.SetEventObject(this);
|
||||||
|
wxMutexGuiEnter();
|
||||||
|
AddPendingEvent(event);
|
||||||
|
wxMutexGuiLeave();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/////////
|
||||||
|
// Event
|
||||||
|
DEFINE_EVENT_TYPE(wxEVT_STOP_AUDIO)
|
||||||
|
|
||||||
|
BEGIN_EVENT_TABLE(AudioPlayer, wxEvtHandler)
|
||||||
|
EVT_COMMAND (1000, wxEVT_STOP_AUDIO, AudioPlayer::OnStopAudio)
|
||||||
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
|
void AudioPlayer::OnStopAudio(wxCommandEvent &event) {
|
||||||
|
Stop(false);
|
||||||
|
}
|
84
core/audio_player.h
Normal file
84
core/audio_player.h
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
// Copyright (c) 2005, Rodrigo Braz Monteiro
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without
|
||||||
|
// modification, are permitted provided that the following conditions are met:
|
||||||
|
//
|
||||||
|
// * Redistributions of source code must retain the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer.
|
||||||
|
// * Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer in the documentation
|
||||||
|
// and/or other materials provided with the distribution.
|
||||||
|
// * Neither the name of the Aegisub Group nor the names of its contributors
|
||||||
|
// may be used to endorse or promote products derived from this software
|
||||||
|
// without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||||
|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
// POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// AEGISUB
|
||||||
|
//
|
||||||
|
// Website: http://aegisub.cellosoft.com
|
||||||
|
// Contact: mailto:zeratul@cellosoft.com
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
|
||||||
|
///////////
|
||||||
|
// Headers
|
||||||
|
#include <wx/wxprec.h>
|
||||||
|
|
||||||
|
|
||||||
|
//////////////
|
||||||
|
// Prototypes
|
||||||
|
class AudioProvider;
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////
|
||||||
|
// Audio Player base class
|
||||||
|
class AudioPlayer : public wxEvtHandler {
|
||||||
|
private:
|
||||||
|
void OnStopAudio(wxCommandEvent &event);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
AudioProvider *provider;
|
||||||
|
|
||||||
|
public:
|
||||||
|
AudioPlayer();
|
||||||
|
virtual ~AudioPlayer();
|
||||||
|
|
||||||
|
virtual void Play(__int64 start,__int64 count)=0; // Play sample range
|
||||||
|
virtual void Stop(bool timerToo=true)=0; // Stop playing
|
||||||
|
virtual void RequestStop(); // Request it to stop playing in a thread-safe way
|
||||||
|
|
||||||
|
virtual void SetVolume(double volume)=0;
|
||||||
|
virtual double GetVolume()=0;
|
||||||
|
|
||||||
|
void SetProvider(AudioProvider *provider);
|
||||||
|
|
||||||
|
virtual __int64 GetEndPosition()=0;
|
||||||
|
virtual __int64 GetCurrentPosition()=0;
|
||||||
|
virtual void SetEndPosition(__int64 pos)=0;
|
||||||
|
virtual void SetCurrentPosition(__int64 pos)=0;
|
||||||
|
|
||||||
|
DECLARE_EVENT_TABLE()
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/////////
|
||||||
|
// Event
|
||||||
|
DECLARE_EVENT_TYPE(wxEVT_STOP_AUDIO, -1)
|
||||||
|
|
|
@ -581,26 +581,3 @@ void AudioProvider::CloseStream() {
|
||||||
Pa_CloseStream(stream);
|
Pa_CloseStream(stream);
|
||||||
} catch (...) {}
|
} catch (...) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////
|
|
||||||
// Ask to stop later
|
|
||||||
void AudioProvider::RequestStop() {
|
|
||||||
wxCommandEvent event(wxEVT_STOP_AUDIO, 1000);
|
|
||||||
event.SetEventObject(this);
|
|
||||||
wxMutexGuiEnter();
|
|
||||||
AddPendingEvent(event);
|
|
||||||
wxMutexGuiLeave();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/////////
|
|
||||||
// Event
|
|
||||||
DEFINE_EVENT_TYPE(wxEVT_STOP_AUDIO)
|
|
||||||
|
|
||||||
BEGIN_EVENT_TABLE(AudioProvider, wxEvtHandler)
|
|
||||||
EVT_COMMAND (1000, wxEVT_STOP_AUDIO, AudioProvider::OnStopAudio)
|
|
||||||
END_EVENT_TABLE()
|
|
||||||
|
|
||||||
void AudioProvider::OnStopAudio(wxCommandEvent &event) {
|
|
||||||
Stop(false);
|
|
||||||
}
|
|
||||||
|
|
|
@ -34,16 +34,16 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef AUDIO_PROVIDER_H
|
#pragma once
|
||||||
#define AUDIO_PROVIDER_H
|
|
||||||
|
|
||||||
|
|
||||||
///////////
|
///////////
|
||||||
// Headers
|
// Headers
|
||||||
#include <wx/wxprec.h>
|
#include <wx/wxprec.h>
|
||||||
#include "avisynth_wrap.h"
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include "avisynth_wrap.h"
|
||||||
|
#include "audio_player.h"
|
||||||
|
|
||||||
|
|
||||||
//////////////
|
//////////////
|
||||||
|
@ -63,7 +63,7 @@ enum AudioProviderType {
|
||||||
|
|
||||||
////////////////////////
|
////////////////////////
|
||||||
// Audio provider class
|
// Audio provider class
|
||||||
class AudioProvider : public wxEvtHandler, public AviSynthWrapper {
|
class AudioProvider : public AviSynthWrapper, public AudioPlayer {
|
||||||
private:
|
private:
|
||||||
static int pa_refcount;
|
static int pa_refcount;
|
||||||
|
|
||||||
|
@ -94,11 +94,11 @@ private:
|
||||||
void ConvertToDiskCache(PClip &tempclip);
|
void ConvertToDiskCache(PClip &tempclip);
|
||||||
void LoadFromClip(AVSValue clip);
|
void LoadFromClip(AVSValue clip);
|
||||||
void OpenAVSAudio();
|
void OpenAVSAudio();
|
||||||
void OnStopAudio(wxCommandEvent &event);
|
|
||||||
static wxString DiskCachePath();
|
static wxString DiskCachePath();
|
||||||
static wxString DiskCacheName();
|
static wxString DiskCacheName();
|
||||||
void SetFile();
|
void SetFile();
|
||||||
void Unload();
|
void Unload();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
wxMutex PAMutex;
|
wxMutex PAMutex;
|
||||||
volatile bool stopping;
|
volatile bool stopping;
|
||||||
|
@ -112,7 +112,6 @@ public:
|
||||||
volatile __int64 realPlayPos;
|
volatile __int64 realPlayPos;
|
||||||
volatile __int64 startMS;
|
volatile __int64 startMS;
|
||||||
void *stream;
|
void *stream;
|
||||||
clock_t span;
|
|
||||||
|
|
||||||
AudioProvider(wxString _filename, AudioDisplay *_display);
|
AudioProvider(wxString _filename, AudioDisplay *_display);
|
||||||
~AudioProvider();
|
~AudioProvider();
|
||||||
|
@ -122,21 +121,18 @@ public:
|
||||||
void GetAudio(void *buf, __int64 start, __int64 count);
|
void GetAudio(void *buf, __int64 start, __int64 count);
|
||||||
void GetWaveForm(int *min,int *peak,__int64 start,int w,int h,int samples,float scale);
|
void GetWaveForm(int *min,int *peak,__int64 start,int w,int h,int samples,float scale);
|
||||||
|
|
||||||
void Play(__int64 start,__int64 count);
|
|
||||||
void Stop(bool timerToo=true);
|
|
||||||
void RequestStop();
|
|
||||||
|
|
||||||
int GetChannels();
|
int GetChannels();
|
||||||
__int64 GetNumSamples();
|
__int64 GetNumSamples();
|
||||||
int GetSampleRate();
|
int GetSampleRate();
|
||||||
|
|
||||||
DECLARE_EVENT_TABLE()
|
void Play(__int64 start,__int64 count);
|
||||||
|
void Stop(bool timerToo=true);
|
||||||
|
|
||||||
|
__int64 GetEndPosition() { return endPos; }
|
||||||
|
__int64 GetCurrentPosition() { return realPlayPos; }
|
||||||
|
void SetEndPosition(__int64 pos) { endPos = pos; }
|
||||||
|
void SetCurrentPosition(__int64 pos) { playPos = pos; realPlayPos = pos; }
|
||||||
|
|
||||||
|
void SetVolume(double vol) { volume = vol; }
|
||||||
|
double GetVolume() { return volume; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/////////
|
|
||||||
// Event
|
|
||||||
DECLARE_EVENT_TYPE(wxEVT_STOP_AUDIO, -1)
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -109,9 +109,6 @@ void LAVCVideoProvider::LoadVideo(wxString filename) {
|
||||||
}
|
}
|
||||||
if (vidStream == -1) throw _T("Could not find a video stream");
|
if (vidStream == -1) throw _T("Could not find a video stream");
|
||||||
|
|
||||||
// Check length
|
|
||||||
if (stream->duration <= 0) throw _T("Returned invalid stream length");
|
|
||||||
|
|
||||||
// Find codec
|
// Find codec
|
||||||
codec = avcodec_find_decoder(codecContext->codec_id);
|
codec = avcodec_find_decoder(codecContext->codec_id);
|
||||||
if (!codec) throw _T("Could not find suitable video decoder");
|
if (!codec) throw _T("Could not find suitable video decoder");
|
||||||
|
@ -123,6 +120,9 @@ void LAVCVideoProvider::LoadVideo(wxString filename) {
|
||||||
result = avcodec_open(codecContext,codec);
|
result = avcodec_open(codecContext,codec);
|
||||||
if (result < 0) throw _T("Failed to open video decoder");
|
if (result < 0) throw _T("Failed to open video decoder");
|
||||||
|
|
||||||
|
// Check length
|
||||||
|
if (stream->duration <= 0) throw _T("Returned invalid stream length");
|
||||||
|
|
||||||
// Set size
|
// Set size
|
||||||
dar = double(GetSourceWidth()) / GetSourceHeight();
|
dar = double(GetSourceWidth()) / GetSourceHeight();
|
||||||
UpdateDisplaySize();
|
UpdateDisplaySize();
|
||||||
|
|
Loading…
Reference in a new issue