Slider changing Frequencies?

edited October 2016 in Library Questions

Hey guys, so I have this slider, which should change the frequencies when you move it, but I don't know how to realise this. Does anyone have an idea on how to do this?

Answers

  • edited October 2016 Answer ✓

    It looks like you figured out how to set the position of the slider with .setPosition(). How do you get the position?

    You also figured out how to set the frequency with currentFreq = Frequency.ofHertz(); and wave.setFrequency(currentFreq);

    So:

    How do you get the current position of the slider? Then, in the draw loop, you can write code that says:

    "set the frequency = get the current slider position"

  • edited October 2016 Answer ✓

    I take that back. You set the screen Position of your sliders, and initialized its Range, but you didn't set its Value.

    Read the "Accessing Controllers" sections of the ControlP5 page. Then try these changes:

    1. You only need a single ControlP5 object -- get rid of cp6, make both sliders with cp5.addSlider
    2. You create your sliders, but you don't name then anything! Declare the global object, then assign to it when you call addSlider in setup e.g.

      Slider sliderHertz;
      
      ...
      
      sliderHertz = cp5.addSlider("Hertz").setPosition(205,105).setRange(100,200);
      
    3. At the beginning or end of each draw, set your frequency based on your slider. Because you named it, you can refer to it.

      wave.setFrequency( Frequency.ofHertz( sliderHertz.getValue() ) );
      
    4. Change your keyPressed code so that now your keys affect your sliders -- which affect the frequency. Now your key presses won't get overwritten by the next slider update, or be out of sync with what the slider shows.

      if ( key == 'a' ) sliderHertz.setValue(100);
      
  • P.S. Here are working ControlP5 examples sketches, including sliders: 1, 2, 3

  • Oh, now I got it! Thank you very much!! Do you have an idea, how to change the volume of the frequencies? Everything I found online was for MP3 sounds, I guess song.setGain(0.5); its not meant to be used for the frequencies?

  • Your question is: "I know how to wave.setFrequency, can I wave.somethingToChangeTheVolume ... or do I need a different object type from wave?

    1. What is wave?
      According to your code, it is an Oscil.
    2. What can an Oscil do?
      Check out the minim documentation, and look up the Oscil class. Looks like it has something called .amplitude

    Did that help you find a solution?

  • Oh ok, I added "wave.setAmplitude( sliderVolume.getValue() );" into the draw. But now I have the problem, that the volume is not changing. If the slider is on 0, there is no sound. Increasing the slider doesnt change the volume, but the Sinuswave. Do you have a clue on how to fix this?

  • @sampletape -- Maybe you should post your latest code.

Sign In or Register to comment.