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

Author Topic: Accessing the buffer  (Read 2300 times)

0 Members and 1 Guest are viewing this topic.

PJ

  • Newbie
  • *
  • Posts: 3
    • View Profile
Accessing the buffer
« on: September 01, 2017, 11:44:13 am »
Hi guys, im quite new to SFML. I'm trying to access the samples but when i apply the sound.getSamples() function all i obtain is an Int16 value.I was expecting an array of integer values to apply FFT later on. Any tip or help?

And what should i use to get a real-time array? Sound or Music?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Accessing the buffer
« Reply #1 on: September 01, 2017, 11:52:14 am »
Quote
when i apply the sound.getSamples() function all i obtain is an Int16 value
What is the class of "sound"? Don't forget to loook at the documentation and tutoriels, classes and functions are all well described.

Quote
And what should i use to get a real-time array? Sound or Music?
You want to get real-time samples from what source?
Laurent Gomila - SFML developer

PJ

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Accessing the buffer
« Reply #2 on: September 01, 2017, 12:48:09 pm »
#include <iostream>
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include <fftw3.h>
#include <Windows.h>


int main()
{
        // Create the main window
        sf::RenderWindow window(sf::VideoMode(800, 600), "OUR TEST");
        sf::SoundBuffer buffer;
        sf::Sound sound;
        if (!buffer.loadFromFile("Etherwood - Spoken.wav"))
        {
                std::cout << "ERROR"<<std::endl;
        }
        sound.setBuffer(buffer);
        sound.setVolume(25);

        std::cout << "Sample Rate: " << buffer.getSampleRate() << std::endl;

        while (window.isOpen())
        {
                // Process events
                sf::Event event;
                while (window.pollEvent(event))
                {
                        /*while (sound.getStatus() == sf::Sound::Playing) {
                                std::cout << buffer.getSamples() << std::endl;
                                Sleep(400);
                        }*/

                        switch (event.type)
                        {
                        case sf::Event::Closed:
                                window.close();
                                break;
                        case sf::Event::KeyPressed:
                                if (event.key.code == sf::Keyboard:: P)
                                {
                                        sound.play();
                                }
                                if (event.key.code == sf::Keyboard::Escape)
                                        window.close();
                                break;
                        }
                }
                window.clear();
                window.display();
        }
        return EXIT_SUCCESS;
}

This is my entire code. I run the getSamples() on the buffer.
I want to get a real time array from my buffer that is streaming the audio
« Last Edit: September 01, 2017, 12:59:40 pm by Laurent »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Accessing the buffer
« Reply #3 on: September 01, 2017, 01:02:32 pm »
SoundBuffer::getSamples() returns a pointer to the array of samples.

Then, to know which samples are being played, you have to perform a lookup into this array based on the current playing position of the Sound (you'll have to multiply the time position by the sample rate and channel count to get the sample index).

As I said, everything's described in the documentation, take the time to read it.
Laurent Gomila - SFML developer

PJ

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Accessing the buffer
« Reply #4 on: September 01, 2017, 01:41:25 pm »
Ok, thanks for the reply, i'll find out

 

anything