java - Representing music audio samples in terms of dB? -


this question has answer here:

i starting project allow me use java read sound samples, , depending on properties of each sample (i'm thinking focusing on decibels @ moment sake of simplification, or finding way compute overall 'volume' of specific sample or set of samples), return value 0-255 0 silence , 255 highest sound pressure (compared reference point, suppose? have no idea how word this). want have these values returned bytes , sent arduino in order control intensity of led's using pwm, , visually 'see' music.

i not sort of audio file format expert, , have no particular understanding of how data stored in music file. such, having trouble finding out how read sample , find way represent overall volume level byte. have looked through javax.sound.sampled package , confusing me. insight how accomplish appreciated.

as bastyen (+1 me) indicates, calculating decibels not simple, requires looking @ large number of samples. however, since sound samples run more visual frames in animation, making aggregate measure works out rather neatly.

a nice visual animation rate, example, updates 60 times per second, , common sampling rate sound 44100 times per second. so, 735 samples (44100 / 60 = 735) might end being choice interfacing visualizer.

by way, of official java tutorials i've read (i big fan), have found ones accompany javax.sound.sampled difficult. http://docs.oracle.com/javase/tutorial/sound/toc.html
still worth reading. if in charge of rewrite, there many more code examples. of best code examples in several sections deep, e.g., "using files , format converters" discussion.

if don't wish compute rms, hack store local high and/or low value given number of samples. relating these numbers decibels dubious, maybe useful after giving mapping of choice visualizer. part of problem values single point on given wave can range wildly. local high might more due phase of constituent harmonics happening line energy or volume.

your pcm top , bottom values not 0 , 256, more -128 127 8-bit encoding. more common still 16-bit encoding (-32768 32767). hang of if follow bastyen's links. make code independent of bit-encoding, normalize data (convert floats between -1 , 1) before doing other calculations.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -