MCPcopy Create free account
hub / github.com/BambooTracker/BambooTracker / exportToWav

Method exportToWav

BambooTracker/bamboo_tracker.cpp:1762–1823  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1760}
1761
1762bool BambooTracker::exportToWav(io::WavContainer& container, int loopCnt, ExportCancellCallback checkFunc)
1763{
1764 int tmpRate = opnaCtrl_->getRate();
1765 opnaCtrl_->setRate(static_cast<int>(container.getSampleRate()));
1766 size_t sampCnt = static_cast<size_t>(opnaCtrl_->getRate() * opnaCtrl_->getDuration() / 1000);
1767 size_t intrCnt = static_cast<size_t>(opnaCtrl_->getRate()) / mod_->getTickFrequency();
1768 size_t intrCntRest = 0;
1769 std::vector<int16_t> buf(sampCnt << 1);
1770
1771 int endOrder, endStep;
1772 checkNextPositionOfLastStepAndStepSize(mod_->getSong(curSongNum_), endOrder, endStep);
1773 bool endFlag = false;
1774 bool tmpFollow = std::exchange(isFollowPlay_, false);
1775 startPlayFromStart();
1776
1777 while (true) {
1778 size_t sampCntRest = sampCnt;
1779 while (sampCntRest) {
1780 if (!intrCntRest) { // Interruption
1781 intrCntRest = intrCnt; // Set counts to next interruption
1782
1783 if (!streamCountUp()) {
1784 if (checkFunc()) { // Update lambda function
1785 stopPlaySong();
1786 isFollowPlay_ = tmpFollow;
1787 opnaCtrl_->setRate(tmpRate);
1788 return false;
1789 }
1790
1791 int playOrder = playback_->getPlayingOrderNumber();
1792 int playStep = playback_->getPlayingStepNumber();
1793 if ((playOrder == -1 && playStep == -1)
1794 || (playOrder == endOrder && playStep == endStep && !(loopCnt--))){
1795 endFlag = true;
1796 break;
1797 }
1798 }
1799 }
1800
1801 size_t count = std::min(intrCntRest, sampCntRest);
1802 sampCntRest -= count;
1803 intrCntRest -= count;
1804
1805 bool result = opnaCtrl_->getStreamSamples(buf.data(), count);
1806 if (!result) {
1807 stopPlaySong();
1808 isFollowPlay_ = tmpFollow;
1809 opnaCtrl_->setRate(tmpRate);
1810 return false;
1811 }
1812 container.appendSample(buf.data(), count);
1813 }
1814
1815 if (endFlag) break;
1816 }
1817
1818 stopPlaySong();
1819 isFollowPlay_ = tmpFollow;

Callers 1

Calls 11

getDurationMethod · 0.80
getTickFrequencyMethod · 0.80
appendSampleMethod · 0.80
getRateMethod · 0.45
setRateMethod · 0.45
getSampleRateMethod · 0.45
getPlayingOrderNumberMethod · 0.45
getPlayingStepNumberMethod · 0.45
getStreamSamplesMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected