Last active
July 14, 2020 10:03
-
-
Save vaibhavpandeyvpz/6d7d78bf92329e6d4ea14a3e1ecd9580 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.IOException | |
import java.io.OutputStream | |
class WavHeader ( | |
private val format: Int = 0, | |
private val channels: Int = 0, | |
private val hertz: Int = 0, | |
private val bitrate: Int = 0, | |
private val size: Int = 0 | |
) { | |
@Throws(IOException::class) | |
fun write(out: OutputStream): Int { | |
writeId(out, "RIFF") | |
writeInt(out, size) | |
writeId(out, "WAVEfmt ") | |
writeInt(out, 16) | |
writeShort(out, format) | |
writeShort(out, channels) | |
writeInt(out, hertz) | |
writeInt(out, channels * hertz * bitrate / 8) | |
writeShort(out, channels * bitrate / 8) | |
writeShort(out, bitrate) | |
writeId(out, "data") | |
writeInt(out, size) | |
return 44 | |
} | |
companion object { | |
@Throws(IOException::class) | |
private fun writeId(out: OutputStream, id: String) { | |
for (element in id) out.write(element.toInt()) | |
} | |
@Throws(IOException::class) | |
private fun writeInt(out: OutputStream, v: Int) { | |
out.write(v shr 0) | |
out.write(v shr 8) | |
out.write(v shr 16) | |
out.write(v shr 24) | |
} | |
@Throws(IOException::class) | |
private fun writeShort(out: OutputStream, v: Int) { | |
out.write(v shr 0) | |
out.write(v shr 8) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment