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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Eilessa

Pages: [1]
1
Audio / Re: getPlayingOffset returns 0 when it shouldn't
« on: August 08, 2014, 04:00:10 pm »
Thank you so much! Hope you have better luck than I've had :-\

2
Audio / Re: getPlayingOffset returns 0 when it shouldn't
« on: August 08, 2014, 10:31:02 am »
I hope the following program fully satisfies your request. If not, let me know what I need to fix and I'll update! This is as minimal as I can make it, all in the main.cpp-file:

#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <iostream>

sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
bool wasKeyPressed = false; // Used so that it only detects the first keypress and not continuously.
sf::SoundBuffer m_origBuffer;
sf::SoundBuffer m_currBuffer;
sf::Sound m_sound;

void changeBuffer()
{
        int sampleCount = m_origBuffer.getSampleCount();
        const sf::Int16* origSamples = m_origBuffer.getSamples();

        m_currBuffer.loadFromSamples(origSamples, sampleCount, m_origBuffer.getChannelCount(), m_origBuffer.getSampleRate());
        sf::Time time = m_sound.getPlayingOffset();
        std::cout << "Sound offset at change: " << time.asMilliseconds() << "\t";
        m_sound.setBuffer(m_currBuffer);
        m_sound.play();
        m_sound.setPlayingOffset(time);

        std::cout << "Offset set to time: " << time.asMilliseconds() << std::endl;
}

int main()
{
        if (!m_origBuffer.loadFromFile("../Assets/Ape.wav"))
                std::cout << "ERROR: Failed to load file!" << std::endl;
        m_sound.setBuffer(m_origBuffer);
        m_sound.setLoop(true);
        m_sound.play();

        while (window.isOpen())
        {
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                window.close();
                }

                window.clear();

                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Num1))
                {
                        if (!wasKeyPressed)
                                changeBuffer();
                        wasKeyPressed = true;
                }
                else
                        wasKeyPressed = false;

                window.display();
        }

        return 0;
}

Pressing the 1 key makes the sound restart from the beginning of the clip. The debug printing of the time value shows that the first time, there is a value other than 0, but all the other times, the time is 0. This is peculiar as I would have expected some other value from getPlayingOffset().

I have tried two modifications to the code above:
  • Commenting out the row m_sound.setBuffer(m_currBuffer); this worked, no lag and time != 0
  • Changing that same row to m_sound.setBuffer(m_origBuffer); which also worked, no lag and time was != 0.

It is peculiar though, as this example merely copies the m_origBuffer by sending the samples unchanged into the m_currBuffer load function as well as copy all other information from m_origBuffer. I can't make out what to do of it as I can't think of any ways of completing my assignment without changing buffers.

Thank you so much for the time you take to help me!

3
Audio / Re: getPlayingOffset returns 0 when it shouldn't
« on: August 08, 2014, 09:36:55 am »
Here is the full code of that part (edited out my debug printing when posting before)

   
m_currBuffer.loadFromSamples(samples, sampleCount, m_origBuffer.getChannelCount(), m_origBuffer.getSampleRate());
        m_sound.pause();
        sf::Time time = m_sound.getPlayingOffset();
        std::cout << "Sound offset at change: " << time.asMilliseconds() << "\t";
        m_sound.setBuffer(m_currBuffer);
        m_sound.play();
        m_sound.setPlayingOffset(time);

        std::cout << "Offset set to time: " << time.asMilliseconds() << std::endl;

As said previously, I find that time is always 0. That seems erroneous to me, but it's probably that I have misunderstood something about how to use the functions. I just can't figure out what!

4
SFML website / Re: Unhelpful Tutorial
« on: August 08, 2014, 09:32:22 am »
I think that would be clearer and very helpful  :)

You're right - it's unfair to call the entire tutorial unhelpful because of this one thing. However it was for me as this stumped me and prevented me from doing any of it. That's why all of it was unhelpful to me specifically.

5
Audio / Re: getPlayingOffset returns 0 when it shouldn't
« on: August 08, 2014, 09:26:08 am »
Thank you for your reply! Unfortunately, I have tried that too - this is just left from when I tried another order to see if that was the error. Then I forgot to change it back before posting. I'll update it!

Thanks for the hint about memory leaks :)

Edit: Right, the problem I think is that time is always 0 apart from the very first time this is performed. I think that's the problem. That's why I think I have made a mistake with getPlayingOffset

6
Audio / getPlayingOffset returns 0 when it shouldn't
« on: August 08, 2014, 08:50:38 am »
Hi,

I must be missing something, because it doesn't work. First of all, a bit of background of what I'm trying to do: I have an assignment in school for which I need to modify audio. The bit I'm stuck on is changing volume. Because of the assignment - I'm not allowed to use the built in volume function.

What I'm trying to do: I have the original buffer, as well as a "current buffer". This is because I want to keep the original file for easy recovery after making changes (more are to come). I copy the contents of the original buffer into an sf::Int16 array that I modify, load into the current buffer and then I call my sound variable's setBuffer-method passing in the current buffer. So far so good, the sound still works.

But, this causes the sound to restart from the beginning (naturally) which I don't want. To solve that, before I change the buffer, I save the playing offset to a variable and after the buffer has been changed, I set the playing offset to that time. As this did not work, I printed the values I got from getPlayingOffset and it turns out, other than the first time, this returns 0. Why is this?

The code segment for the above:
   
int sampleCount = m_origBuffer.getSampleCount();
        const sf::Int16* origSamples = m_origBuffer.getSamples();
        sf::Int16* samples = new sf::Int16[sampleCount];

        for (int i = 0; i < sampleCount; ++i)
        {
                samples[i] = origSamples[i] * m_volume;
        }

        m_currBuffer.loadFromSamples(samples, sampleCount, m_origBuffer.getChannelCount(), m_origBuffer.getSampleRate());
        sf::Time time = m_sound.getPlayingOffset();
        std::cout << "Sound offset at change: " << time.asMilliseconds() << "\t";
        m_sound.setBuffer(m_currBuffer);
        m_sound.play();
        m_sound.setPlayingOffset(time);

        std::cout << "Offset set to time: " << time.asMilliseconds() << std::endl;

Thankful for help!

7
SFML website / Re: Unhelpful Tutorial
« on: August 08, 2014, 08:30:49 am »
I group this tutorial in the same category as the tutorials helping you set up SFML with for instance Visual Studio. Then it could be argued that in fact they DO instruct the user with regards to the compiler.

Regardless... ALL I'M SAYING IS: It would be helpful and much clearer to a lot of beginners who may never have heard of CMake before (like me) to add that short text, less than a sentence. You may not agree, but if it indeed is helpful to people - why do you keep opposing it so much. Because I refuse to believe you think these people should just get out and not use SFML.

Bottom line - the other tutorials have impressed me to no end with the information and how helpful they are to beginners. This one didn't. I have a solution, do what you want with it. Use it (or modify it) and improve the tutorial, or ignore it, arguing that you yourselves already know the information so it needn't be included.

8
SFML website / Re: Unhelpful Tutorial
« on: August 05, 2014, 04:25:31 pm »
As you yourself quotes: "all the needed dependencies are provided directly with SFML", which is very easily assumed to include CMake. If the tutorial was truly meant to be helpful, and for beginners, this would be clarified. All that is needed is a parenthesis saying "(except for CMake)". If that is clear to you, great. But it is very arrogant and unhelpful to refuse it and treat all who do not immediately see it as idiots.

Thank you but no thank you for your help

9
SFML website / Unhelpful Tutorial
« on: August 05, 2014, 04:10:19 pm »
First of all, thank you for your tutorials. They are amazing!

However, there is one I find I am not helped by at all. the http://www.sfml-dev.org/tutorials/2.1/compile-with-cmake.php. It says with windows, I need not install anything, but I cannot get it to work. Am I supposed to install CMake? I am not an unintelligent person so this is something you really should look into clarifying. If you clearly write nothing needs to be installed, then it should be specified if there is indeed something that needs to be installed.

Pages: [1]