Hi. I am trying to create a small audio based application that uses a class that inherits from SoundRecorder, and overrides the onProcessSamples function.
I am getting an error that says:
"In function `NoiseCancellor::onProcessSamples(short const*, unsigned long)': NoiseCancellor.cpp: (.text+0xef): undefined reference to `sf::SoundBuffer::loadFromSamples(short const*, unsigned long long, unsigned int, unsigned int)'
colled2: error: ld return 1 exit status
First of all I AM linking all of the sfml libraries, including -lsfml-audio.
I am using Linux Mint 17.1 (Rebecca) (Ubuntu 14) 64 bit on a 64 bit machine.
My NoiseCancellor.cpp file looks like this:
#include "NoiseCancellor.hpp"
bool NoiseCancellor::onProcessSamples(const sf::Int16* samples, std::size_t sampleCount)
{
sf::Int16* cancelSamples = new sf::Int16[sampleCount];
for (size_t i = 0; i < sampleCount; ++i) {
cancelSamples[i] = -samples[i];
}
sf::SoundBuffer cancelBuffer;
cancelBuffer.loadFromSamples(cancelSamples, sizeof(cancelSamples) * sampleCount, 1, getSampleRate());
sf::Sound cancelSound(cancelBuffer);
cancelSound.play();
return true;
}
~
And my NoiseCancellor.hpp looks like this:
#ifndef NOISE_CANCELLOR_HPP
#define NOISE_CANCELLOR_HPP
#include <SFML/Audio.hpp>
class NoiseCancellor : public sf::SoundRecorder {
bool onProcessSamples(const sf::Int16* samples, std::size_t sampleCount);
};
#endif
I tried to fix it by forcing the parameters to be handled as the types `const Int16 *samples, std::size_t sampleCount, unsigned int channelCount, unsigned int sampleRate`, to exactly coincide with the documentation on the function, by static_casting all the variables as I was passing them into the function, but the error message didn't go away. Then I even tried const_casting the first parameter (since it const), and static casting all the rest. The error still didn't go away. I've been trying to search the internet to see if I could find a solution to this problem, but I didn't. Any help with this would be much appreciated. Thank you.