Just started looking into the audio buffer for SFML 2.1 to try to record from my microphone and play it back in a stream.
However, i'm having issues even getting the basics compiled before even getting to what i'm trying.
I don't have much experience with virtual void functions, but I basically copy/pasted the code from
http://www.sfml-dev.org/documentation/2.1/classsf_1_1SoundRecorder.phpand i'm not having any luck.
A few problems i'm having.
if (!recorder.start())
start is a void function, so I can't check if it returns true or false since it returns nothing, but the code on the example used it
virtual bool onProcessSamples(const Int16* samples, std::size_t sampleCount)
My compiler isn't recognizing Int16 as a data type. I tried to figure out which header this would be included in, and I wasn't having any luck. I just changed it to UINT16* for now in my code, but i'm not sure if these are the same.
Here is my code
#ifdef SFML_STATIC
#pragma comment(lib, "glew.lib")
#pragma comment(lib, "freetype.lib")
#pragma comment(lib, "jpeg.lib")
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "winmm.lib")
#pragma comment(lib, "gdi32.lib")
#endif // SFML_STATIC
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <SFML/Window.hpp>
#include <Windows.h>
#include <iostream>
#include <string>
using namespace std;
class CustomRecorder : public sf::SoundRecorder
{
virtual bool onStart() // optional
{
// Initialize whatever has to be done before the capture starts
// Return true to start playing
return true;
}
virtual bool onProcessSamples(const UINT16* samples, std::size_t sampleCount)
{
// Do something with the new chunk of samples (store them, send them, ...)
// Return true to continue playing
return true;
}
virtual void onStop() // optional
{
// Clean up whatever has to be done after the capture ends
}
};
int main()
{
if (CustomRecorder::isAvailable())
{
CustomRecorder recorder; //Error #1
if (!recorder.start()) //Error #2
return -1;
recorder.stop();
}
return 0;
}
Error #1
1 IntelliSense: object of abstract class type "CustomRecorder" is not allowed:
pure virtual function "sf::SoundRecorder::onProcessSamples" has no overrider c:\Users\Jacob\Documents\Visual Studio 2013\Projects\SFMLGame\SFMLGame\Main.cpp 44 18 SFMLGame
Error #2
2 IntelliSense: expression must have bool type (or be convertible to bool) c:\Users\Jacob\Documents\Visual Studio 2013\Projects\SFMLGame\SFMLGame\Main.cpp 45 8 SFMLGame
Thanks for taking the time to read. Any input is appreciated. I just want to be able to get this compile so I can try to learn how to record and play to/from streamed audio buffers so that I can work on a basic voip later. Just really new to sound buffers and SFML.