So I'm loading a recorded file ("recording.ogg") which plays fine by default.
However what I'm doing now is I retrieve the samples and reverse them and try to put them in a new buffer.
After doing this and playing from the buffer, I hear nothing now. What's wrong?
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Audio.hpp>
#include <iostream>
#include <string>
using namespace std;
//g++ test.cpp -o test -DSFML_STATIC -I C:\SFML\include -L C:\SFML\lib -lsfml-graphics-s -lsfml-window-s -lsfml-audio-s -lsfml-system-s -lopenal32 -lvorbisfile -lvorbisenc -lvorbis -logg -lFLAC -ljpeg -lfreetype -lgdi32 -lopengl32 -lwinmm
int main(int argc, char* argv[])
{
sf::SoundBuffer buffer;
if (!buffer.loadFromFile("recording.ogg")){
return EXIT_FAILURE;
}
const sf::Int16* samples = buffer.getSamples();
size_t samples_count = buffer.getSampleCount();
sf::Int16 newSamples[samples_count];
//Reversing samples
for(int i = 0; i <= samples_count; i++){
newSamples[i] = samples[samples_count-i];
}
sf::SoundBuffer newBuffer;
if(!newBuffer.loadFromSamples(&newSamples[0], samples_count, 2, 44100)){
cout << "Unable to load from new samples" << endl;
}
sf::Sound snd(newBuffer);
snd.play();
cin.ignore();
cout << "Done" << endl;
return EXIT_SUCCESS;
}
EDIT: Apparently I had to use the same number of channels at the original buffer (original only had 1).
Anyone know why I can't just set it to 2? Why is it silent if I set the new buffer to 2 instead of the original (1) ?