forked from mia/Aegisub
Update audio_player_portaudio2.* for PortAudio v19.
Originally committed to SVN as r2783.
This commit is contained in:
parent
23eea68fdd
commit
e61d0b77ac
2 changed files with 15 additions and 30 deletions
|
@ -45,11 +45,6 @@
|
||||||
#include "audio_provider_manager.h"
|
#include "audio_provider_manager.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
#ifdef HAVE_PA_GETSTREAMTIME
|
|
||||||
#define Pa_StreamTime Pa_GetStreamTime /* PortAudio v19 */
|
|
||||||
#define PaTimestamp PaTime
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
///////////
|
///////////
|
||||||
// Library
|
// Library
|
||||||
|
@ -94,13 +89,9 @@ PortAudioPlayer::~PortAudioPlayer() {
|
||||||
|
|
||||||
//////////////////////
|
//////////////////////
|
||||||
// PortAudio callback
|
// PortAudio callback
|
||||||
#ifndef HAVE_PA_GETSTREAMTIME
|
|
||||||
int PortAudioPlayer::paCallback(void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, PaTimestamp outTime, void *userData) {
|
int PortAudioPlayer::paCallback(void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo* timeInfo, PaStreamCallbackFlags statusFlags, void *userData) {
|
||||||
#else
|
|
||||||
int PortAudioPlayer::paCallback(const void *inputBuffer, void *outputBuffer,
|
|
||||||
unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo *timei,
|
|
||||||
PaStreamCallbackFlags flags, void *userData) {
|
|
||||||
#endif
|
|
||||||
// Get provider
|
// Get provider
|
||||||
PortAudioPlayer *player = (PortAudioPlayer *) userData;
|
PortAudioPlayer *player = (PortAudioPlayer *) userData;
|
||||||
AudioProvider *provider = player->GetProvider();
|
AudioProvider *provider = player->GetProvider();
|
||||||
|
@ -135,13 +126,10 @@ int PortAudioPlayer::paCallback(const void *inputBuffer, void *outputBuffer,
|
||||||
|
|
||||||
// Set play position (and real one)
|
// Set play position (and real one)
|
||||||
player->playPos += framesPerBuffer;
|
player->playPos += framesPerBuffer;
|
||||||
#ifndef __APPLE__
|
|
||||||
player->realPlayPos = (int64_t)(Pa_StreamTime(player->stream) - player->paStart) + player->startPos;
|
const PaStreamInfo* streamInfo = Pa_GetStreamInfo(player->stream);
|
||||||
#else
|
player->realPlayPos = (timeInfo->outputBufferDacTime * streamInfo->sampleRate) + player->startPos;
|
||||||
// AudioDeviceGetCurrentTime(), used by Pa_StreamTime() on OS X, is buggered, so use playPos for now
|
|
||||||
player->realPlayPos = player->playPos;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Cap to start if lower
|
// Cap to start if lower
|
||||||
return end;
|
return end;
|
||||||
}
|
}
|
||||||
|
@ -167,7 +155,7 @@ void PortAudioPlayer::Play(int64_t start,int64_t count) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
playing = true;
|
playing = true;
|
||||||
paStart = Pa_StreamTime(stream);
|
paStart = Pa_GetStreamTime(stream);
|
||||||
|
|
||||||
// Update timer
|
// Update timer
|
||||||
if (displayTimer && !displayTimer->IsRunning()) displayTimer->Start(15);
|
if (displayTimer && !displayTimer->IsRunning()) displayTimer->Start(15);
|
||||||
|
@ -195,11 +183,7 @@ void PortAudioPlayer::Stop(bool timerToo) {
|
||||||
// Open stream
|
// Open stream
|
||||||
void PortAudioPlayer::OpenStream() {
|
void PortAudioPlayer::OpenStream() {
|
||||||
// Open stream
|
// Open stream
|
||||||
PaError err = Pa_OpenDefaultStream(&stream,0,provider->GetChannels(),paInt16,provider->GetSampleRate(),256,
|
PaError err = Pa_OpenDefaultStream(&stream,0,provider->GetChannels(),paInt16,provider->GetSampleRate(),256,paCallback,this);
|
||||||
#ifndef HAVE_PA_GETSTREAMTIME
|
|
||||||
16, /* Pa v19 doesn't have a numberOfBuffers parameter */
|
|
||||||
#endif
|
|
||||||
paCallback,this);
|
|
||||||
|
|
||||||
if (err != paNoError) {
|
if (err != paNoError) {
|
||||||
throw wxString(_T("Failed initializing PortAudio stream with error: ") + wxString(Pa_GetErrorText(err),wxConvLocal));
|
throw wxString(_T("Failed initializing PortAudio stream with error: ") + wxString(Pa_GetErrorText(err),wxConvLocal));
|
||||||
|
|
|
@ -47,6 +47,7 @@ extern "C" {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////
|
////////////////////
|
||||||
// Portaudio player
|
// Portaudio player
|
||||||
class PortAudioPlayer : public AudioPlayer {
|
class PortAudioPlayer : public AudioPlayer {
|
||||||
|
@ -62,17 +63,17 @@ private:
|
||||||
volatile int64_t startPos;
|
volatile int64_t startPos;
|
||||||
volatile int64_t endPos;
|
volatile int64_t endPos;
|
||||||
void *stream;
|
void *stream;
|
||||||
PaTimestamp paStart;
|
PaTime paStart;
|
||||||
volatile int64_t realPlayPos;
|
volatile int64_t realPlayPos;
|
||||||
|
|
||||||
#ifndef HAVE_PA_GETSTREAMTIME
|
// static int paCallback(void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, PaTime outTime, void *userData);
|
||||||
static int paCallback(void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, PaTimestamp outTime, void *userData);
|
static int paCallback(void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo* timeInfo, PaStreamCallbackFlags statusFlags, void *userData);
|
||||||
#else
|
/*
|
||||||
static int paCallback(const void *inputBuffer, void *outputBuffer,
|
static int paCallback(const void *inputBuffer, void *outputBuffer,
|
||||||
unsigned long framesPerBuffer,
|
unsigned long framesPerBuffer,
|
||||||
const PaStreamCallbackTimeInfo *timei,
|
const PaStreamCallbackTimeInfo *timei,
|
||||||
PaStreamCallbackFlags flags, void *userData);
|
PaStreamCallbackFlags flags, void *userData);
|
||||||
#endif
|
*/
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PortAudioPlayer();
|
PortAudioPlayer();
|
||||||
|
|
Loading…
Reference in a new issue