Mercurial > hg > svapp
comparison audioio/AudioCallbackPlaySource.cpp @ 163:2c158dd3b983
* Fix latency correction when time stretching
author | Chris Cannam |
---|---|
date | Fri, 27 Feb 2009 12:55:34 +0000 |
parents | 72495c4cd315 |
children | 07d8dac78edc |
comparison
equal
deleted
inserted
replaced
162:c17284397aa9 | 163:2c158dd3b983 |
---|---|
646 RealTime bufferedto_t = RealTime::frame2RealTime(readBufferFill, sourceRate); | 646 RealTime bufferedto_t = RealTime::frame2RealTime(readBufferFill, sourceRate); |
647 | 647 |
648 if (timeRatio != 1.0) { | 648 if (timeRatio != 1.0) { |
649 lastretrieved_t = lastretrieved_t / timeRatio; | 649 lastretrieved_t = lastretrieved_t / timeRatio; |
650 sincerequest_t = sincerequest_t / timeRatio; | 650 sincerequest_t = sincerequest_t / timeRatio; |
651 latency_t = latency_t / timeRatio; | |
651 } | 652 } |
652 | 653 |
653 #ifdef DEBUG_AUDIO_PLAY_SOURCE_PLAYING | 654 #ifdef DEBUG_AUDIO_PLAY_SOURCE_PLAYING |
654 std::cerr << "\nbuffered to: " << bufferedto_t << ", in buffer: " << inbuffer_t << ", time ratio " << timeRatio << "\n stretcher latency: " << stretchlat_t << ", device latency: " << latency_t << "\n since request: " << sincerequest_t << ", last retrieved: " << lastretrieved_t << std::endl; | 655 std::cerr << "\nbuffered to: " << bufferedto_t << ", in buffer: " << inbuffer_t << ", time ratio " << timeRatio << "\n stretcher latency: " << stretchlat_t << ", device latency: " << latency_t << "\n since request: " << sincerequest_t << ", last retrieved quantity: " << lastretrieved_t << std::endl; |
655 #endif | 656 #endif |
656 | 657 |
657 RealTime end = RealTime::frame2RealTime(m_lastModelEndFrame, sourceRate); | 658 RealTime end = RealTime::frame2RealTime(m_lastModelEndFrame, sourceRate); |
658 | 659 |
659 // Normally the range lists should contain at least one item each | 660 // Normally the range lists should contain at least one item each |
719 } | 720 } |
720 } else { | 721 } else { |
721 m_playStartFramePassed = true; | 722 m_playStartFramePassed = true; |
722 } | 723 } |
723 } | 724 } |
725 | |
726 #ifdef DEBUG_AUDIO_PLAY_SOURCE_PLAYING | |
727 std::cerr << "playing_t " << playing_t; | |
728 #endif | |
724 | 729 |
725 playing_t = playing_t - m_rangeStarts[inRange]; | 730 playing_t = playing_t - m_rangeStarts[inRange]; |
726 | 731 |
727 #ifdef DEBUG_AUDIO_PLAY_SOURCE_PLAYING | 732 #ifdef DEBUG_AUDIO_PLAY_SOURCE_PLAYING |
728 std::cerr << "playing_t as offset into range " << inRange << " (with start = " << m_rangeStarts[inRange] << ") = " << playing_t << std::endl; | 733 std::cerr << " as offset into range " << inRange << " (start =" << m_rangeStarts[inRange] << " duration =" << m_rangeDurations[inRange] << ") = " << playing_t << std::endl; |
729 #endif | 734 #endif |
730 | 735 |
731 while (playing_t < RealTime::zeroTime) { | 736 while (playing_t < RealTime::zeroTime) { |
732 | 737 |
733 if (inRange == 0) { | 738 if (inRange == 0) { |
1356 | 1361 |
1357 for (size_t c = 0; c < channels; ++c) { | 1362 for (size_t c = 0; c < channels; ++c) { |
1358 bufferPtrs[c] = nonintlv + c * orig; | 1363 bufferPtrs[c] = nonintlv + c * orig; |
1359 } | 1364 } |
1360 | 1365 |
1361 got = mixModels(f, orig, bufferPtrs); | 1366 got = mixModels(f, orig, bufferPtrs); // also modifies f |
1362 | 1367 |
1363 // and interleave into first half | 1368 // and interleave into first half |
1364 for (size_t c = 0; c < channels; ++c) { | 1369 for (size_t c = 0; c < channels; ++c) { |
1365 for (size_t i = 0; i < got; ++i) { | 1370 for (size_t i = 0; i < got; ++i) { |
1366 float sample = nonintlv[c * got + i]; | 1371 float sample = nonintlv[c * got + i]; |
1438 for (size_t i = 0; i < space; ++i) { | 1443 for (size_t i = 0; i < space; ++i) { |
1439 tmp[c * space + i] = 0.0f; | 1444 tmp[c * space + i] = 0.0f; |
1440 } | 1445 } |
1441 } | 1446 } |
1442 | 1447 |
1443 size_t got = mixModels(f, space, bufferPtrs); | 1448 size_t got = mixModels(f, space, bufferPtrs); // also modifies f |
1444 | 1449 |
1445 for (size_t c = 0; c < channels; ++c) { | 1450 for (size_t c = 0; c < channels; ++c) { |
1446 | 1451 |
1447 RingBuffer<float> *wb = getWriteRingBuffer(c); | 1452 RingBuffer<float> *wb = getWriteRingBuffer(c); |
1448 if (wb) { | 1453 if (wb) { |
1460 } | 1465 } |
1461 } | 1466 } |
1462 | 1467 |
1463 m_writeBufferFill = f; | 1468 m_writeBufferFill = f; |
1464 if (readWriteEqual) m_readBufferFill = f; | 1469 if (readWriteEqual) m_readBufferFill = f; |
1470 | |
1471 #ifdef DEBUG_AUDIO_PLAY_SOURCE | |
1472 std::cout << "Read buffer fill is now " << m_readBufferFill << std::endl; | |
1473 #endif | |
1465 | 1474 |
1466 //!!! how do we know when ended? need to mark up a fully-buffered flag and check this if we find the buffers empty in getSourceSamples | 1475 //!!! how do we know when ended? need to mark up a fully-buffered flag and check this if we find the buffers empty in getSourceSamples |
1467 } | 1476 } |
1468 | 1477 |
1469 return true; | 1478 return true; |