# Sound frequency label

**URL:** <https://discourse.processing.org/t/sound-frequency-label/27456>\
**Category:** Libraries\
**Created:** [January 29, 2021, 11:28am UTC](https://discourse.processing.org/t/sound-frequency-label/27456 "2021-01-29T11:28:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [January 29, 2021, 11:28am UTC](https://discourse.processing.org/t/sound-frequency-label/27456/1 "2021-01-29T11:28:44Z")

</div>

hi

how to set frequency values to each peak in sound library example

```auto
/**
 * Inspect the frequency spectrum of different simple oscillators.
 */

import processing.sound.*;

// All oscillators are instances of the Oscillator superclass.
Oscillator oscs[] = new Oscillator[5];

// Store information on which of the oscillators is currently playing.
int current = 0;

FFT fft;
int fftBands = 512;

void setup() {
  size(640, 360);
  background(255);

  // Turn the volume down globally.
  Sound s = new Sound(this);
  s.volume(0.2);

  // Create the oscillators and put them into an array.
  oscs[0] = new SinOsc(this);
  oscs[1] = new TriOsc(this);
  oscs[2] = new SawOsc(this);
  oscs[3] = new SqrOsc(this);

  // Special treatment for the Pulse oscillator to set its pulse width.
  Pulse pulse = new Pulse(this);
  pulse.width(0.05);
  oscs[4] = pulse;

  // Initialise the FFT and start playing the (default) oscillator.
  fft = new FFT(this, 512);
  oscs[current].play();
  fft.input(oscs[current]);
}

void draw() {
  // Only play one of the four oscillators, based on mouseY
  int nextOscillator = constrain(floor(map(mouseY, 0, height, 0, oscs.length)), 0, oscs.length - 1);

  if (nextOscillator != current) {
    oscs[current].stop();
    current = nextOscillator;

    // Switch FFT analysis over to the newly selected oscillator.
    fft.input(oscs[current]);
    // Play
    oscs[current].play();
  }

  // Map mouseX from 20Hz to 22000Hz for frequency.
  float frequency = map(mouseX, 0, width, 20.0, 22000.0);
  // Update oscillator frequency.
  oscs[current].freq(frequency);

  // Draw frequency spectrum.
  background(125, 255, 125);
  fill(255, 0, 150);
  noStroke();

  fft.analyze();

  float r_width = width/float(fftBands);

  for (int i = 0; i < fftBands; i++) {
    rect( i*r_width, height, r_width, -fft.spectrum[i]*height);
  }

  // Display the name of the oscillator class.
  textSize(32);
  fill(0);
  float verticalPosition = map(current, -1, oscs.length, 0, height);
  text(oscs[current].getClass().getSimpleName(), 0, verticalPosition);
}

```

 ![Untitled 27](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/d/d13022f7a5d7b9ee40bed9f59b41109b8395fb93.jpeg)

thanks in advance

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [January 31, 2021, 7:34am UTC](https://discourse.processing.org/t/sound-frequency-label/27456/3 "2021-01-31T07:34:19Z")

</div>

thanks for me i made it

 ![Untitled 28](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/4/4876c7298dc3927f10cf2ade72f4ce67192df8e0.jpeg)
