stt(dump): WAV-заголовок — размеры little-endian (плееры открывают дампы)

This commit is contained in:
2026-08-24 21:36:53 +03:00
parent 0d79b5aa33
commit e21c27b0ee
3 changed files with 142 additions and 2 deletions
@@ -42,13 +42,17 @@ class WavWriter(
runCatching {
RandomAccessFile(path, "rw").use { raf ->
raf.seek(4)
raf.writeInt((36 + dataBytes).toInt()) // размер RIFF
raf.write(leInt(36 + dataBytes)) // размер RIFF (little-endian)
raf.seek(40)
raf.writeInt(dataBytes.toInt()) // размер data
raf.write(leInt(dataBytes)) // размер data (little-endian)
}
}
}
/** 4 байта little-endian (WAV-заголовок), в отличие от RandomAccessFile.writeInt (big-endian). */
private fun leInt(v: Long): ByteArray =
ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN).putInt(v.toInt()).array()
private fun headerBytes(): ByteArray =
ByteBuffer.allocate(44).order(ByteOrder.LITTLE_ENDIAN).apply {
put("RIFF".toByteArray())