// SFML 1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <SFML\Audio.hpp>
#include <Windows.h>
#include <thread>
#include <iostream>
#include "MethodHeaders.h"
#include <string>
#include <string.h>
int main(int nNumberOfArgs, char *pszArgs[]) {
//check if audio capture is available
if (!sf::SoundBufferRecorder::isAvailable())
{
std::cout << "error: audio capture is not available on this system" << std::endl;
std::cin.get();
}
else
{
// create the recorder
HandleSamples sampler;
std::vector<std::string> devices = sampler.getAvailableDevices();
std::cout << !devices.empty() << std::endl;
if (!(devices.empty())) {
HandleSamples sampler;
sampler.setDevice(devices.at(0));
sampler.start();
std::cout << "sampler has started" << std::endl;
Sleep(1000000);
sampler.stop();
}
else
// handle if no microphone can be detected
{
std::cout << "error: There is no audio input device detected on this system" << std::endl;
std::cin.get();
}
}
}
void handlePitch(float pitch) {
std::cout << pitch << std::endl;
}
//sampler.cpp
#include "stdafx.h"
#include <SFML\Audio.hpp>
#include <thread>
#include <iostream>
#include "MethodHeaders.h"
bool HandleSamples::onProcessSamples(const sf::Int16* samples, std::size_t sampleCount) {
sf::Music music;
music.openFromMemory(samples, sampleCount);
float pitch = music.getPitch();
music.play();
handlePitch(pitch);
return true;
}
This is the error I get.
Failed to open sound file from memory (format not supported)
Failed to play audio stream: sound parameters have not been initialized (call initialize() first)
How would I fix this?