Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Not able to get SoundRecorder Documented example to compile  (Read 3257 times)

0 Members and 1 Guest are viewing this topic.

Pindrought

  • Newbie
  • *
  • Posts: 11
    • View Profile
Not able to get SoundRecorder Documented example to compile
« on: February 19, 2015, 11:45:11 am »
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.php
and i'm not having any luck.

A few problems i'm having.
Code: [Select]
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

Code: [Select]
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
Code: [Select]
#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
Quote
   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
Quote
   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.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Not able to get SoundRecorder Documented example to compile
« Reply #1 on: February 19, 2015, 12:22:49 pm »
Int16 in the function signature is sf::Int16 and it's defined in the SFML/Config.hpp header.

sf::SoundRecorder::start() doesn't have the return tpye void but bool, as such you can certainly check whether it started or not.

Don't use #pragma comment to link libraries. Linking libraries has nothing to do with your source code. Instead follow the official tutorials and link the libraries in your project settings.

IntelliSense "error" messages are of no interest to anyone, since they could simply be wrong. Compile your application and if you get compilation errors post them here.
« Last Edit: February 19, 2015, 12:25:37 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Not able to get SoundRecorder Documented example to compile
« Reply #2 on: February 19, 2015, 12:36:45 pm »
Quote
sf::SoundRecorder::start() doesn't have the return tpye void but bool, as such you can certainly check whether it started or not.
Only in SFML 2.2, and the OP is using SFML 2.1. However the doc for 2.1 is correct and doesn't contain the line of code that tests the return value of recorder.start().
« Last Edit: February 19, 2015, 12:38:54 pm by Laurent »
Laurent Gomila - SFML developer

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Not able to get SoundRecorder Documented example to compile
« Reply #3 on: February 19, 2015, 12:38:42 pm »
Ah :D

Guess it's time to upgrade.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Pindrought

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Not able to get SoundRecorder Documented example to compile
« Reply #4 on: February 19, 2015, 12:41:34 pm »
Quote
sf::SoundRecorder::start() doesn't have the return tpye void but bool, as such you can certainly check whether it started or not.
Only in SFML 2.2, and the OP is using SFML 2.1. However the doc for 2.1 is correct and doesn't contain the line of code that tests the return value of recorder.start().

Ah this makes sense then.

Thanks a lot both of you! I appreciate your time and i'll upgrade to 2.2 and work through it that way.