1
Audio / getPlayingOffset returns 0 when it shouldn't
« on: August 08, 2014, 08:50:38 am »
Hi,
I must be missing something, because it doesn't work. First of all, a bit of background of what I'm trying to do: I have an assignment in school for which I need to modify audio. The bit I'm stuck on is changing volume. Because of the assignment - I'm not allowed to use the built in volume function.
What I'm trying to do: I have the original buffer, as well as a "current buffer". This is because I want to keep the original file for easy recovery after making changes (more are to come). I copy the contents of the original buffer into an sf::Int16 array that I modify, load into the current buffer and then I call my sound variable's setBuffer-method passing in the current buffer. So far so good, the sound still works.
But, this causes the sound to restart from the beginning (naturally) which I don't want. To solve that, before I change the buffer, I save the playing offset to a variable and after the buffer has been changed, I set the playing offset to that time. As this did not work, I printed the values I got from getPlayingOffset and it turns out, other than the first time, this returns 0. Why is this?
The code segment for the above:
Thankful for help!
I must be missing something, because it doesn't work. First of all, a bit of background of what I'm trying to do: I have an assignment in school for which I need to modify audio. The bit I'm stuck on is changing volume. Because of the assignment - I'm not allowed to use the built in volume function.
What I'm trying to do: I have the original buffer, as well as a "current buffer". This is because I want to keep the original file for easy recovery after making changes (more are to come). I copy the contents of the original buffer into an sf::Int16 array that I modify, load into the current buffer and then I call my sound variable's setBuffer-method passing in the current buffer. So far so good, the sound still works.
But, this causes the sound to restart from the beginning (naturally) which I don't want. To solve that, before I change the buffer, I save the playing offset to a variable and after the buffer has been changed, I set the playing offset to that time. As this did not work, I printed the values I got from getPlayingOffset and it turns out, other than the first time, this returns 0. Why is this?
The code segment for the above:
int sampleCount = m_origBuffer.getSampleCount();
const sf::Int16* origSamples = m_origBuffer.getSamples();
sf::Int16* samples = new sf::Int16[sampleCount];
for (int i = 0; i < sampleCount; ++i)
{
samples[i] = origSamples[i] * m_volume;
}
m_currBuffer.loadFromSamples(samples, sampleCount, m_origBuffer.getChannelCount(), m_origBuffer.getSampleRate());
sf::Time time = m_sound.getPlayingOffset();
std::cout << "Sound offset at change: " << time.asMilliseconds() << "\t";
m_sound.setBuffer(m_currBuffer);
m_sound.play();
m_sound.setPlayingOffset(time);
std::cout << "Offset set to time: " << time.asMilliseconds() << std::endl;
const sf::Int16* origSamples = m_origBuffer.getSamples();
sf::Int16* samples = new sf::Int16[sampleCount];
for (int i = 0; i < sampleCount; ++i)
{
samples[i] = origSamples[i] * m_volume;
}
m_currBuffer.loadFromSamples(samples, sampleCount, m_origBuffer.getChannelCount(), m_origBuffer.getSampleRate());
sf::Time time = m_sound.getPlayingOffset();
std::cout << "Sound offset at change: " << time.asMilliseconds() << "\t";
m_sound.setBuffer(m_currBuffer);
m_sound.play();
m_sound.setPlayingOffset(time);
std::cout << "Offset set to time: " << time.asMilliseconds() << std::endl;
Thankful for help!