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

Author Topic: Scratchvaders - a project of silliness and woo  (Read 4449 times)

0 Members and 1 Guest are viewing this topic.

fallahn

  • Hero Member
  • *****
  • Posts: 507
  • Buns.
    • View Profile
    • Trederia
Scratchvaders - a project of silliness and woo
« on: August 11, 2013, 02:17:49 pm »
So apart from coding I like to spend my time playing with old school vinyl, and I got to thinking what would happen if I tried to combine the two. The answer was this:



Just a bit of fun really, the audio input triggers the 'fire' function when it peaks - it would work just as well if you were to sit there shouting 'pew pew pew!' in to a microphone. I had to reduce the sleep time in SFML audio to 1ms to make it sensitive enough to work, but it also had the side effect of causing the music to skip / stutter when using the screen capture software (it works fine other wise). It's no DJ Hero but a good learning experience :)

BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
Re: Scratchvaders - a project of silliness and woo
« Reply #1 on: August 11, 2013, 06:00:09 pm »
I really like the concept, execution seems a bit simplistic but overall great!
« Last Edit: August 12, 2013, 12:41:22 am by BaneTrapper »
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
AW: Re: Scratchvaders - a project of silliness and woo
« Reply #2 on: August 11, 2013, 08:21:50 pm »
Hehe looks interesting. I guess it could also be used for other things.
Btw how exactly do you decide when to shoot?

I really like the concept, execution seems a bit simplistic but overall great!
For that statement you had to fully quote him? Please use quotes to specialize the answer for a specific paragraph. :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

fallahn

  • Hero Member
  • *****
  • Posts: 507
  • Buns.
    • View Profile
    • Trederia
Re: AW: Re: Scratchvaders - a project of silliness and woo
« Reply #3 on: August 11, 2013, 09:21:04 pm »
Hehe looks interesting. I guess it could also be used for other things.
Btw how exactly do you decide when to shoot?

Well.. I don't really. I just get into the groove.... Like I say it's not really a serious thing, it was kind of inspired by a scene from qbert's wave twisters and I thought 'hey it would be cool to shoot aliens with scratching' or something. Unless someone wants the source I doubt I'll do anything else to it any time soon.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Scratchvaders - a project of silliness and woo
« Reply #4 on: August 11, 2013, 09:27:35 pm »
Oh I rather meant code wise. How do you decide when scratching is happening and when not? ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

fallahn

  • Hero Member
  • *****
  • Posts: 507
  • Buns.
    • View Profile
    • Trederia
Re: Scratchvaders - a project of silliness and woo
« Reply #5 on: August 11, 2013, 09:55:40 pm »
Ah  ;D

Well there's not much to it. The audio input class just inherits from sf::SoundRecorder and uses the buffer to create a VU meter:

bool AudioIn::onProcessSamples(const sf::Int16* samples, std::size_t sampleCount)
{
        //sum and average the value of the current set of samples
        sf::Int64 sum = 0;
        for(std::size_t i = 0; i < sampleCount; i++)
        {
                sum += std::abs(samples[i]);
        }

        float avg = static_cast<float>(sum / sampleCount);
     
    //10 * log() == power, 20 * log() == amplitude
        //See: http://www.sengpielaudio.com/calculator-db.htm
        m_dB = (avg > 0) ? 20.f * log10(avg / m_reference) : -1000000.f; //in theory could go to -inf so we cut off somewhere
        sf::Lock lock(m_mutex);
        Signal = (m_dB > m_threshold);

        return true;
}
 

Signal is an atomic bool (because the audio input runs in its own thread) which is set to true if the input level is above a designated value. In this case that value is set by the calibration mode you see at the beginning of the video where I check the input volume of the record. That way you ultimately get a boolean value which you can test much in the same ways as sf::Keyboard::isKeyPressed(), eg:

if(AudioIn.Signal) fire();
 

fallahn

  • Hero Member
  • *****
  • Posts: 507
  • Buns.
    • View Profile
    • Trederia
Re: Scratchvaders - a project of silliness and woo
« Reply #6 on: April 08, 2014, 01:12:26 pm »
Dragging up an old topic; I found the source for this the other day so I tidied it up and put it on Github