0

I’m trying to build a sketch that shows me levels of audio coming into a system. I want to be able to do more than 2 channels so i know that i need more than the processing.sound library can provide currently and my searching has led me to javax.sound.sampled.*, however this is as far as my searching and playing has got me.

Does anyone know how to query the system for how many lines are coming in and to get the amplitude of audio on each line?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
matt
  • 1
  • I remember trying that back in 2012 with the [beads library](http://www.beadsproject.net/). It wasn't super straight forward, but it worked: check out [this answer](https://stackoverflow.com/questions/37944418/getting-multiple-audio-inputs-in-processing). Hopefully the library has been updated since and multi channel support is easier to use. – George Profenza May 28 '18 at 14:06

1 Answers1

0

This is kind of a composite question.

For the number of lines, see Accessing Audio System Resources in the Java tutorials. There is sample code there for inspecting what lines are present. If some of the terms are confusing, most are defined in the tutorial immediately preceding this one.

To see what is on the line, check Capturing Audio.

To get levels, you will probably want to do some sort of rolling average (usually termed as root-mean-square). The "controls" (sometimes) provided at a higher level are kind of iffy for a variety of reasons.

In order to calculate those levels, though, you will have to convert the byte data to PCM. The example code in Using Files and Format Converters has example code that shows the point where the conversion would take place. In the first real example given, under the heading "Reading Sound Files" take note of the place where the comment sits that reads

// Here, do something useful with the audio data that's

// now in the audioBytes array...

I recall there are already StackOverflow questions that show the commands needed to convert bytes to PCM.

Community
  • 1
  • 1
Phil Freihofner
  • 7,645
  • 1
  • 20
  • 41