• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

How to convert microphone readed ByteArray to Double Array ( amplitude )

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I want to do FFT spectrum analysis of the Microphone input. The code for reading microphone data Is as follows :



As you see I have the readed microphone data into targetData[] .

The jTransforms API DoubleFFT_1D.complexForward( ) accepts only double[] with a amplitude range from -1.0 to +1.0 for FFT spectrum analysation.

How can targetData[] be converted to double array with this amplitude ? I think due the 16 bit sampleSize may the byte pairs must be converted but I dont know.


Help would be very nice.




 
Rancher
Posts: 4888
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do the bytes that are read represent?
 
Andre Geissler
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The readed byte date is the PCM data I think. Like a wave file stream.
 
Norm Radder
Rancher
Posts: 4888
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, I was asking what do the values in the bytes represent?  4 bytes to an int, 2 bytes to char, or what?
 
Sheriff
Posts: 3914
542
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Norm Radder wrote:Sorry, I was asking what do the values in the bytes represent?  4 bytes to an int, 2 bytes to char, or what?


They should represent a signed linear value.  The number of bits per sample and endian-ness (byte ordering )can be learned using:
targetLine.getFormat().getSampleSizeInBits() and targetLine.getFormat().isBigEndian()

Edit: I didn't realize that you actually specified these values in AudioFormat format = new AudioFormat(44100, 16, 1, true, true).  I think I would have used constants to make it obvious what 16, true, and true were specifying.
 
Andre Geissler
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now I have another code for subwoofer FFT using microphone with Minim API. Its much easier-

 
joke time: What is brown and sticky? ... ... ... A stick! Use it to beat this tiny ad!
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic