# Sound, Perlin Noise, and Processing. Looking for a demo

**URL:** <https://discourse.processing.org/t/sound-perlin-noise-and-processing-looking-for-a-demo/45732>\
**Category:** Libraries\
**Created:** [February 8, 2025, 6:25pm UTC](https://discourse.processing.org/t/sound-perlin-noise-and-processing-looking-for-a-demo/45732 "2025-02-08T18:25:29Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [February 8, 2025, 9:24pm UTC](https://discourse.processing.org/t/sound-perlin-noise-and-processing-looking-for-a-demo/45732/2 "2025-02-08T21:24:41Z")

</div>

Hello @mario60 ,

Try generating some Perlin noise data and saving it to a sound file and see what it sounds like.

_[Saving AudioSample as a sound file of any format](https://discourse.processing.org/t/saving-audiosample-as-a-sound-file-of-any-format/23174)_

I will certainly be exploring this in the future but not anytime soon…

I had some success with this!

Replace the sine wave data with Perlin noise and write that to the array.

I cleaned up the code in one of the examples to demonstrate beat frequencies (click mouse on sketch window to generate and play):

```Processing
// Original here:
// https://forum.processing.org/two/discussion/4339/how-to-save-a-wav-file-using-audiosystem-and-audioinputstream-of-javasound

// Updates by glv to generate stereo with beat frequencies

// References
// https://stackoverflow.com/questions/44415863/what-is-the-byte-format-of-an-8-bit-monaural-wav-file
// https://forum.processing.org/two/discussion/4339/how-to-save-a-wav-file-using-audiosystem-and-audioinputstream-of-javasound
// https://www.szynalski.com/tone-generator/

import javax.sound.sampled.*;
import java.io.*;

import processing.sound.*;
SoundFile file;

void setup() {}

void draw() {}

void mousePressed()
  {
  byte[] pcm_data = new byte[44100*2];
  double L1 = 44100.0/240.0;
  double L2 = 44100.0/250.0;
  for (int i=0; i<pcm_data.length; i+=2) // glv modified
    {
    pcm_data[i] = (byte)(55*Math.sin((i/L1)*Math.PI*2));
    pcm_data[i+1] = (byte)(55*Math.sin((i/L2)*Math.PI*2)); // glv modified
    }

  AudioFormat frmt = new AudioFormat(44100, 8, 2, true, true);
  AudioInputStream ais = new AudioInputStream(
    new ByteArrayInputStream(pcm_data), frmt, 
    pcm_data.length / frmt.getFrameSize()
  );

  try 
    {
    AudioSystem.write(ais, AudioFileFormat.Type.WAVE, new 
      File(sketchPath() + "/test.wav") // glv added brackets for sketchPath
    );
    println("Done!");  
    } 
  catch(Exception e) 
    {
    e.printStackTrace();
    }
  // glv added:
  file = new SoundFile(this, "test.wav");
  file.play();
  }

```

Do a bit of research and fill the array by encoding Perlin noise values into WAV file data. This is achievable.

`:)`

---

_[View the full topic](https://discourse.processing.org/t/sound-perlin-noise-and-processing-looking-for-a-demo/45732)._
