Revision 86bec9a1 libav/wav.c

View differences:

libav/wav.c
33 33
/* WAVEFORMATEX header */
34 34
int put_wav_header(ByteIOContext *pb, AVCodecContext *enc)
35 35
{
36
    int tag, bps;
36
    int tag, bps, blkalign, bytespersec;
37 37

  
38 38
    tag = codec_get_tag(codec_wav_tags, enc->codec_id);
39 39
    if (tag == 0)
......
41 41
    put_le16(pb, tag); 
42 42
    put_le16(pb, enc->channels);
43 43
    put_le32(pb, enc->sample_rate);
44
    put_le32(pb, enc->bit_rate / 8);
45
    put_le16(pb, 1); /* block align */
46 44
    if (enc->codec_id == CODEC_ID_PCM_U8 ||
47 45
        enc->codec_id == CODEC_ID_PCM_ALAW ||
48 46
        enc->codec_id == CODEC_ID_PCM_MULAW) {
49 47
        bps = 8;
48
    } else if (enc->codec_id == CODEC_ID_MP2) {
49
        bps = 0;
50 50
    } else {
51 51
        bps = 16;
52 52
    }
53
    put_le16(pb, bps); /* bits per sample */
54 53
    
55
    put_le16(pb, 0); /* wav_extra_size */
54
    if (enc->codec_id == CODEC_ID_MP2)
55
        blkalign = 1;
56
    else
57
        blkalign = enc->channels*bps >> 3;
58
    if (enc->codec_id == CODEC_ID_PCM_U8 ||
59
        enc->codec_id == CODEC_ID_PCM_S16LE) {
60
        bytespersec = enc->sample_rate * blkalign;
61
    } else {
62
        bytespersec = enc->bit_rate / 8;
63
    }
64
    put_le32(pb, bytespersec); /* bytes per second */
65
    put_le16(pb, blkalign); /* block align */
66
    put_le16(pb, bps); /* bits per sample */
67
    if (enc->codec_id == CODEC_ID_MP2) {
68
        put_le16(pb, 12); /* wav_extra_size */
69
        put_le16(pb, 1); /* wID */
70
        put_le32(pb, 2); /* fdwFlags */
71
        put_le16(pb, 1152); /* nBlockSize */
72
        put_le16(pb, 1); /* nFramesPerBlock */
73
        put_le16(pb, 1393); /* nCodecDelay */
74
    } else
75
        put_le16(pb, 0); /* wav_extra_size */
76

  
56 77
    return 0;
57 78
}
58 79

  

Also available in: Unified diff