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

Author Topic: Piano fast in windows, slow in linux?  (Read 16593 times)

0 Members and 1 Guest are viewing this topic.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Piano fast in windows, slow in linux?
« Reply #15 on: July 22, 2009, 03:51:23 pm »
Correct :)
Laurent Gomila - SFML developer

FPtje

  • Newbie
  • *
  • Posts: 14
    • View Profile
Piano fast in windows, slow in linux?
« Reply #16 on: July 22, 2009, 03:58:38 pm »
By the way, the same program on the windows installation on the same laptop is fast. so Linux is the problem.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Piano fast in windows, slow in linux?
« Reply #17 on: July 22, 2009, 07:59:24 pm »
Quote from: "Laurent"
Here is a quick and dirty replacement:
Code: [Select]
...
std::vector<sf::Music*> Piano;
...

int main()
{
    Piano.resize(100, new sf::Music(10000));
    ...

    for (int i = 0; i < 100; ++i)
        delete Piano[i];

    return EXIT_SUCCESS;
}

Be careful, since std::vector::resize() only copies the pointer and not the value behind it. 99 of 100 delete-statements result in undefined behaviour.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Piano fast in windows, slow in linux?
« Reply #18 on: July 22, 2009, 08:42:53 pm »
That's what we said previously ;)
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Piano fast in windows, slow in linux?
« Reply #19 on: July 22, 2009, 09:58:37 pm »
Oh sorry, didn't see that... :oops:
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

FPtje

  • Newbie
  • *
  • Posts: 14
    • View Profile
Piano fast in windows, slow in linux?
« Reply #20 on: July 23, 2009, 11:12:03 pm »
So does anyone know the cause of this problem?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Piano fast in windows, slow in linux?
« Reply #21 on: July 24, 2009, 03:06:46 pm »
Have you tried using sf::Sound instead of sf::Music? sf::Music is really overkill for playing such a small sound, the audio samples are reloaded/streamed from the disk every time you play the music.
Laurent Gomila - SFML developer

FPtje

  • Newbie
  • *
  • Posts: 14
    • View Profile
Piano fast in windows, slow in linux?
« Reply #22 on: July 24, 2009, 06:02:32 pm »
Yes I have, someone helped me with it:
Code: [Select]
#include <SFML/Window.hpp>
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>

sf::Sound Piano[100];
sf::SoundBuffer PianoSound;

void PlayPiano(float pitch);
int width = sf::VideoMode::GetMode(0).Width;
int height = sf::VideoMode::GetMode(0).Height;

int main()
{
    PianoSound.LoadFromFile( "piano.wav");
    //I know I shouldnt be doing this, but I dont know of any other way, Im still learning
    for (int i = 0;i < 100; i++){
        Piano[i].SetBuffer(PianoSound);
    }

    // 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){
                    // insert cases here.
                    case (sf::Key::Escape):
                        App.Close();
                        running = false;
                        break;
                    default:
                        break;
                }
            }
        }
    }

    return EXIT_SUCCESS;
}

void PlayPiano(float pitch){
    for (int i = 0; i < 100; i++){
        if (Piano[i].GetStatus() != Piano[i].Playing){
             Piano[i].Stop();
             Piano[i].SetPitch (pitch);
             Piano[i].Play();
             break;
        }
    }
}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Piano fast in windows, slow in linux?
« Reply #23 on: July 24, 2009, 07:06:12 pm »
And it made no difference at all?
Laurent Gomila - SFML developer

FPtje

  • Newbie
  • *
  • Posts: 14
    • View Profile
Piano fast in windows, slow in linux?
« Reply #24 on: July 25, 2009, 10:27:25 am »
No difference at all.

FPtje

  • Newbie
  • *
  • Posts: 14
    • View Profile
Piano fast in windows, slow in linux?
« Reply #25 on: July 29, 2009, 08:54:20 pm »
There seems to be a delay in this application too:

Code: [Select]

////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Audio.hpp>
#include <iomanip>
#include <iostream>


////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////
int main()
{
    int a;
    std::cin >> a;
    std::cout << "TEST" << std::endl;
    // Load a sound buffer from a wav file
    sf::SoundBuffer Buffer;
    if (!Buffer.LoadFromFile("sound.wav"))
        return EXIT_FAILURE;

    // Display sound informations
    std::cout << "sound.wav :" << std::endl;
    std::cout << " " << Buffer.GetDuration()      << " sec"           << std::endl;
    std::cout << " " << Buffer.GetSampleRate()    << " samples / sec" << std::endl;
    std::cout << " " << Buffer.GetChannelsCount() << " channels"      << std::endl;

    // Create a sound instance and play it
    sf::Sound Sound(Buffer);
    Sound.Play();

    // Loop while the sound is playing
    while (Sound.GetStatus() == sf::Sound::Playing)
    {
        // Display the playing position
        std::cout << "\rPlaying... " << std::fixed << std::setprecision(2) << Sound.GetPlayingOffset() << " sec";

        // Leave some CPU time for other threads
        sf::Sleep(0.1f);
    }
    std::cout << std::endl;

    // Wait until the user presses 'enter' key
    std::cout << "Press enter to exit..." << std::endl;
    std::cin.ignore(10000, '\n');

    return EXIT_SUCCESS;
}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Piano fast in windows, slow in linux?
« Reply #26 on: July 29, 2009, 09:20:16 pm »
In this case it could be the loading.
Laurent Gomila - SFML developer

FPtje

  • Newbie
  • *
  • Posts: 14
    • View Profile
Piano fast in windows, slow in linux?
« Reply #27 on: August 01, 2009, 12:51:47 pm »
no it isn't

drmoth

  • Newbie
  • *
  • Posts: 9
    • View Profile
Piano fast in windows, slow in linux?
« Reply #28 on: November 18, 2009, 01:37:27 am »
Hi,

I've recently been running the Linux version of the audio subsystem of SFML and it works fine. The latency with the latest version of OpenAL Soft is really very good under Alsa (I have a crappy integrated laptop sound card).

You can tweak the buffer size of the OpenAL Soft driver in a config file in order to improve latency. Download the OpenAL Soft source package and read the contents of the alsoft.conf file.

If you have really large latencies you are possibly running OpenAL under pulseaudio.

Latencies in audio occur under Linux when your audio is not set up properly. There's a good guide to lowering latencies of audio under Linux that comes with the demo of Pianoteq (http://www.pianoteq.com/)

 

anything