예제 #1
0
파일: osx-audio.c 프로젝트: also/spotfm
void audio_get_position(audio_player_t *player, int *position) {
	state_t *state = (state_t *) player->internal_state;
	AudioTimeStamp ts;
	AudioQueueGetCurrentTime(state->queue, NULL, &ts, NULL);
	//printf("mSampleTime: %f\n", ts.mSampleTime);
	if (state->playing) {
		//printf("actual ? time: %f\n", ts.mSampleTime / state->desc.mSampleRate);
	}
//	*position = ts.mSampleTime;
}
예제 #2
0
AudioTimeStamp Audio_Queue::currentTime()
{
    AudioTimeStamp queueTime;
    Boolean discontinuity;
    
    memset(&queueTime, 0, sizeof queueTime);
    
    OSStatus err = AudioQueueGetCurrentTime(m_outAQ, NULL, &queueTime, &discontinuity);
    if (err) {
        AQ_TRACE("AudioQueueGetCurrentTime failed\n");
    }
    
    return queueTime;
}
예제 #3
0
 double Audio_Queue::timePlayedInSeconds() {
     double timePlayed = 0;
     
     AudioTimeStamp queueTime;
     Boolean discontinuity;
     
     OSStatus err = AudioQueueGetCurrentTime(m_outAQ, NULL, &queueTime, &discontinuity);
     if (err) {
         goto out;
     }
     
     timePlayed = queueTime.mSampleTime / m_streamDesc.mSampleRate;
     
 out:
     return timePlayed;
 }
예제 #4
0
    double progress() const {
        double p = 0;

        AudioTimeStamp timeStamp;
        OSStatus status = AudioQueueGetCurrentTime (
           aqData.mQueue,
           NULL,
           &timeStamp,
           NULL
        );
        
//        checkStatus(status);
        
        p = timeStamp.mSampleTime/aqData.mDataFormat.mSampleRate + timeBase;
                
        return p;
    }
예제 #5
0
SInt64 DZAudioQueuePlayer::seek(float time)
{
    // Cannot seek if parameters not available or parser/queue not ready.
    if (this->_format.mSampleRate <= 0 || this->_format.mFramesPerPacket <= 0) {
        return -1;
    }
    if (this->_parser == NULL || this->_queue == NULL
        || this->_status == DZAudioQueuePlayerStatus_NotReady
        || this->_status == DZAudioQueuePlayerStatus_Error) {
        return -1;
    }
    
    // Get audio data offset.
    SInt64 dataOffset = 0;
    UInt32 propertySize = sizeof(dataOffset);
    if (dzDebugError(AudioFileStreamGetProperty(this->_parser, kAudioFileStreamProperty_DataOffset, &propertySize, &dataOffset), "Fail to get stream data offset.")) {
        return -1;
    }
    
    // Reset audio queue to clear the current queue buffer.
    if (dzDebugError(AudioQueueReset(this->_queue), "Fail to reset audio queue.")) {
        return -1;
    }
    
    // Get audio queue current time.
    AudioTimeStamp timeStamp;
    if (this->_status == DZAudioQueuePlayerStatus_ReadyToStart) {
        timeStamp.mSampleTime = 0;
    } else if (dzDebugError(AudioQueueGetCurrentTime(this->_queue, NULL, &(timeStamp), NULL),
                     "Fail to get audio queue current time.")) {
        return -1;
    }
    
    // Calculate packet offset and so the byte offset.
    SInt64 packetOffset = round(time * this->_format.mSampleRate / this->_format.mFramesPerPacket);
    SInt64 byteOffset = 0;
    UInt32 ioFlag = 0;
    if (dzDebugError(AudioFileStreamSeek(this->_parser, packetOffset, &byteOffset, &ioFlag),
                     "Fail to seek in audio file stream.")) {
        return -1;
    }
    this->_timeAmendment = time - timeStamp.mSampleTime / this->_format.mSampleRate;
    return byteOffset + dataOffset;
}
예제 #6
0
Float64 DZAudioQueuePlayer::getCurrentTime()
{
    // 0 if audio queue is not started.
    if (this->_queue == NULL || (this->_status != DZAudioQueuePlayerStatus_Running
                                 && this->_status != DZAudioQueuePlayerStatus_Paused)) {
        return 0;
    }
    
    // 0 if sample rate is not known.
    if (this->_format.mSampleRate == 0) {
        return 0;
    }
    
    // Get the time elapsed after last seek, plus the amendment.
    AudioTimeStamp timeStamp;
    if (dzDebugError(AudioQueueGetCurrentTime(this->_queue, NULL, &(timeStamp), NULL),
                     "Fail to get audio queue current time.")) {
        return 0;
    }
    return timeStamp.mSampleTime / this->_format.mSampleRate + this->_timeAmendment;
}