JAVA - How to play audio sound represented as float[] or double[]
I read an audio file in bytes, then i do FFT (as low-pass-filter) on the audio byte[], so the out开发者_Go百科put of the FFT is a double[] (of Real and Imaginary). Now i wanna play the result to hear the sound. I use SourceDataLine if i will play a byte[].
So the problem, is how can i play the double[] ??
Thanks,
Samer Samy
I think the best approach would be to convert it back to byte[].
You could do this using a ByteArrayOutputStream
and a DataOutputStream
.
The ByteArrayOutputStream
one allow retreive the content of the stream as a byte array and the DataOutputStream
allow you to write double to the stream.
To expand on @Lynch's answer, which apparently wasn't clear enough for the OP:
byteStream = new ByteArrayOutputStream();
dataStream = new DataOutputStream( byteStream );
// write each element of your double[] to dataStream
dataStream.close();
byteStream.close();
byte[] audioBytes = byteStream.toByteArray();
精彩评论