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

Author Topic: Accessing music samples?  (Read 5849 times)

0 Members and 1 Guest are viewing this topic.

notshaggy

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Accessing music samples?
« on: April 12, 2015, 05:07:29 pm »
Is there a way to access the samples of a music?

I'm trying to create an audio visualiser using FFTW, so think I need the audio samples to give as input?

Thanks for any help.


notshaggy

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: Accessing music samples?
« Reply #2 on: April 13, 2015, 02:12:14 pm »
Thanks for pointing that out!

However it always gives me the same values when I print out the array, so I'm not really sure if I'm calling it correctly?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Accessing music samples?
« Reply #3 on: April 13, 2015, 02:29:34 pm »
What do you expect? Should they magically change? :)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

notshaggy

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: Accessing music samples?
« Reply #4 on: April 18, 2015, 12:47:52 pm »
I would have expected the samples to have different values as the music is played, yes.

Surely if the samples are the same then the sound played would be one continuous tone?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Accessing music samples?
« Reply #5 on: April 18, 2015, 01:11:08 pm »
No, sf::SoundBuffer stores all the samples of an audio file, it does not stream continuously. As such, the samples only change when you reload them.
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
Re: Accessing music samples?
« Reply #6 on: April 18, 2015, 01:48:08 pm »
If you want to process the samples of a playing sf::Music on the fly, then create your own class derived from it, and override the onGetData virtual function. Something like:

class MyMusic : public sf::Music
{
protected:

    bool onGetData(Chunk& data) override
    {
        if (sf::Music::onGetData(data))
        {
            // ... data contains the next chunk of samples to be played by the music ...
            return true;
        }
        else
            return false;
    }
};

Since sf::Music is triple-buffered, the data that you get there will only be played a few moments later (something like 2 seconds), so you may have to adjust if you want your visualizer to be perfectly synchronized with the music.
Laurent Gomila - SFML developer

notshaggy

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: Accessing music samples?
« Reply #7 on: April 26, 2015, 04:09:49 pm »
Thanks for everyone's help so far.

I tried doing it as above with better results. Is there a way to get onGetData() to run more frequently?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Accessing music samples?
« Reply #8 on: April 26, 2015, 04:39:19 pm »
Nop. It is currently hard-coded in sf::Music (buffer length) and sf::SoundStream (buffer count).
Laurent Gomila - SFML developer

 

anything