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

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

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):

// 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.

:)

1 Like