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 - madpl1239

Pages: [1]
1
Audio / Re: Audio is recording, but not playing, im no idea why this is.
« on: January 13, 2022, 10:00:11 pm »
thanks to kojack for the suggestions. It seems that it may be as you say. In my search for bedbugs, I go in this direction. Thanks one time yet. Maybe someone have any other proposition?

2
Audio / Re: Audio is recording, but not playing, im no idea why this is.
« on: January 13, 2022, 07:52:31 pm »
eXpl0it3r thanks so suggestion. I did a little experiment and added one line of code from while (...) as below:


                if(switch_play)
                {
                        // here is problem: this button not changing color, why?
                        buttonPlay.setFillColor(sf::Color::Red);

                        switch_play = false;
                        snd.play();
                       
                         // when add this line below sound is playing:)))
                         while(snd.get()->getStatus() == sf::SoundSource::
                                       Status::Playing)
                                ;
                }
                else
                { .... }
 

Awesome ;D sound is playing now!!!
But still button play doesn't change color, and according to the code it should. The record button works as expected. And now here's the problem. Why it is: Why one button changes color and the other does not. According to the code, both buttons should work properly. Any propositions, suggestions? Maybe someone know why it is.

3
Audio / Audio is recording, but not playing, im no idea why this is.
« on: January 11, 2022, 09:29:42 pm »
Hello everyone, maybe someone help me. Last times im trying make short code: small window application to recording signal from my microphone. Of course all in SFML :P  (window, buttons and audio).
I have problem.  When launch app (compilation at Kubuntu: GCC 7.5, SFML 2.5.1, this same at Window - i compiled too)
recording is ok, but when i press 'play' button i dnot hear anything - i no idea why this is so . 'Record' button is on the left, 'play' button is on the right, 'save' button below. 'Play' button does not change color, and according to the code it should. Im attaching source code bellow:
 
/*
 * main.cpp
 *
 * Recording, playing and save microphone.
 *
 * 08-01-2022 by madpl (aka madpl1239)
 */

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

constexpr int WIDTH = 400;
constexpr int HEIGHT = 300;
constexpr int SAMPLERATE = 44100;

// colors
sf::Color bishop(255, 0, 128, 255);
sf::Color amarant(230, 28, 102, 255);
sf::Color aquamarine(127, 255, 212, 255);
sf::Color chabre(51, 0, 204, 255);

inline sf::RenderWindow win;
inline sf::SoundBuffer buffer;

inline sf::RectangleShape buttonRec(sf::Vector2f(120, 60));
inline sf::RectangleShape buttonPlay(sf::Vector2f(120, 60));
inline sf::RectangleShape buttonSave(sf::Vector2f(120, 60));


class CSound : public sf::Sound
{
public:
        CSound():
                m_switch(false)
        {
        }
       
        virtual ~CSound()
        {
                m_switch = false;
        }

        void play()
        {
                m_switch = true;
                sf::Sound::play();
        }
       
        void stop()
        {
                m_switch = false;
                sf::Sound::stop();
        }
       
        bool isPlaying()
        {
                return m_switch;
        }

private:
        bool m_switch;
};


class CRecorder : public sf::SoundBufferRecorder
{
public:
        CRecorder():
                m_sampleRate(44100),
                m_switch(false)
        {
        }

        virtual ~CRecorder()
        {
                m_sampleRate = 0;
                m_switch = false;
        }

        void start()
        {
                m_switch = true;
                sf::SoundBufferRecorder::start(m_sampleRate);
        }
       
        void stop()
        {
                m_switch = false;
                sf::SoundBufferRecorder::stop();
        }
       
        bool isRecording()
        {
                return m_switch;
        }
       
private:
        int m_sampleRate;      
        bool m_switch;
};


int main(void)
{
        sf::Clock clk;
       
        CRecorder rec;
        CSound snd;
       
        // buttons definitions
        buttonRec.setOrigin(60, 30);
        buttonRec.setPosition(80, 140);
        buttonRec.setFillColor(aquamarine);
        buttonRec.setOutlineThickness(2);
        buttonRec.setOutlineColor(sf::Color::Black);
               
        buttonPlay.setOrigin(60, 30);
        buttonPlay.setPosition(320, 140);
        buttonPlay.setFillColor(aquamarine);
        buttonPlay.setOutlineThickness(2);
        buttonPlay.setOutlineColor(sf::Color::Black);
       
        buttonSave.setOrigin(60, 30);
        buttonSave.setPosition(200, 240);
        buttonSave.setFillColor(aquamarine);
        buttonSave.setOutlineThickness(2);
        buttonSave.setOutlineColor(sf::Color::Black);
       
        win.create(sf::VideoMode(WIDTH, HEIGHT), "micRecord v0.5",
                          sf::Style::Titlebar | sf::Style::Close);
       
        if(!win.isOpen())
                return -1;
       
        win.setPosition(sf::Vector2i(500, 200));
       
        if(sf::SoundBufferRecorder::isAvailable() == false)
        {
                std::cout << "Sorry, audio capture is not supported
                                                      by your system.\n"
;
               
                return -1;
        }
       
        bool switch_record = false;
        bool switch_play = false;
        bool switch_save = false;
       
        float elapsedTime = 0.0f;
        clk.restart();
       
        sf::Event e;
        while(win.isOpen())
        {
                while(win.pollEvent(e))
                {
                        if(e.type == sf::Event::Closed)
                                win.close();
                       
                        if(e.type == sf::Event::KeyPressed and
                           e.key.code == sf::Keyboard::Escape)
                                win.close();
                       
                        if(e.type == sf::Event::MouseButtonPressed and
                           e.mouseButton.button == sf::Mouse::Left)
                        {
                                sf::Vector2i localMousePos =
                                               sf::Mouse::getPosition(win);

                                if(buttonRec.getGlobalBounds().
                                   contains(localMousePos.x, localMousePos.y))
                                {
                                        switch_record = !switch_record;
                                        switch_play = false;
                                        switch_save = false;
                                }

                                if(buttonPlay.getGlobalBounds().
                                   contains(localMousePos.x, localMousePos.y))
                                {
                                        switch_play = !switch_play;
                                        switch_record = false;
                                        switch_save = false;
                                }

                                if(buttonSave.getGlobalBounds().
                                   contains(localMousePos.x, localMousePos.y))
                                {
                                        switch_save = !switch_save;
                                        switch_record = false;
                                        switch_play = false;
                                }
                        }
                }
               
                if(switch_record)
                {
                        buttonRec.setFillColor(sf::Color::Red);
                       
                        if(!rec.isRecording())
                                rec.start();
                }
                else
                {
                        buttonRec.setFillColor(aquamarine);
                       
                        rec.stop();
                       
                        buffer = rec.getBuffer();
                        snd.setBuffer(buffer);
                        snd.setLoop(false);
                }
               
                if(switch_play == true)
                {
                        buttonPlay.setFillColor(sf::Color::Red);
                        switch_play = false;
                        snd.play();
                }
               
                if(switch_play == false)
                {
                        if(snd.getStatus() == sf::SoundSource::Playing)
                        {
                                buttonPlay.setFillColor(sf::Color::Red);
                        }
                        else
                        {
                                buttonPlay.setFillColor(aquamarine);
                        }
                }
                       
                if(switch_save)
                {
                        buttonSave.setFillColor(amarant);
                        buffer.saveToFile("./rec.ogg");
                       
                         elapsedTime = clk.getElapsedTime().asSeconds();
                        if(elapsedTime > 3)
                        {
                                buttonSave.setFillColor(aquamarine);
                                switch_save = false;
                                clk.restart();
                        }
                }
                else
                        buttonSave.setFillColor(aquamarine);
                       
                win.clear(chabre);
               
                win.draw(buttonRec);
                win.draw(buttonPlay);
                win.draw(buttonSave);
               
                win.display();
        }
               
        std::cout << "\ndone.\n";
       
        return 0;
}
 

4
SFML projects / Re: FLIGHT
« on: June 26, 2020, 07:56:46 pm »
I probably found error. It is in AssetManager::LoadResources()::SetapShader.
I used to compiling mingw8.1.0seh (gcc for Windows). I think, that is something bad
with path to shaders or mingw not so good compiling function (method) to read shaders programs. I curently investigeting :D this problem.

He he - i talk to myself :P


5
SFML projects / Re: FLIGHT
« on: June 25, 2020, 06:06:15 pm »
Hello:)))

Im new on this forum, but old programmer:))) I was compiling FLIGHT on Win7 and mingw-64-seh version. But when i run FLIGHT i have follow message and code crashed.

Warning: The created OpenGL context does not fully meet the settings that were requested
Requested: version = 3.3 ; depth bits = 24 ; stencil bits = 8 ; AA level = 2 ; core = true ; debug = true ; sRGB = false
Created: version = 3.3 ; depth bits = 24 ; stencil bits = 8 ; AA level = 2 ; core = true ; debug = true ; sRGB = false

Somebody help me? i have OpenGL (GLSL) 4.3 version :P

Pages: [1]
anything