forked from mia/Aegisub
Move stream position info into it's own struct.. Looks like a few globals can't be helped due to how the AudioPlayer class is designed. If I have to use globals I'll atleast make them easier to manage.. Updates #997.
Originally committed to SVN as r3434.
This commit is contained in:
parent
5ea99a65e7
commit
8ba5aa27be
2 changed files with 28 additions and 36 deletions
|
@ -73,7 +73,7 @@ PortAudioPlayer::PortAudioPlayer() {
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
volume = 1.0f;
|
volume = 1.0f;
|
||||||
paStart = 0.0;
|
pos.pa_start = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -153,9 +153,9 @@ void PortAudioPlayer::Play(int64_t start,int64_t count) {
|
||||||
PaError err;
|
PaError err;
|
||||||
|
|
||||||
// Set values
|
// Set values
|
||||||
endPos = start + count;
|
pos.end = start + count;
|
||||||
playPos = start;
|
pos.current = start;
|
||||||
startPos = start;
|
pos.start = start;
|
||||||
|
|
||||||
// Start playing
|
// Start playing
|
||||||
if (!IsPlaying()) {
|
if (!IsPlaying()) {
|
||||||
|
@ -173,7 +173,7 @@ void PortAudioPlayer::Play(int64_t start,int64_t count) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
paStart = Pa_GetStreamTime(stream);
|
pos.pa_start = Pa_GetStreamTime(stream);
|
||||||
|
|
||||||
// Update timer
|
// Update timer
|
||||||
if (displayTimer && !displayTimer->IsRunning()) displayTimer->Start(15);
|
if (displayTimer && !displayTimer->IsRunning()) displayTimer->Start(15);
|
||||||
|
@ -218,21 +218,21 @@ int PortAudioPlayer::paCallback(
|
||||||
AudioProvider *provider = player->GetProvider();
|
AudioProvider *provider = player->GetProvider();
|
||||||
|
|
||||||
#ifdef PORTAUDIO_DEBUG
|
#ifdef PORTAUDIO_DEBUG
|
||||||
printf("paCallBack: playPos: %lld startPos: %lld paStart: %f Pa_GetStreamTime: %f AdcTime: %f DacTime: %f framesPerBuffer: %lu CPU: %f\n",
|
printf("paCallBack: pos.current: %lld pos.start: %lld paStart: %f Pa_GetStreamTime: %f AdcTime: %f DacTime: %f framesPerBuffer: %lu CPU: %f\n",
|
||||||
player->playPos, player->startPos, player->paStart, Pa_GetStreamTime(player->stream),
|
player->pos.current, player->pos.start, player->paStart, Pa_GetStreamTime(player->stream),
|
||||||
timeInfo->inputBufferAdcTime, timeInfo->outputBufferDacTime, framesPerBuffer, Pa_GetStreamCpuLoad(player->stream));
|
timeInfo->inputBufferAdcTime, timeInfo->outputBufferDacTime, framesPerBuffer, Pa_GetStreamCpuLoad(player->stream));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Calculate how much left
|
// Calculate how much left
|
||||||
int64_t lenAvailable = (player->endPos - player->playPos) > 0 ? framesPerBuffer : 0;
|
int64_t lenAvailable = (player->pos.end - player->pos.current) > 0 ? framesPerBuffer : 0;
|
||||||
|
|
||||||
|
|
||||||
// Play something
|
// Play something
|
||||||
if (lenAvailable > 0) {
|
if (lenAvailable > 0) {
|
||||||
provider->GetAudioWithVolume(outputBuffer, player->playPos, lenAvailable, player->GetVolume());
|
provider->GetAudioWithVolume(outputBuffer, player->pos.current, lenAvailable, player->GetVolume());
|
||||||
|
|
||||||
// Set play position
|
// Set play position
|
||||||
player->playPos += framesPerBuffer;
|
player->pos.current += framesPerBuffer;
|
||||||
|
|
||||||
// Continue as normal
|
// Continue as normal
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -255,15 +255,15 @@ int64_t PortAudioPlayer::GetCurrentPosition()
|
||||||
|
|
||||||
#ifdef PORTAUDIO_DEBUG
|
#ifdef PORTAUDIO_DEBUG
|
||||||
PaTime pa_getstream = Pa_GetStreamTime(stream);
|
PaTime pa_getstream = Pa_GetStreamTime(stream);
|
||||||
int64_t real = ((pa_getstream - paStart) * streamInfo->sampleRate) + startPos;
|
int64_t real = ((pa_getstream - paStart) * streamInfo->sampleRate) + pos.start;
|
||||||
printf("GetCurrentPosition: Pa_GetStreamTime: %f startPos: %lld playPos: %lld paStart: %f real: %lld diff: %f\n",
|
printf("GetCurrentPosition: Pa_GetStreamTime: %f pos.start: %lld pos.current: %lld paStart: %f real: %lld diff: %f\n",
|
||||||
pa_getstream, startPos, playPos, paStart, real, pa_getstream-paStart);
|
pa_getstream, pos.start, pos.current, paStart, real, pa_getstream-paStart);
|
||||||
|
|
||||||
return real;
|
return real;
|
||||||
#else
|
|
||||||
return ((Pa_GetStreamTime(stream) - paStart) * streamInfo->sampleRate) + startPos;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
return ((Pa_GetStreamTime(stream) - pos.pa_start) * streamInfo->sampleRate) + pos.start;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -47,36 +47,29 @@ extern "C" {
|
||||||
#include <portaudio.h>
|
#include <portaudio.h>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// @class PortAudioPlayer
|
/// @class PortAudioPlayer
|
||||||
/// @brief PortAudio Player
|
/// @brief PortAudio Player
|
||||||
///
|
///
|
||||||
class PortAudioPlayer : public AudioPlayer {
|
class PortAudioPlayer : public AudioPlayer {
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/// DOCME
|
/// Initialisation reference counter.
|
||||||
static int pa_refcount;
|
static int pa_refcount;
|
||||||
|
|
||||||
/// Current volume level.
|
/// Current volume level.
|
||||||
float volume;
|
float volume;
|
||||||
|
|
||||||
/// Playback position.
|
/// @brief Stream playback position info.
|
||||||
volatile int64_t playPos;
|
typedef struct PositionInfo {
|
||||||
|
volatile int64_t current; /// Current position.
|
||||||
|
volatile int64_t start; /// Start position.
|
||||||
|
volatile int64_t end; /// End position.
|
||||||
|
PaTime pa_start; /// PortAudio internal start position.
|
||||||
|
};
|
||||||
|
PositionInfo pos;
|
||||||
|
|
||||||
/// Playback start position.
|
|
||||||
volatile int64_t startPos;
|
|
||||||
|
|
||||||
/// Playback end position.
|
|
||||||
volatile int64_t endPos;
|
|
||||||
|
|
||||||
/// Audio Stream
|
|
||||||
void *stream;
|
void *stream;
|
||||||
|
|
||||||
/// PortAudio internal start position.
|
|
||||||
PaTime paStart;
|
|
||||||
|
|
||||||
static int paCallback(
|
static int paCallback(
|
||||||
const void *inputBuffer,
|
const void *inputBuffer,
|
||||||
void *outputBuffer,
|
void *outputBuffer,
|
||||||
|
@ -105,20 +98,20 @@ public:
|
||||||
|
|
||||||
/// @brief Position audio will be played from.
|
/// @brief Position audio will be played from.
|
||||||
/// @return Start position.
|
/// @return Start position.
|
||||||
int64_t GetStartPosition() { return startPos; }
|
int64_t GetStartPosition() { return pos.start; }
|
||||||
|
|
||||||
/// @brief End position playback will stop at.
|
/// @brief End position playback will stop at.
|
||||||
/// @return End position.
|
/// @return End position.
|
||||||
int64_t GetEndPosition() { return endPos; }
|
int64_t GetEndPosition() { return pos.end; }
|
||||||
int64_t GetCurrentPosition();
|
int64_t GetCurrentPosition();
|
||||||
|
|
||||||
/// @brief Set end position of playback
|
/// @brief Set end position of playback
|
||||||
/// @param pos End position
|
/// @param pos End position
|
||||||
void SetEndPosition(int64_t pos) { endPos = pos; }
|
void SetEndPosition(int64_t position) { pos.end = position; }
|
||||||
|
|
||||||
/// @brief Set current position of playback.
|
/// @brief Set current position of playback.
|
||||||
/// @param pos Current position
|
/// @param pos Current position
|
||||||
void SetCurrentPosition(int64_t pos) { playPos = pos; }
|
void SetCurrentPosition(int64_t position) { pos.current = position; }
|
||||||
|
|
||||||
|
|
||||||
/// @brief Set volume level
|
/// @brief Set volume level
|
||||||
|
@ -133,7 +126,6 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// @class PortAudioPlayerFactory
|
/// @class PortAudioPlayerFactory
|
||||||
/// @brief PortAudio Player Factory
|
/// @brief PortAudio Player Factory
|
||||||
class PortAudioPlayerFactory : public AudioPlayerFactory {
|
class PortAudioPlayerFactory : public AudioPlayerFactory {
|
||||||
|
|
Loading…
Reference in a new issue