[DEV] update audio time interface
This commit is contained in:
@@ -1065,7 +1065,7 @@ void audio::orchestra::api::Alsa::callbackEvent() {
|
||||
}
|
||||
}
|
||||
|
||||
std11::chrono::system_clock::time_point audio::orchestra::api::Alsa::getStreamTime() {
|
||||
audio::Time audio::orchestra::api::Alsa::getStreamTime() {
|
||||
//ATA_DEBUG("mode : " << m_private->timeMode);
|
||||
if (m_private->timeMode == timestampMode_Hardware) {
|
||||
snd_pcm_status_t *status = nullptr;
|
||||
@@ -1082,22 +1082,22 @@ std11::chrono::system_clock::time_point audio::orchestra::api::Alsa::getStreamTi
|
||||
#if 1
|
||||
snd_timestamp_t timestamp;
|
||||
snd_pcm_status_get_tstamp(status, ×tamp);
|
||||
m_startTime = std11::chrono::system_clock::from_time_t(timestamp.tv_sec) + std11::chrono::microseconds(timestamp.tv_usec);
|
||||
m_startTime = audio::Time(timestamp.tv_sec, timestamp.tv_usec * 1000);
|
||||
#else
|
||||
#if 1
|
||||
snd_htimestamp_t timestamp;
|
||||
snd_pcm_status_get_htstamp(status, ×tamp);
|
||||
m_startTime = std11::chrono::system_clock::from_time_t(timestamp.tv_sec) + std11::chrono::nanoseconds(timestamp.tv_nsec);
|
||||
m_startTime = audio::Time(timestamp.tv_sec, timestamp.tv_nsec);
|
||||
#else
|
||||
snd_htimestamp_t timestamp;
|
||||
snd_pcm_status_get_audio_htstamp(status, ×tamp);
|
||||
m_startTime = std11::chrono::system_clock::from_time_t(timestamp.tv_sec) + std11::chrono::nanoseconds(timestamp.tv_nsec);
|
||||
m_startTime = audio::Time(timestamp.tv_sec, timestamp.tv_nsec);
|
||||
return m_startTime;
|
||||
#endif
|
||||
#endif
|
||||
ATA_VERBOSE("snd_pcm_status_get_htstamp : " << m_startTime);
|
||||
snd_pcm_sframes_t delay = snd_pcm_status_get_delay(status);
|
||||
std11::chrono::nanoseconds timeDelay(delay*1000000000LL/int64_t(m_sampleRate));
|
||||
audio::Duration timeDelay = audio::Duration(0, delay*1000000000LL/int64_t(m_sampleRate));
|
||||
ATA_VERBOSE("delay : " << timeDelay.count() << " ns");
|
||||
//return m_startTime + m_duration;
|
||||
if (m_private->handles[0] != nullptr) {
|
||||
@@ -1109,7 +1109,7 @@ std11::chrono::system_clock::time_point audio::orchestra::api::Alsa::getStreamTi
|
||||
}
|
||||
return m_startTime;
|
||||
} else if (m_private->timeMode == timestampMode_trigered) {
|
||||
if (m_startTime == std11::chrono::system_clock::time_point()) {
|
||||
if (m_startTime == audio::Time()) {
|
||||
snd_pcm_status_t *status = nullptr;
|
||||
snd_pcm_status_alloca(&status);
|
||||
// get harware timestamp all the time:
|
||||
@@ -1124,16 +1124,16 @@ std11::chrono::system_clock::time_point audio::orchestra::api::Alsa::getStreamTi
|
||||
// get start time:
|
||||
snd_timestamp_t timestamp;
|
||||
snd_pcm_status_get_trigger_tstamp(status, ×tamp);
|
||||
m_startTime = std11::chrono::system_clock::from_time_t(timestamp.tv_sec) + std11::chrono::microseconds(timestamp.tv_usec);
|
||||
m_startTime = audio::Time(timestamp.tv_sec, timestamp.tv_usec);
|
||||
ATA_VERBOSE("snd_pcm_status_get_trigger_tstamp : " << m_startTime);
|
||||
}
|
||||
return m_startTime + m_duration;
|
||||
} else {
|
||||
// softaware mode ...
|
||||
if (m_startTime == std11::chrono::system_clock::time_point()) {
|
||||
m_startTime = std11::chrono::system_clock::now();
|
||||
if (m_startTime == audio::Time()) {
|
||||
m_startTime = audio::Time::now();
|
||||
ATA_ERROR("START TIOMESTAMP : " << m_startTime);
|
||||
std11::chrono::nanoseconds timeDelay(m_bufferSize*1000000000LL/int64_t(m_sampleRate));
|
||||
audio::Duration timeDelay = audio::Duration(0, m_bufferSize*1000000000LL/int64_t(m_sampleRate));
|
||||
if (m_private->handles[0] != nullptr) {
|
||||
// output
|
||||
m_startTime += timeDelay;
|
||||
@@ -1141,7 +1141,7 @@ std11::chrono::system_clock::time_point audio::orchestra::api::Alsa::getStreamTi
|
||||
// input
|
||||
m_startTime -= timeDelay;
|
||||
}
|
||||
m_duration = std11::chrono::microseconds(0);
|
||||
m_duration = audio::Duration(0);
|
||||
}
|
||||
return m_startTime + m_duration;
|
||||
}
|
||||
@@ -1167,7 +1167,7 @@ void audio::orchestra::api::Alsa::callbackEventOneCycle() {
|
||||
return; // TODO : notify appl: audio::orchestra::error_warning;
|
||||
}
|
||||
int32_t doStopStream = 0;
|
||||
std11::chrono::system_clock::time_point streamTime;
|
||||
audio::Time streamTime;
|
||||
std::vector<enum audio::orchestra::status> status;
|
||||
if ( m_mode != audio::orchestra::mode_input
|
||||
&& m_private->xrun[0] == true) {
|
||||
@@ -1260,16 +1260,16 @@ void audio::orchestra::api::Alsa::callbackEventOneCycle() {
|
||||
noInput:
|
||||
streamTime = getStreamTime();
|
||||
{
|
||||
std11::chrono::system_clock::time_point startCall = std11::chrono::system_clock::now();
|
||||
audio::Time startCall = audio::Time::now();
|
||||
doStopStream = m_callback(&m_userBuffer[1][0],
|
||||
streamTime,// - std11::chrono::nanoseconds(m_latency[1]*1000000000LL/int64_t(m_sampleRate)),
|
||||
streamTime,// - audio::Duration(m_latency[1]*1000000000LL/int64_t(m_sampleRate)),
|
||||
&m_userBuffer[0][0],
|
||||
streamTime,// + std11::chrono::nanoseconds(m_latency[0]*1000000000LL/int64_t(m_sampleRate)),
|
||||
streamTime,// + audio::Duration(m_latency[0]*1000000000LL/int64_t(m_sampleRate)),
|
||||
m_bufferSize,
|
||||
status);
|
||||
std11::chrono::system_clock::time_point stopCall = std11::chrono::system_clock::now();
|
||||
std11::chrono::nanoseconds timeDelay(m_bufferSize*1000000000LL/int64_t(m_sampleRate));
|
||||
std11::chrono::nanoseconds timeProcess = stopCall - startCall;
|
||||
audio::Time stopCall = audio::Time::now();
|
||||
audio::Duration timeDelay(0, m_bufferSize*1000000000LL/int64_t(m_sampleRate));
|
||||
audio::Duration timeProcess = stopCall - startCall;
|
||||
if (timeDelay <= timeProcess) {
|
||||
ATA_ERROR("SOFT XRUN ... : (bufferTime) " << timeDelay.count() << " < " << timeProcess.count() << " (process time) ns");
|
||||
}
|
||||
|
@@ -66,7 +66,7 @@ namespace audio {
|
||||
audio::format _format,
|
||||
uint32_t *_bufferSize,
|
||||
const audio::orchestra::StreamOptions& _options);
|
||||
virtual std11::chrono::system_clock::time_point getStreamTime();
|
||||
virtual audio::Time getStreamTime();
|
||||
public:
|
||||
bool isMasterOf(audio::orchestra::Api* _api);
|
||||
};
|
||||
|
@@ -110,11 +110,11 @@ enum audio::orchestra::error audio::orchestra::api::Android::abortStream() {
|
||||
void audio::orchestra::api::Android::callBackEvent(void* _data,
|
||||
int32_t _frameRate) {
|
||||
int32_t doStopStream = 0;
|
||||
std11::chrono::system_clock::time_point streamTime = getStreamTime();
|
||||
audio::Time streamTime = getStreamTime();
|
||||
std::vector<enum audio::orchestra::status> status;
|
||||
if (m_doConvertBuffer[audio::orchestra::mode_output] == true) {
|
||||
doStopStream = m_callback(nullptr,
|
||||
std11::chrono::system_clock::time_point(),
|
||||
audio::Time(),
|
||||
m_userBuffer[audio::orchestra::mode_output],
|
||||
streamTime,
|
||||
_frameRate,
|
||||
@@ -124,7 +124,7 @@ void audio::orchestra::api::Android::callBackEvent(void* _data,
|
||||
doStopStream = m_callback(_data,
|
||||
streamTime,
|
||||
nullptr,
|
||||
std11::chrono::system_clock::time_point(),
|
||||
audio::Time(),
|
||||
_frameRate,
|
||||
status);
|
||||
}
|
||||
|
@@ -694,7 +694,7 @@ bool audio::orchestra::api::Asio::callbackEvent(long bufferIndex) {
|
||||
// Invoke user callback to get fresh output data UNLESS we are
|
||||
// draining stream.
|
||||
if (m_private->drainCounter == 0) {
|
||||
std11::chrono::system_clock::time_point streamTime = getStreamTime();
|
||||
audio::Time streamTime = getStreamTime();
|
||||
std::vector<enum audio::orchestra::status status;
|
||||
if (m_mode != audio::orchestra::mode_input && asioXRun == true) {
|
||||
status.push_back(audio::orchestra::status_underflow);
|
||||
|
@@ -1012,9 +1012,9 @@ void audio::orchestra::api::Core::coreStopStream(void *_userData) {
|
||||
|
||||
bool audio::orchestra::api::Core::callbackEvent(AudioDeviceID _deviceId,
|
||||
const AudioBufferList *_inBufferList,
|
||||
const std11::chrono::system_clock::time_point& _inTime,
|
||||
const audio::Time& _inTime,
|
||||
const AudioBufferList *_outBufferList,
|
||||
const std11::chrono::system_clock::time_point& _outTime) {
|
||||
const audio::Time& _outTime) {
|
||||
if ( m_state == audio::orchestra::state_stopped
|
||||
|| m_state == audio::orchestra::state_stopping) {
|
||||
return true;
|
||||
|
@@ -35,9 +35,9 @@ namespace audio {
|
||||
long getStreamLatency();
|
||||
bool callbackEvent(AudioDeviceID _deviceId,
|
||||
const AudioBufferList *_inBufferList,
|
||||
const std11::chrono::system_clock::time_point& _inTime,
|
||||
const audio::Time& _inTime,
|
||||
const AudioBufferList *_outBufferList,
|
||||
const std11::chrono::system_clock::time_point& _outTime);
|
||||
const audio::Time& _outTime);
|
||||
static OSStatus callbackEvent(AudioDeviceID _inDevice,
|
||||
const AudioTimeStamp* _inNow,
|
||||
const AudioBufferList* _inInputData,
|
||||
|
@@ -129,7 +129,7 @@ void audio::orchestra::api::CoreIos::callBackEvent(void* _data,
|
||||
return;
|
||||
#endif
|
||||
int32_t doStopStream = 0;
|
||||
std11::chrono::system_clock::time_point streamTime = getStreamTime();
|
||||
audio::Time streamTime = getStreamTime();
|
||||
std::vector<enum audio::orchestra::status> status;
|
||||
if (m_doConvertBuffer[modeToIdTable(audio::orchestra::mode_output)] == true) {
|
||||
doStopStream = m_callback(nullptr,
|
||||
|
@@ -984,7 +984,7 @@ void audio::orchestra::api::Ds::callbackEvent() {
|
||||
// Invoke user callback to get fresh output data UNLESS we are
|
||||
// draining stream.
|
||||
if (m_private->drainCounter == 0) {
|
||||
std11::chrono::system_clock::time_point streamTime = getStreamTime();
|
||||
audio::Time streamTime = getStreamTime();
|
||||
audio::orchestra::status status = audio::orchestra::status_ok;
|
||||
if ( m_mode != audio::orchestra::mode_input
|
||||
&& m_private->xrun[0] == true) {
|
||||
|
@@ -656,7 +656,7 @@ bool audio::orchestra::api::Jack::callbackEvent(uint64_t _nframes) {
|
||||
}
|
||||
// Invoke user callback first, to get fresh output data.
|
||||
if (m_private->drainCounter == 0) {
|
||||
std11::chrono::time_point<std11::chrono::system_clock> streamTime = getStreamTime();
|
||||
audio::Time streamTime = getStreamTime();
|
||||
std::vector<enum audio::orchestra::status> status;
|
||||
if (m_mode != audio::orchestra::mode_input && m_private->xrun[0] == true) {
|
||||
status.push_back(audio::orchestra::status_underflow);
|
||||
|
@@ -712,7 +712,7 @@ void audio::orchestra::api::Oss::callbackEvent() {
|
||||
}
|
||||
// Invoke user callback to get fresh output data.
|
||||
int32_t doStopStream = 0;
|
||||
std11::chrono::system_clock::time_point streamTime = getStreamTime();
|
||||
audio::Time streamTime = getStreamTime();
|
||||
std::vector<enum audio::orchestra::status> status;
|
||||
if ( m_mode != audio::orchestra::mode_input
|
||||
&& m_private->xrun[0] == true) {
|
||||
|
@@ -153,7 +153,7 @@ void audio::orchestra::api::Pulse::callbackEventOneCycle() {
|
||||
ATA_ERROR("the stream is closed ... this shouldn't happen!");
|
||||
return;
|
||||
}
|
||||
std11::chrono::system_clock::time_point streamTime = getStreamTime();
|
||||
audio::Time streamTime = getStreamTime();
|
||||
std::vector<enum audio::orchestra::status> status;
|
||||
int32_t doStopStream = m_callback(&m_userBuffer[audio::orchestra::modeToIdTable(audio::orchestra::mode_input)][0],
|
||||
streamTime,
|
||||
|
Reference in New Issue
Block a user