When I Retrieve The Amplitudes From An Audio Source - The Data Often Comes Back Different. Whats The Best Way To Regulate The Data So I Get The Same Numbers Consistently?

Hello friendos!

I have just finished my first hackathon project and… it was grueling. The official end is tonight.

Pretty much, the project takes an audio file, and allows the user to select a “cut” from it. This cut has it’s amplitude levels taken and used for a secret encryption dictionary.

To decrypt the project, you have to upload the same song and select the same cut from it.

Well I just finished the project last night and I tested it, and it worked!

However, it doesn’t work most of the time. I looked at the data of the amplitudes generated, and it appears that even though I’m getting the same portions of the song - there are different values of data.

What I figure must be going on is that p5 isn’t registering the amplitudes at the same points, so it doesn’t quite work out to be the same.

Is there some sort of way I can normalfy or smooth the data so that the audio comes back consistent?

Try the code here:https://repl.it/@JacksonEnnis/Muse-Key

1 Like

Hello,

I wrote a “filter” for “noisy” data from an accelerometer and recycled it for use with the Processing sound library and it worked.

Visual example with Arduino:

Filter code (unedited and provided “as is”):

float unfiltered;
float currentMotion;
float previousMotion;
float kf;

float filter()
  {
  //  IIR filter: http://stackoverflow.com/questions/2272527/how-do-you-use-a-moving-average-to-filter-out-accelerometer-values-in-iphone-os
  //  xf = k * xf + (1.0 - k) * x;
  
  currentMotion = (1*amp.analyze());
  unfiltered = currentMotion;
  
  //  Smoothing
   
  // xf = k * xf + (1.0 - k) * x;
  // IIR filter: http://stackoverflow.com/questions/2272527/how-do-you-use-a-moving-average-to-filter-out-accelerometer-values-in-iphone-os
  // https://kiritchatterjee.wordpress.com/2014/11/10/a-simple-digital-low-pass-filter-in-c/
  // https://en.wikipedia.org/wiki/Low-pass_filter
  // http://www.rowetel.com/blog/?p=1245
  // http://www.edn.com/design/systems-design/4320010/A-simple-software-lowpass-filter-suits-embedded-system-applications
  
  if (previousMotion > 0) 
    {
    kf = .96;
    //    currentMotion = k * previousMotion + (1.0 - k) * currentMotion;
    //    currentMotion = k * (previousMotion - currentMotion) + currentMotion;
    //    currentMotion = k *previousMotion - k*currentMotion + currentMotion;
    currentMotion = kf*(previousMotion - currentMotion) + currentMotion;
    }
  
  println();
  print(unfiltered);
  print(" ");
  println(currentMotion);
  previousMotion = currentMotion;
  return currentMotion;
  }

I am confident that there are other approaches to this out there and the sound library may have some.

:slight_smile:

2 Likes

Thank you, I really appreciate it!

1 Like