/////////////////////////////////////////////////////// /see SoundStream::OnGetData ///////////////////////////////////////////////////////
| 74 | /// |
| 75 | //////////////////////////////////////////////////////////// |
| 76 | bool onGetData(sf::SoundStream::Chunk& data) override |
| 77 | { |
| 78 | // We have reached the end of the buffer and all audio data have been played: we can stop playback |
| 79 | if ((m_offset >= m_samples.size()) && m_hasFinished) |
| 80 | return false; |
| 81 | |
| 82 | // No new data has arrived since last update: wait until we get some |
| 83 | while ((m_offset >= m_samples.size()) && !m_hasFinished) |
| 84 | sf::sleep(sf::milliseconds(10)); |
| 85 | |
| 86 | // Copy samples into a local buffer to avoid synchronization problems |
| 87 | // (don't forget that we run in two separate threads) |
| 88 | { |
| 89 | const std::lock_guard lock(m_mutex); |
| 90 | m_tempBuffer.assign(m_samples.begin() + static_cast<std::vector<std::int16_t>::difference_type>(m_offset), |
| 91 | m_samples.end()); |
| 92 | } |
| 93 | |
| 94 | // Fill audio data to pass to the stream |
| 95 | data.samples = m_tempBuffer.data(); |
| 96 | data.sampleCount = m_tempBuffer.size(); |
| 97 | |
| 98 | // Update the playing offset |
| 99 | m_offset += m_tempBuffer.size(); |
| 100 | |
| 101 | return true; |
| 102 | } |
| 103 | |
| 104 | //////////////////////////////////////////////////////////// |
| 105 | /// /see SoundStream::OnSeek |