Microsoft WAVE audio file: JavaScript parsing library

The WAVE file format is a subset of Microsoft's RIFF specification for the storage of multimedia files. A RIFF file starts out with a file header followed by a sequence of data chunks. A WAVE file is often just a RIFF file with a single "WAVE" chunk which consists of two sub-chunks -- a "fmt " chunk specifying the data format and a "data" chunk containing the actual sample data.

This Kaitai implementation was written by John Byrd of Gigantic Software (jbyrd@giganticsoftware.com), and it is likely to contain bugs.

File extension

wav

KS implementation details

This page hosts a formal specification of Microsoft WAVE audio file using Kaitai Struct. This specification can be automatically translated into a variety of programming languages to get a parsing library.

Usage

See the usage examples in the JavaScript notes.

Parse structure from an ArrayBuffer:

var arrayBuffer = ...;
var data = new Wav(new KaitaiStream(arrayBuffer));

After that, one can get various attributes from the structure by accessing fields or properties like:

data.riffId // => get riff id

JavaScript source code to parse Microsoft WAVE audio file

Wav.js

// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild

(function (root, factory) {
  if (typeof define === 'function' && define.amd) {
    define(['kaitai-struct/KaitaiStream'], factory);
  } else if (typeof module === 'object' && module.exports) {
    module.exports = factory(require('kaitai-struct/KaitaiStream'));
  } else {
    root.Wav = factory(root.KaitaiStream);
  }
}(this, function (KaitaiStream) {
/**
 * The WAVE file format is a subset of Microsoft's RIFF specification for the
 * storage of multimedia files. A RIFF file starts out with a file header
 * followed by a sequence of data chunks. A WAVE file is often just a RIFF
 * file with a single "WAVE" chunk which consists of two sub-chunks --
 * a "fmt " chunk specifying the data format and a "data" chunk containing
 * the actual sample data.
 * 
 * This Kaitai implementation was written by John Byrd of Gigantic Software
 * (jbyrd@giganticsoftware.com), and it is likely to contain bugs.
 * @see {@link https://www.loc.gov/preservation/digital/formats/fdd/fdd000001.shtml|Source}
 */

var Wav = (function() {
  Wav.WFormatTagType = Object.freeze({
    UNKNOWN: 0,
    PCM: 1,
    ADPCM: 2,
    IEEE_FLOAT: 3,
    VSELP: 4,
    IBM_CVSD: 5,
    ALAW: 6,
    MULAW: 7,
    DTS: 8,
    DRM: 9,
    WMAVOICE9: 10,
    WMAVOICE10: 11,
    OKI_ADPCM: 16,
    DVI_ADPCM: 17,
    MEDIASPACE_ADPCM: 18,
    SIERRA_ADPCM: 19,
    G723_ADPCM: 20,
    DIGISTD: 21,
    DIGIFIX: 22,
    DIALOGIC_OKI_ADPCM: 23,
    MEDIAVISION_ADPCM: 24,
    CU_CODEC: 25,
    HP_DYN_VOICE: 26,
    YAMAHA_ADPCM: 32,
    SONARC: 33,
    DSPGROUP_TRUESPEECH: 34,
    ECHOSC1: 35,
    AUDIOFILE_AF36: 36,
    APTX: 37,
    AUDIOFILE_AF10: 38,
    PROSODY_1612: 39,
    LRC: 40,
    DOLBY_AC2: 48,
    GSM610: 49,
    MSNAUDIO: 50,
    ANTEX_ADPCME: 51,
    CONTROL_RES_VQLPC: 52,
    DIGIREAL: 53,
    DIGIADPCM: 54,
    CONTROL_RES_CR10: 55,
    NMS_VBXADPCM: 56,
    CS_IMAADPCM: 57,
    ECHOSC3: 58,
    ROCKWELL_ADPCM: 59,
    ROCKWELL_DIGITALK: 60,
    XEBEC: 61,
    G721_ADPCM: 64,
    G728_CELP: 65,
    MSG723: 66,
    INTEL_G723_1: 67,
    INTEL_G729: 68,
    SHARP_G726: 69,
    MPEG: 80,
    RT24: 82,
    PAC: 83,
    MPEGLAYER3: 85,
    LUCENT_G723: 89,
    CIRRUS: 96,
    ESPCM: 97,
    VOXWARE: 98,
    CANOPUS_ATRAC: 99,
    G726_ADPCM: 100,
    G722_ADPCM: 101,
    DSAT: 102,
    DSAT_DISPLAY: 103,
    VOXWARE_BYTE_ALIGNED: 105,
    VOXWARE_AC8: 112,
    VOXWARE_AC10: 113,
    VOXWARE_AC16: 114,
    VOXWARE_AC20: 115,
    VOXWARE_RT24: 116,
    VOXWARE_RT29: 117,
    VOXWARE_RT29HW: 118,
    VOXWARE_VR12: 119,
    VOXWARE_VR18: 120,
    VOXWARE_TQ40: 121,
    VOXWARE_SC3: 122,
    VOXWARE_SC3_1: 123,
    SOFTSOUND: 128,
    VOXWARE_TQ60: 129,
    MSRT24: 130,
    G729A: 131,
    MVI_MVI2: 132,
    DF_G726: 133,
    DF_GSM610: 134,
    ISIAUDIO: 136,
    ONLIVE: 137,
    MULTITUDE_FT_SX20: 138,
    INFOCOM_ITS_G721_ADPCM: 139,
    CONVEDIA_G729: 140,
    CONGRUENCY: 141,
    SBC24: 145,
    DOLBY_AC3_SPDIF: 146,
    MEDIASONIC_G723: 147,
    PROSODY_8KBPS: 148,
    ZYXEL_ADPCM: 151,
    PHILIPS_LPCBB: 152,
    PACKED: 153,
    MALDEN_PHONYTALK: 160,
    RACAL_RECORDER_GSM: 161,
    RACAL_RECORDER_G720_A: 162,
    RACAL_RECORDER_G723_1: 163,
    RACAL_RECORDER_TETRA_ACELP: 164,
    NEC_AAC: 176,
    RAW_AAC1: 255,
    RHETOREX_ADPCM: 256,
    IRAT: 257,
    VIVO_G723: 273,
    VIVO_SIREN: 274,
    PHILIPS_CELP: 288,
    PHILIPS_GRUNDIG: 289,
    DIGITAL_G723: 291,
    SANYO_LD_ADPCM: 293,
    SIPROLAB_ACEPLNET: 304,
    SIPROLAB_ACELP4800: 305,
    SIPROLAB_ACELP8V3: 306,
    SIPROLAB_G729: 307,
    SIPROLAB_G729A: 308,
    SIPROLAB_KELVIN: 309,
    VOICEAGE_AMR: 310,
    G726ADPCM: 320,
    DICTAPHONE_CELP68: 321,
    DICTAPHONE_CELP54: 322,
    QUALCOMM_PUREVOICE: 336,
    QUALCOMM_HALFRATE: 337,
    TUBGSM: 341,
    MSAUDIO1: 352,
    WMAUDIO2: 353,
    WMAUDIO3: 354,
    WMAUDIO_LOSSLESS: 355,
    WMASPDIF: 356,
    UNISYS_NAP_ADPCM: 368,
    UNISYS_NAP_ULAW: 369,
    UNISYS_NAP_ALAW: 370,
    UNISYS_NAP_16K: 371,
    SYCOM_ACM_SYC008: 372,
    SYCOM_ACM_SYC701_G726L: 373,
    SYCOM_ACM_SYC701_CELP54: 374,
    SYCOM_ACM_SYC701_CELP68: 375,
    KNOWLEDGE_ADVENTURE_ADPCM: 376,
    FRAUNHOFER_IIS_MPEG2_AAC: 384,
    DTS_DS: 400,
    CREATIVE_ADPCM: 512,
    CREATIVE_FASTSPEECH8: 514,
    CREATIVE_FASTSPEECH10: 515,
    UHER_ADPCM: 528,
    ULEAD_DV_AUDIO: 533,
    ULEAD_DV_AUDIO_1: 534,
    QUARTERDECK: 544,
    ILINK_VC: 560,
    RAW_SPORT: 576,
    ESST_AC3: 577,
    GENERIC_PASSTHRU: 585,
    IPI_HSX: 592,
    IPI_RPELP: 593,
    CS2: 608,
    SONY_SCX: 624,
    SONY_SCY: 625,
    SONY_ATRAC3: 626,
    SONY_SPC: 627,
    TELUM_AUDIO: 640,
    TELUM_IA_AUDIO: 641,
    NORCOM_VOICE_SYSTEMS_ADPCM: 645,
    FM_TOWNS_SND: 768,
    MICRONAS: 848,
    MICRONAS_CELP833: 849,
    BTV_DIGITAL: 1024,
    INTEL_MUSIC_CODER: 1025,
    INDEO_AUDIO: 1026,
    QDESIGN_MUSIC: 1104,
    ON2_VP7_AUDIO: 1280,
    ON2_VP6_AUDIO: 1281,
    VME_VMPCM: 1664,
    TPC: 1665,
    LIGHTWAVE_LOSSLESS: 2222,
    OLIGSM: 4096,
    OLIADPCM: 4097,
    OLICELP: 4098,
    OLISBC: 4099,
    OLIOPR: 4100,
    LH_CODEC: 4352,
    LH_CODEC_CELP: 4353,
    LH_CODEC_SBC8: 4354,
    LH_CODEC_SBC12: 4355,
    LH_CODEC_SBC16: 4356,
    NORRIS: 5120,
    ISIAUDIO_2: 5121,
    SOUNDSPACE_MUSICOMPRESS: 5376,
    MPEG_ADTS_AAC: 5632,
    MPEG_RAW_AAC: 5633,
    MPEG_LOAS: 5634,
    NOKIA_MPEG_ADTS_AAC: 5640,
    NOKIA_MPEG_RAW_AAC: 5641,
    VODAFONE_MPEG_ADTS_AAC: 5642,
    VODAFONE_MPEG_RAW_AAC: 5643,
    MPEG_HEAAC: 5648,
    VOXWARE_RT24_SPEECH: 6172,
    SONICFOUNDRY_LOSSLESS: 6513,
    INNINGS_TELECOM_ADPCM: 6521,
    LUCENT_SX8300P: 7175,
    LUCENT_SX5363S: 7180,
    CUSEEME: 7939,
    NTCSOFT_ALF2CM_ACM: 8132,
    DVM: 8192,
    DTS2: 8193,
    MAKEAVIS: 13075,
    DIVIO_MPEG4_AAC: 16707,
    NOKIA_ADAPTIVE_MULTIRATE: 16897,
    DIVIO_G726: 16963,
    LEAD_SPEECH: 17228,
    LEAD_VORBIS: 22092,
    WAVPACK_AUDIO: 22358,
    OGG_VORBIS_MODE_1: 26447,
    OGG_VORBIS_MODE_2: 26448,
    OGG_VORBIS_MODE_3: 26449,
    OGG_VORBIS_MODE_1_PLUS: 26479,
    OGG_VORBIS_MODE_2_PLUS: 26480,
    OGG_VORBIS_MODE_3_PLUS: 26481,
    THREECOM_NBX: 28672,
    FAAD_AAC: 28781,
    AMR_NB: 29537,
    AMR_WB: 29538,
    AMR_WP: 29539,
    GSM_AMR_CBR: 31265,
    GSM_AMR_VBR_SID: 31266,
    COMVERSE_INFOSYS_G723_1: 41216,
    COMVERSE_INFOSYS_AVQSBC: 41217,
    COMVERSE_INFOSYS_SBC: 41218,
    SYMBOL_G729_A: 41219,
    VOICEAGE_AMR_WB: 41220,
    INGENIENT_G726: 41221,
    MPEG4_AAC: 41222,
    ENCORE_G726: 41223,
    ZOLL_ASAO: 41224,
    SPEEX_VOICE: 41225,
    VIANIX_MASC: 41226,
    WM9_SPECTRUM_ANALYZER: 41227,
    WMF_SPECTRUM_ANAYZER: 41228,
    GSM_610: 41229,
    GSM_620: 41230,
    GSM_660: 41231,
    GSM_690: 41232,
    GSM_ADAPTIVE_MULTIRATE_WB: 41233,
    POLYCOM_G722: 41234,
    POLYCOM_G728: 41235,
    POLYCOM_G729_A: 41236,
    POLYCOM_SIREN: 41237,
    GLOBAL_IP_ILBC: 41238,
    RADIOTIME_TIME_SHIFT_RADIO: 41239,
    NICE_ACA: 41240,
    NICE_ADPCM: 41241,
    VOCORD_G721: 41242,
    VOCORD_G726: 41243,
    VOCORD_G722_1: 41244,
    VOCORD_G728: 41245,
    VOCORD_G729: 41246,
    VOCORD_G729_A: 41247,
    VOCORD_G723_1: 41248,
    VOCORD_LBC: 41249,
    NICE_G728: 41250,
    FRACE_TELECOM_G729: 41251,
    CODIAN: 41252,
    FLAC: 61868,
    EXTENSIBLE: 65534,
    DEVELOPMENT: 65535,

    0: "UNKNOWN",
    1: "PCM",
    2: "ADPCM",
    3: "IEEE_FLOAT",
    4: "VSELP",
    5: "IBM_CVSD",
    6: "ALAW",
    7: "MULAW",
    8: "DTS",
    9: "DRM",
    10: "WMAVOICE9",
    11: "WMAVOICE10",
    16: "OKI_ADPCM",
    17: "DVI_ADPCM",
    18: "MEDIASPACE_ADPCM",
    19: "SIERRA_ADPCM",
    20: "G723_ADPCM",
    21: "DIGISTD",
    22: "DIGIFIX",
    23: "DIALOGIC_OKI_ADPCM",
    24: "MEDIAVISION_ADPCM",
    25: "CU_CODEC",
    26: "HP_DYN_VOICE",
    32: "YAMAHA_ADPCM",
    33: "SONARC",
    34: "DSPGROUP_TRUESPEECH",
    35: "ECHOSC1",
    36: "AUDIOFILE_AF36",
    37: "APTX",
    38: "AUDIOFILE_AF10",
    39: "PROSODY_1612",
    40: "LRC",
    48: "DOLBY_AC2",
    49: "GSM610",
    50: "MSNAUDIO",
    51: "ANTEX_ADPCME",
    52: "CONTROL_RES_VQLPC",
    53: "DIGIREAL",
    54: "DIGIADPCM",
    55: "CONTROL_RES_CR10",
    56: "NMS_VBXADPCM",
    57: "CS_IMAADPCM",
    58: "ECHOSC3",
    59: "ROCKWELL_ADPCM",
    60: "ROCKWELL_DIGITALK",
    61: "XEBEC",
    64: "G721_ADPCM",
    65: "G728_CELP",
    66: "MSG723",
    67: "INTEL_G723_1",
    68: "INTEL_G729",
    69: "SHARP_G726",
    80: "MPEG",
    82: "RT24",
    83: "PAC",
    85: "MPEGLAYER3",
    89: "LUCENT_G723",
    96: "CIRRUS",
    97: "ESPCM",
    98: "VOXWARE",
    99: "CANOPUS_ATRAC",
    100: "G726_ADPCM",
    101: "G722_ADPCM",
    102: "DSAT",
    103: "DSAT_DISPLAY",
    105: "VOXWARE_BYTE_ALIGNED",
    112: "VOXWARE_AC8",
    113: "VOXWARE_AC10",
    114: "VOXWARE_AC16",
    115: "VOXWARE_AC20",
    116: "VOXWARE_RT24",
    117: "VOXWARE_RT29",
    118: "VOXWARE_RT29HW",
    119: "VOXWARE_VR12",
    120: "VOXWARE_VR18",
    121: "VOXWARE_TQ40",
    122: "VOXWARE_SC3",
    123: "VOXWARE_SC3_1",
    128: "SOFTSOUND",
    129: "VOXWARE_TQ60",
    130: "MSRT24",
    131: "G729A",
    132: "MVI_MVI2",
    133: "DF_G726",
    134: "DF_GSM610",
    136: "ISIAUDIO",
    137: "ONLIVE",
    138: "MULTITUDE_FT_SX20",
    139: "INFOCOM_ITS_G721_ADPCM",
    140: "CONVEDIA_G729",
    141: "CONGRUENCY",
    145: "SBC24",
    146: "DOLBY_AC3_SPDIF",
    147: "MEDIASONIC_G723",
    148: "PROSODY_8KBPS",
    151: "ZYXEL_ADPCM",
    152: "PHILIPS_LPCBB",
    153: "PACKED",
    160: "MALDEN_PHONYTALK",
    161: "RACAL_RECORDER_GSM",
    162: "RACAL_RECORDER_G720_A",
    163: "RACAL_RECORDER_G723_1",
    164: "RACAL_RECORDER_TETRA_ACELP",
    176: "NEC_AAC",
    255: "RAW_AAC1",
    256: "RHETOREX_ADPCM",
    257: "IRAT",
    273: "VIVO_G723",
    274: "VIVO_SIREN",
    288: "PHILIPS_CELP",
    289: "PHILIPS_GRUNDIG",
    291: "DIGITAL_G723",
    293: "SANYO_LD_ADPCM",
    304: "SIPROLAB_ACEPLNET",
    305: "SIPROLAB_ACELP4800",
    306: "SIPROLAB_ACELP8V3",
    307: "SIPROLAB_G729",
    308: "SIPROLAB_G729A",
    309: "SIPROLAB_KELVIN",
    310: "VOICEAGE_AMR",
    320: "G726ADPCM",
    321: "DICTAPHONE_CELP68",
    322: "DICTAPHONE_CELP54",
    336: "QUALCOMM_PUREVOICE",
    337: "QUALCOMM_HALFRATE",
    341: "TUBGSM",
    352: "MSAUDIO1",
    353: "WMAUDIO2",
    354: "WMAUDIO3",
    355: "WMAUDIO_LOSSLESS",
    356: "WMASPDIF",
    368: "UNISYS_NAP_ADPCM",
    369: "UNISYS_NAP_ULAW",
    370: "UNISYS_NAP_ALAW",
    371: "UNISYS_NAP_16K",
    372: "SYCOM_ACM_SYC008",
    373: "SYCOM_ACM_SYC701_G726L",
    374: "SYCOM_ACM_SYC701_CELP54",
    375: "SYCOM_ACM_SYC701_CELP68",
    376: "KNOWLEDGE_ADVENTURE_ADPCM",
    384: "FRAUNHOFER_IIS_MPEG2_AAC",
    400: "DTS_DS",
    512: "CREATIVE_ADPCM",
    514: "CREATIVE_FASTSPEECH8",
    515: "CREATIVE_FASTSPEECH10",
    528: "UHER_ADPCM",
    533: "ULEAD_DV_AUDIO",
    534: "ULEAD_DV_AUDIO_1",
    544: "QUARTERDECK",
    560: "ILINK_VC",
    576: "RAW_SPORT",
    577: "ESST_AC3",
    585: "GENERIC_PASSTHRU",
    592: "IPI_HSX",
    593: "IPI_RPELP",
    608: "CS2",
    624: "SONY_SCX",
    625: "SONY_SCY",
    626: "SONY_ATRAC3",
    627: "SONY_SPC",
    640: "TELUM_AUDIO",
    641: "TELUM_IA_AUDIO",
    645: "NORCOM_VOICE_SYSTEMS_ADPCM",
    768: "FM_TOWNS_SND",
    848: "MICRONAS",
    849: "MICRONAS_CELP833",
    1024: "BTV_DIGITAL",
    1025: "INTEL_MUSIC_CODER",
    1026: "INDEO_AUDIO",
    1104: "QDESIGN_MUSIC",
    1280: "ON2_VP7_AUDIO",
    1281: "ON2_VP6_AUDIO",
    1664: "VME_VMPCM",
    1665: "TPC",
    2222: "LIGHTWAVE_LOSSLESS",
    4096: "OLIGSM",
    4097: "OLIADPCM",
    4098: "OLICELP",
    4099: "OLISBC",
    4100: "OLIOPR",
    4352: "LH_CODEC",
    4353: "LH_CODEC_CELP",
    4354: "LH_CODEC_SBC8",
    4355: "LH_CODEC_SBC12",
    4356: "LH_CODEC_SBC16",
    5120: "NORRIS",
    5121: "ISIAUDIO_2",
    5376: "SOUNDSPACE_MUSICOMPRESS",
    5632: "MPEG_ADTS_AAC",
    5633: "MPEG_RAW_AAC",
    5634: "MPEG_LOAS",
    5640: "NOKIA_MPEG_ADTS_AAC",
    5641: "NOKIA_MPEG_RAW_AAC",
    5642: "VODAFONE_MPEG_ADTS_AAC",
    5643: "VODAFONE_MPEG_RAW_AAC",
    5648: "MPEG_HEAAC",
    6172: "VOXWARE_RT24_SPEECH",
    6513: "SONICFOUNDRY_LOSSLESS",
    6521: "INNINGS_TELECOM_ADPCM",
    7175: "LUCENT_SX8300P",
    7180: "LUCENT_SX5363S",
    7939: "CUSEEME",
    8132: "NTCSOFT_ALF2CM_ACM",
    8192: "DVM",
    8193: "DTS2",
    13075: "MAKEAVIS",
    16707: "DIVIO_MPEG4_AAC",
    16897: "NOKIA_ADAPTIVE_MULTIRATE",
    16963: "DIVIO_G726",
    17228: "LEAD_SPEECH",
    22092: "LEAD_VORBIS",
    22358: "WAVPACK_AUDIO",
    26447: "OGG_VORBIS_MODE_1",
    26448: "OGG_VORBIS_MODE_2",
    26449: "OGG_VORBIS_MODE_3",
    26479: "OGG_VORBIS_MODE_1_PLUS",
    26480: "OGG_VORBIS_MODE_2_PLUS",
    26481: "OGG_VORBIS_MODE_3_PLUS",
    28672: "THREECOM_NBX",
    28781: "FAAD_AAC",
    29537: "AMR_NB",
    29538: "AMR_WB",
    29539: "AMR_WP",
    31265: "GSM_AMR_CBR",
    31266: "GSM_AMR_VBR_SID",
    41216: "COMVERSE_INFOSYS_G723_1",
    41217: "COMVERSE_INFOSYS_AVQSBC",
    41218: "COMVERSE_INFOSYS_SBC",
    41219: "SYMBOL_G729_A",
    41220: "VOICEAGE_AMR_WB",
    41221: "INGENIENT_G726",
    41222: "MPEG4_AAC",
    41223: "ENCORE_G726",
    41224: "ZOLL_ASAO",
    41225: "SPEEX_VOICE",
    41226: "VIANIX_MASC",
    41227: "WM9_SPECTRUM_ANALYZER",
    41228: "WMF_SPECTRUM_ANAYZER",
    41229: "GSM_610",
    41230: "GSM_620",
    41231: "GSM_660",
    41232: "GSM_690",
    41233: "GSM_ADAPTIVE_MULTIRATE_WB",
    41234: "POLYCOM_G722",
    41235: "POLYCOM_G728",
    41236: "POLYCOM_G729_A",
    41237: "POLYCOM_SIREN",
    41238: "GLOBAL_IP_ILBC",
    41239: "RADIOTIME_TIME_SHIFT_RADIO",
    41240: "NICE_ACA",
    41241: "NICE_ADPCM",
    41242: "VOCORD_G721",
    41243: "VOCORD_G726",
    41244: "VOCORD_G722_1",
    41245: "VOCORD_G728",
    41246: "VOCORD_G729",
    41247: "VOCORD_G729_A",
    41248: "VOCORD_G723_1",
    41249: "VOCORD_LBC",
    41250: "NICE_G728",
    41251: "FRACE_TELECOM_G729",
    41252: "CODIAN",
    61868: "FLAC",
    65534: "EXTENSIBLE",
    65535: "DEVELOPMENT",
  });

  Wav.ChunkType = Object.freeze({
    FMT: 544501094,
    BEXT: 1650817140,
    CUE: 1668637984,
    DATA: 1684108385,
    MINF: 1835626086,
    REGN: 1919248238,
    UMID: 1970104676,

    544501094: "FMT",
    1650817140: "BEXT",
    1668637984: "CUE",
    1684108385: "DATA",
    1835626086: "MINF",
    1919248238: "REGN",
    1970104676: "UMID",
  });

  function Wav(_io, _parent, _root) {
    this._io = _io;
    this._parent = _parent;
    this._root = _root || this;

    this._read();
  }
  Wav.prototype._read = function() {
    this.riffId = this._io.ensureFixedContents([82, 73, 70, 70]);
    this.fileSize = this._io.readU4le();
    this.waveId = this._io.ensureFixedContents([87, 65, 86, 69]);
    this._raw_chunks = this._io.readBytes((this.fileSize - 5));
    var _io__raw_chunks = new KaitaiStream(this._raw_chunks);
    this.chunks = new ChunksType(_io__raw_chunks, this, this._root);
  }

  var SampleType = Wav.SampleType = (function() {
    function SampleType(_io, _parent, _root) {
      this._io = _io;
      this._parent = _parent;
      this._root = _root || this;

      this._read();
    }
    SampleType.prototype._read = function() {
      this.sample = this._io.readU2le();
    }

    return SampleType;
  })();

  var FormatChunkType = Wav.FormatChunkType = (function() {
    function FormatChunkType(_io, _parent, _root) {
      this._io = _io;
      this._parent = _parent;
      this._root = _root || this;

      this._read();
    }
    FormatChunkType.prototype._read = function() {
      this.wFormatTag = this._io.readU2le();
      this.nChannels = this._io.readU2le();
      this.nSamplesPerSec = this._io.readU4le();
      this.nAvgBytesPerSec = this._io.readU4le();
      this.nBlockAlign = this._io.readU2le();
      this.wBitsPerSample = this._io.readU2le();
      if (!(this.isBasicPcm)) {
        this.cbSize = this._io.readU2le();
      }
      if (this.isCbSizeMeaningful) {
        this.wValidBitsPerSample = this._io.readU2le();
      }
      if (this.isExtensible) {
        this.channelMaskAndSubformat = new ChannelMaskAndSubformatType(this._io, this, this._root);
      }
    }
    Object.defineProperty(FormatChunkType.prototype, 'isExtensible', {
      get: function() {
        if (this._m_isExtensible !== undefined)
          return this._m_isExtensible;
        this._m_isExtensible = this.wFormatTag == Wav.WFormatTagType.EXTENSIBLE;
        return this._m_isExtensible;
      }
    });
    Object.defineProperty(FormatChunkType.prototype, 'isBasicPcm', {
      get: function() {
        if (this._m_isBasicPcm !== undefined)
          return this._m_isBasicPcm;
        this._m_isBasicPcm = this.wFormatTag == Wav.WFormatTagType.PCM;
        return this._m_isBasicPcm;
      }
    });
    Object.defineProperty(FormatChunkType.prototype, 'isBasicFloat', {
      get: function() {
        if (this._m_isBasicFloat !== undefined)
          return this._m_isBasicFloat;
        this._m_isBasicFloat = this.wFormatTag == Wav.WFormatTagType.IEEE_FLOAT;
        return this._m_isBasicFloat;
      }
    });
    Object.defineProperty(FormatChunkType.prototype, 'isCbSizeMeaningful', {
      get: function() {
        if (this._m_isCbSizeMeaningful !== undefined)
          return this._m_isCbSizeMeaningful;
        this._m_isCbSizeMeaningful =  ((!(this.isBasicPcm)) && (this.cbSize != 0)) ;
        return this._m_isCbSizeMeaningful;
      }
    });

    return FormatChunkType;
  })();

  var GuidType = Wav.GuidType = (function() {
    function GuidType(_io, _parent, _root) {
      this._io = _io;
      this._parent = _parent;
      this._root = _root || this;

      this._read();
    }
    GuidType.prototype._read = function() {
      this.data1 = this._io.readU4le();
      this.data2 = this._io.readU2le();
      this.data3 = this._io.readU2le();
      this.data4 = this._io.readU4be();
      this.data4a = this._io.readU4be();
    }

    return GuidType;
  })();

  var CuePointType = Wav.CuePointType = (function() {
    function CuePointType(_io, _parent, _root) {
      this._io = _io;
      this._parent = _parent;
      this._root = _root || this;

      this._read();
    }
    CuePointType.prototype._read = function() {
      this.dwName = this._io.readU4le();
      this.dwPosition = this._io.readU4le();
      this.fccChunk = this._io.readU4le();
      this.dwChunkStart = this._io.readU4le();
      this.dwBlockStart = this._io.readU4le();
      this.dwSampleOffset = this._io.readU4le();
    }

    return CuePointType;
  })();

  var DataChunkType = Wav.DataChunkType = (function() {
    function DataChunkType(_io, _parent, _root) {
      this._io = _io;
      this._parent = _parent;
      this._root = _root || this;

      this._read();
    }
    DataChunkType.prototype._read = function() {
      this.data = this._io.readBytesFull();
    }

    return DataChunkType;
  })();

  var SamplesType = Wav.SamplesType = (function() {
    function SamplesType(_io, _parent, _root) {
      this._io = _io;
      this._parent = _parent;
      this._root = _root || this;

      this._read();
    }
    SamplesType.prototype._read = function() {
      this.samples = this._io.readU4le();
    }

    return SamplesType;
  })();

  var ChannelMaskAndSubformatType = Wav.ChannelMaskAndSubformatType = (function() {
    function ChannelMaskAndSubformatType(_io, _parent, _root) {
      this._io = _io;
      this._parent = _parent;
      this._root = _root || this;

      this._read();
    }
    ChannelMaskAndSubformatType.prototype._read = function() {
      this.dwChannelMask = new ChannelMaskType(this._io, this, this._root);
      this.subformat = new GuidType(this._io, this, this._root);
    }

    return ChannelMaskAndSubformatType;
  })();

  var ChunksType = Wav.ChunksType = (function() {
    function ChunksType(_io, _parent, _root) {
      this._io = _io;
      this._parent = _parent;
      this._root = _root || this;

      this._read();
    }
    ChunksType.prototype._read = function() {
      this.chunk = [];
      var i = 0;
      while (!this._io.isEof()) {
        this.chunk.push(new ChunkType(this._io, this, this._root));
        i++;
      }
    }

    return ChunksType;
  })();

  var CueChunkType = Wav.CueChunkType = (function() {
    function CueChunkType(_io, _parent, _root) {
      this._io = _io;
      this._parent = _parent;
      this._root = _root || this;

      this._read();
    }
    CueChunkType.prototype._read = function() {
      this.dwCuePoints = this._io.readU4le();
      if (this.dwCuePoints != 0) {
        this.cuePoints = new Array(this.dwCuePoints);
        for (var i = 0; i < this.dwCuePoints; i++) {
          this.cuePoints[i] = new CuePointType(this._io, this, this._root);
        }
      }
    }

    return CueChunkType;
  })();

  var ChannelMaskType = Wav.ChannelMaskType = (function() {
    function ChannelMaskType(_io, _parent, _root) {
      this._io = _io;
      this._parent = _parent;
      this._root = _root || this;

      this._read();
    }
    ChannelMaskType.prototype._read = function() {
      this.frontRightOfCenter = this._io.readBitsInt(1) != 0;
      this.frontLeftOfCenter = this._io.readBitsInt(1) != 0;
      this.backRight = this._io.readBitsInt(1) != 0;
      this.backLeft = this._io.readBitsInt(1) != 0;
      this.lowFrequency = this._io.readBitsInt(1) != 0;
      this.frontCenter = this._io.readBitsInt(1) != 0;
      this.frontRight = this._io.readBitsInt(1) != 0;
      this.frontLeft = this._io.readBitsInt(1) != 0;
      this.topCenter = this._io.readBitsInt(1) != 0;
      this.sideRight = this._io.readBitsInt(1) != 0;
      this.sideLeft = this._io.readBitsInt(1) != 0;
      this.backCenter = this._io.readBitsInt(1) != 0;
      this.topBackLeft = this._io.readBitsInt(1) != 0;
      this.topFrontRight = this._io.readBitsInt(1) != 0;
      this.topFrontCenter = this._io.readBitsInt(1) != 0;
      this.topFrontLeft = this._io.readBitsInt(1) != 0;
      this.unused1 = this._io.readBitsInt(6);
      this.topBackRight = this._io.readBitsInt(1) != 0;
      this.topBackCenter = this._io.readBitsInt(1) != 0;
      this.unused2 = this._io.readBitsInt(8);
    }

    return ChannelMaskType;
  })();

  var ChunkType = Wav.ChunkType = (function() {
    function ChunkType(_io, _parent, _root) {
      this._io = _io;
      this._parent = _parent;
      this._root = _root || this;

      this._read();
    }
    ChunkType.prototype._read = function() {
      this.chunkId = this._io.readU4be();
      this.len = this._io.readU4le();
      switch (this.chunkId) {
      case 1684108385:
        this._raw_data = this._io.readBytes(this.len);
        var _io__raw_data = new KaitaiStream(this._raw_data);
        this.data = new DataChunkType(_io__raw_data, this, this._root);
        break;
      case 1668637984:
        this._raw_data = this._io.readBytes(this.len);
        var _io__raw_data = new KaitaiStream(this._raw_data);
        this.data = new CueChunkType(_io__raw_data, this, this._root);
        break;
      case 1650817140:
        this._raw_data = this._io.readBytes(this.len);
        var _io__raw_data = new KaitaiStream(this._raw_data);
        this.data = new BextChunkType(_io__raw_data, this, this._root);
        break;
      case 1718449184:
        this._raw_data = this._io.readBytes(this.len);
        var _io__raw_data = new KaitaiStream(this._raw_data);
        this.data = new FormatChunkType(_io__raw_data, this, this._root);
        break;
      default:
        this.data = this._io.readBytes(this.len);
        break;
      }
    }

    return ChunkType;
  })();

  var BextChunkType = Wav.BextChunkType = (function() {
    function BextChunkType(_io, _parent, _root) {
      this._io = _io;
      this._parent = _parent;
      this._root = _root || this;

      this._read();
    }
    BextChunkType.prototype._read = function() {
      this.description = KaitaiStream.bytesToStr(this._io.readBytes(256), "ASCII");
      this.originator = KaitaiStream.bytesToStr(this._io.readBytes(32), "ASCII");
      this.originatorReference = KaitaiStream.bytesToStr(this._io.readBytes(32), "ASCII");
      this.originationDate = KaitaiStream.bytesToStr(this._io.readBytes(10), "ASCII");
      this.originationTime = KaitaiStream.bytesToStr(this._io.readBytes(8), "ASCII");
      this.timeReferenceLow = this._io.readU4le();
      this.timeReferenceHigh = this._io.readU4le();
      this.version = this._io.readU2le();
      this.umid = this._io.readBytes(64);
      this.loudnessValue = this._io.readU2le();
      this.loudnessRange = this._io.readU2le();
      this.maxTruePeakLevel = this._io.readU2le();
      this.maxMomentaryLoudness = this._io.readU2le();
      this.maxShortTermLoudness = this._io.readU2le();
    }

    return BextChunkType;
  })();
  Object.defineProperty(Wav.prototype, 'formatChunk', {
    get: function() {
      if (this._m_formatChunk !== undefined)
        return this._m_formatChunk;
      this._m_formatChunk = this.chunks.chunk[0].data;
      return this._m_formatChunk;
    }
  });

  return Wav;
})();
return Wav;
}));