audio - WAVE file format -


im Creating an Android application that generates an indication and saves it as a wave file. I looked everywhere and I came to know that I should write the file structure "manually", because Android does not support wave formats.

The file is generated but its not "playable", even on Matlab i get this message: incorrect chuck size information in the WAV file here code Is, please tell me that there is nothing wrong with the structure.

  The public class increases the main activity activity {int period = 1; Int null pattern = 48000; Int numSample = Duration * sampleRate; Double sample [] = new double [humid sample]; Double Freak 1 = 23000; Double Freak 2 = 24000; Byte [] generated = new byte [2 * digit sample]; Handler handler = new handler (); Long mySubChunk1Size = 16; Small myBitsPerSample = 16; Int myFormat = 1; Int myChannels = 1; Long myByteRate = sampleRate * myChannels * myBitsPerSample / 8; Int myBlockAlign = (int) (myChannels * myBitsPerSample / 8); Long myChunk2Size = generated.Snd.length * myChannels * myBitsPerSample / 8; Long time my charge size = 36 + myChunk2 size; @ Override Protected Zero (Bundle Saved Instantstate) {Super. NET (Saved Instantstate); SetContentView (R.layout.activity_main); Thread thread = new thread (new runnable) (try to run away from public) {try {genTone (}}} Catch (IOE option e) {// TODO auto-generated catch block e.printStackTrace ();} Handler Post (new Runanble () {public zero run () {playSound ();}}})}}); thread.start (); } Secure zero () at reserve {super.onResume (); } Zero genTone () throws IOException {double instfreq = 0, fraction; {Fraction = (double) (i) / (double) digit sample for (int i = 0; i & lt; numSample; i ++); Instfreq = freq1 + (fraction * (freq2-freq1)); If ((i% 1000) == 0) {Log.e ("Current freak:", string format ("Frack:% d of% d," instfreq, i, numSample)); } Sample [i] = monastery sin (2 * Math.pi * i / (sampleRate / instfreq)); } Int idx = 0; {// scale maximum dimension final small val = (small) ((DVL * 32767)) for (final dual DVL: sample); The maximum positive specimen for 16-bit integer signed for 16-bit wave PCM is 32767 / /, first byte is a low order byte (PCM: pulse control modulation) Generated [idx ++] = (byte) (Val and 0x00ff) ); Generated [id x ++] = (byte) ((Val & 0xff00)> 8); } DataOutputStream dd = New DataOutputStream (New FileOutputStream (Environment.getExternalStorageDirectory (.) GetAbsolutePath () + "/ tessst.wav")); Dd.writeBytes ("RIFF"); dd.writeInt (0); // Final file size is not known yet, write dd.writeBytes ("WAVE"); Dd.writebytes ("fmt"); Dd.writeInt (Integer.reverseBytes (16)); // Size of the sub-size, 16 dd.writeShort for PCM (Short.reverseBytes (Brief) 1)); // Audio Format, dd.writeShort (Short.reverseBytes (short) myChannels for PCM) // Number of channels, 1 mono, 2 stereo dd.writeInt (integer .reversebytes (sampleRate)); // sample rate dd.writeInt (integer. Reversebits ((sampleRate * myBitsPerSample * myChannels / 8))); // byte rate, samplerate * number of channels * bitspars sample / 8dd.writeShort (short reversebites (short) (myChannels * myBitsPerSample / 8))); // block align, numberofchannel * bitspair sample / 8dd.writeShort (Short.reverseBytes (myBitsPerSample)); // sample per bit dd.writeBytes ("data"); Dd.write (generatedSnd, 0, numSample); dd.close (); }   

It seems that you have not written part of the 'data' audio data ( Generated) Before you can withdraw the stream you have to go back and type 'RIFF' size. In this example code you can calculate it and can not write zero in the first place.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -