Audio usb to arduino?

Could you give me an example?

No. I do not have a java system on my machine so I can't write one for you.

but after a long time the average will be 0, right?

No why should it be? You are averaging positive numbers, so there is no way it could possibly be zero.

Grumpy_Mike:
No. I do not have a java system on my machine so I can't write one for you.
No why should it be? You are averaging positive numbers, so there is no way it could possibly be zero.

I did not mean a java example, just and example with calculations

like
first byte array 1,76,188,42,1,8,5
second 72,53,10,37,85,73
third 1,3,6,1,1,1

first average : 45.8
second would be 45.8 + average / 2 : 50.4
third would be 50.4 + av / 2 : 26.3

is this correct?

is this correct?

Sorry I have no idea what you mean by that.
An avrage is adding up the numbers and dividing by the numbers you added up.

You add up all the numbers > 0 and divide by the number of numbers you added up.

Grumpy_Mike:
Sorry I have no idea what you mean by that.
An avrage is adding up the numbers and dividing by the numbers you added up.

You add up all the numbers > 0 and divide by the number of numbers you added up.

Yep I did that, I think I'm doing it correct.

I was thinking and I think that this data isnt correct. a waveform would be +, -, + - alternating. but this one is +++-+--- ?

a waveform would be +, -, + - alternating.

No, it is very unlikely to do that. Audio wave forms are not symmetric.

Just some observations...

You're configuring your audio stream as stereo 16 bits. Values -255 to +255 don't seem right. I'd expect anywhere from -32,768 to +32,767. You'd also need to check to see how the left and right channels are interleaved. You might need to check that the program is giving you values that you can use in the format that you can use them.

Secondly, to expand on the averaging, you're setting up your capture rate at 8khz. So assuming your program is keeping up, you'd expect to receive 8000 x 16bit reads per channel per second - i.e. 16,000 reads for stereo if you're pulling 16 bits out of the buffer at a time. Perhaps you can consider how often you need to update your LEDs... If you say 4 times a second, then average every 4000 16 bit values that come out of the buffer, and send that to the arduino. The other thing to consider ensuring you don't have an overflow - so consider 65,535 (being the max unsigned 16 bit value) x 4000 gives 262,140,000. You'll need to use a 32 bit integer to hold this. If you adjust the sample rate, or how often you perform the average, you'll need to redo the calculation.

Thirdly, if you're using Windows, then research the Stereo Mix device. You can use this to replicate the sound for your headphones to an analog audio jack. Potentially you can listen to your USB headset while also having an analog audio output to play with.

Thirdly, if you're using Windows, then research the Stereo Mix device. You can use this to replicate the sound for your headphones to an analog audio jack. Potentially you can listen to your USB headset while also having an analog audio output to play with.

That would solve a whole lot of problems if you can get your data in analogue form.