[DEV] update audio time interface
This commit is contained in:
parent
32858d6104
commit
24af15748d
@ -16,7 +16,6 @@
|
||||
#undef __class__
|
||||
#define __class__ "api"
|
||||
|
||||
|
||||
// Static variable definitions.
|
||||
const std::vector<uint32_t>& audio::orchestra::genericSampleRate() {
|
||||
static std::vector<uint32_t> list;
|
||||
@ -57,7 +56,7 @@ audio::orchestra::Api::~Api() {
|
||||
|
||||
enum audio::orchestra::error audio::orchestra::Api::startStream() {
|
||||
ATA_VERBOSE("Start Stream");
|
||||
m_startTime = std11::chrono::system_clock::now();
|
||||
m_startTime = audio::Time::now();
|
||||
m_duration = std11::chrono::microseconds(0);
|
||||
return audio::orchestra::error_none;
|
||||
}
|
||||
@ -201,9 +200,9 @@ bool audio::orchestra::Api::probeDeviceOpen(uint32_t /*device*/,
|
||||
}
|
||||
|
||||
void audio::orchestra::Api::tickStreamTime() {
|
||||
//ATA_WARNING("tick : size=" << m_bufferSize << " rate=" << m_sampleRate << " time=" << std11::chrono::nanoseconds((int64_t(m_bufferSize) * int64_t(1000000000)) / int64_t(m_sampleRate)).count());
|
||||
//ATA_WARNING(" one element=" << std11::chrono::nanoseconds((int64_t(1000000000)) / int64_t(m_sampleRate)).count());
|
||||
m_duration += std11::chrono::nanoseconds((int64_t(m_bufferSize) * int64_t(1000000000)) / int64_t(m_sampleRate));
|
||||
//ATA_WARNING("tick : size=" << m_bufferSize << " rate=" << m_sampleRate << " time=" << audio::Duration((int64_t(m_bufferSize) * int64_t(1000000000)) / int64_t(m_sampleRate)).count());
|
||||
//ATA_WARNING(" one element=" << audio::Duration((int64_t(1000000000)) / int64_t(m_sampleRate)).count());
|
||||
m_duration += audio::Duration((int64_t(m_bufferSize) * int64_t(1000000000)) / int64_t(m_sampleRate));
|
||||
}
|
||||
|
||||
long audio::orchestra::Api::getStreamLatency() {
|
||||
@ -222,9 +221,9 @@ long audio::orchestra::Api::getStreamLatency() {
|
||||
return totalLatency;
|
||||
}
|
||||
|
||||
std11::chrono::system_clock::time_point audio::orchestra::Api::getStreamTime() {
|
||||
audio::Time audio::orchestra::Api::getStreamTime() {
|
||||
if (verifyStream() != audio::orchestra::error_none) {
|
||||
return std11::chrono::system_clock::time_point();
|
||||
return audio::Time();
|
||||
}
|
||||
return m_startTime + m_duration;
|
||||
}
|
||||
@ -251,8 +250,8 @@ void audio::orchestra::Api::clearStreamInfo() {
|
||||
m_bufferSize = 0;
|
||||
m_nBuffers = 0;
|
||||
m_userFormat = audio::format_unknow;
|
||||
m_startTime = std11::chrono::system_clock::time_point();
|
||||
m_duration = std11::chrono::nanoseconds(0);
|
||||
m_startTime = audio::Time();
|
||||
m_duration = audio::Duration(0);
|
||||
m_deviceBuffer = nullptr;
|
||||
m_callback = nullptr;
|
||||
for (int32_t iii=0; iii<2; ++iii) {
|
||||
|
@ -13,6 +13,8 @@
|
||||
#include <audio/orchestra/type.h>
|
||||
#include <audio/orchestra/state.h>
|
||||
#include <audio/orchestra/mode.h>
|
||||
#include <audio/Time.h>
|
||||
#include <audio/Duration.h>
|
||||
|
||||
namespace audio {
|
||||
namespace orchestra {
|
||||
@ -28,9 +30,9 @@ namespace audio {
|
||||
* @param _status List of error that occured in the laps of time.
|
||||
*/
|
||||
typedef std11::function<int32_t (const void* _inputBuffer,
|
||||
const std11::chrono::system_clock::time_point& _timeInput,
|
||||
const audio::Time& _timeInput,
|
||||
void* _outputBuffer,
|
||||
const std11::chrono::system_clock::time_point& _timeOutput,
|
||||
const audio::Time& _timeOutput,
|
||||
uint32_t _nbChunk,
|
||||
const std::vector<audio::orchestra::status>& _status)> AirTAudioCallback;
|
||||
// A protected structure used for buffer conversion.
|
||||
@ -76,7 +78,7 @@ namespace audio {
|
||||
virtual enum audio::orchestra::error abortStream() = 0;
|
||||
long getStreamLatency();
|
||||
uint32_t getStreamSampleRate();
|
||||
virtual std11::chrono::system_clock::time_point getStreamTime();
|
||||
virtual audio::Time getStreamTime();
|
||||
bool isStreamOpen() const {
|
||||
return m_state != audio::orchestra::state_closed;
|
||||
}
|
||||
@ -106,9 +108,9 @@ namespace audio {
|
||||
enum audio::format m_deviceFormat[2]; // Playback and record, respectively.
|
||||
audio::orchestra::ConvertInfo m_convertInfo[2];
|
||||
|
||||
//std11::chrono::system_clock::time_point
|
||||
std11::chrono::system_clock::time_point m_startTime; //!< start time of the stream (restart at every stop, pause ...)
|
||||
std11::chrono::nanoseconds m_duration; //!< duration from wich the stream is started
|
||||
//audio::Time
|
||||
audio::Time m_startTime; //!< start time of the stream (restart at every stop, pause ...)
|
||||
audio::Duration m_duration; //!< duration from wich the stream is started
|
||||
|
||||
/**
|
||||
* @brief api-specific method that attempts to open a device
|
||||
|
@ -277,9 +277,9 @@ namespace audio {
|
||||
* @brief If a stream is not open, an RtError (type = INVALID_USE) will be thrown.
|
||||
* @return the number of elapsed seconds since the stream was started.
|
||||
*/
|
||||
std11::chrono::system_clock::time_point getStreamTime() {
|
||||
audio::Time getStreamTime() {
|
||||
if (m_rtapi == nullptr) {
|
||||
return std11::chrono::system_clock::time_point();
|
||||
return audio::Time();
|
||||
}
|
||||
return m_rtapi->getStreamTime();
|
||||
}
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user