java - Converting Byte Array to Double Array -
I have some problems with WAV files in Java.
WAV format: PCM_SIGNED 44100.0 Hz, 24 bit, stereo, 6 bytes / frames, small-endian
- I have removed WAV data in a byte array with no problem.
- I'm trying to convert the byte array to a double array, but some couples come with the "NaN" value.
Code:
ByteBuffer byteBuffer = ByteBuffer.wrap (byteArray); Double [] doubles = new double [byte array.line / 8]; For (int i = 0; i & lt; doubles; tall; i ++) {couple [i] = byte buffer.get double (i * 8); }
The fact of being 16/24/32 bit, mono / stereo confuse me.
I intend to pass double [] an FFT algorithm and receive audio frequencies.
Thanks
Try it out:
Public stable byte [] toByteArray (double [] doubleArray) {int times = Double.SIZE / byte.SIZE; Byte [] bytes = new byte [double] Long * bar]; For (int i = 0; i & lt; doubleArray.length; i ++) {BitBufer. Vep (Bytes, I * Bar, Times). Inputable (double other [i]); } Return bytes; } Public stable double [] toDoubleArray (byte [] bytes) {int times = Double.SIZE / byte. SIZE; Double [] doubles = new double [bit byte Length / bar]; For (int i = 0; i & lt; duel; tall; i ++) {doubles [i] = byte buffer. Vep (Bytere, I * Times, Times) .getDouble (); } Return doubles; } Public stable byte [] toByteArray (int [] intArray) {int times = Integer.SIZE / byte. SIZE; Byte [] bytes = new byte [intersection.line] bar ;; For (int i = 0; i & lt; intArray.length; i ++) {Bitebuffer. Vep (Bytes, I * Times, Times) .IPIINT (Intereay [I]); } Return bytes; } Public static int [] toIntArray (byte [] bytere) {int bar = integer. SISE / byte SIZE; Int [] ints = new int [byteArray.length / times]; For (int i = 0; i & lt; ints.length; i ++) {ints [i] = byte buffer. Vap (Bytere, I * Bar, Bar) .getInt (); } Return ints; }
जावा प्रोग्रामिंग उदाहरण शुरुआती लोगों के लिए कोड स्निपेट्स
ReplyDeleteस्टेटमेंट उदाहरण कोड जारी रखें