Hi I'm making a piano program(simple console application using sfml to play piano on the computer keyboard).
When I compile it in windows everything is superfast. When I press a button on my keyboard the sound plays instantly.
So yesterday I installed code::blocks on my linux mint gloria 7 installation on my laptop. I had some trouble setting everything up but in the end I got everything to work. The problem is, when I compile it in linux, with gcc compiler and linux settings(no .exe in wine :v:) it's slower!
I press a key on the keyboard, but the sound plays about a second later!
Here is the code:
#include <SFML/Window.hpp>
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>
sf::Music Piano[100];
void PlayPiano(float pitch);
int width = sf::VideoMode::GetMode(0).Width;
int height = sf::VideoMode::GetMode(0).Height;
int main()
{
//I know I shouldnt be doing this, but I dont know of any other way, Im still learning. Could you help me with this too?
for (int i = 0;i < 100; i++){
//Piano[i].OpenFromMemory(Piano[0]);
Piano[i].OpenFromFile("piano.ogg");
}
// Create the main window
sf::RenderWindow App(sf::VideoMode::GetMode(0), "Piano!", sf::Style::Fullscreen);
// Piano picture
sf::Image pianopic;
pianopic.LoadFromFile("PianoPic.tga");
sf::Sprite PianoSprite;
PianoSprite.SetImage(pianopic);
PianoSprite.SetPosition(0,0);
PianoSprite.SetCenter(0, 0);
PianoSprite.Resize(width, height);
App.Clear(sf::Color(0, 100, 0));
App.Draw(PianoSprite);
App.Display();
sf::Event PressKey;
std::cout << "Start playing the piano!"<<std::endl << "Press escape to quit!" << std::endl;
// Start main loopv
bool running = true;
while (running){
while(App.GetEvent(PressKey)){
if (PressKey.Type == sf::Event::KeyPressed) {
//Toets ingedrukt
switch(PressKey.Key.Code){
//I removed some cases here, I only left the escape and I button, but they are there in the real program.
case(sf::Key::I):
PlayPiano(1);
break;
case (sf::Key::Escape):
App.Close();
running = false;
break;
default:
break;
}
}
}
}
return EXIT_SUCCESS;
}
void PlayPiano(float pitch){
//If one piano sound is also playing, then play the next piano sound(this way you can use multiple tones at the same time)
for (int i = 0; i < 100; i++){
if (Piano[i].GetStatus() != Piano[i].Playing){
Piano[i].Stop();
Piano[i].SetPitch (pitch);
std::cout << "PLAYING TONE" << std::endl;
Piano[i].Play();
break;
}
}
}
The windows code is about the same and it runs perfectly.
about the "PLAYING TONE" cout:
WHen I press the I button, I immediately see "PLAYING TONE" in the console screen, but the sound plays a second later!
I made some couts