mathiasbynens / small

Smallest possible syntactically valid files of different types
https://mathiasbynens.be/notes/minimal-html
1.93k stars 184 forks source link

Add smallest possible WAV file #50

Closed mgeier closed 9 years ago

mgeier commented 9 years ago

This file contains 0 audio samples. It has a size of 44 bytes, which is a very typical WAV header size.

Generated with Python:

import struct

def uint32(number):
    return struct.pack('<I', number)

def uint16(number):
    return struct.pack('<H', number)

data = (
    b'RIFF' +
    uint32(36) +  # size

    b'WAVE' +  # file type

    b'fmt ' +
    uint32(16) +  # chunk size
    uint16(1) +  # data type (PCM)
    uint16(1) +  # channels
    uint32(44100) +  # samplerate
    uint32(44100 * 2) +  # bytes per second
    uint16(2) +  # frame size
    uint16(16) +  # bits per sample

    b'data' +
    uint32(0)  # chunk size
)

with open('wav.wav', 'wb') as f:
    f.write(data)
mathiasbynens commented 9 years ago

:+1:, and thanks for including the Python script!