Subversion Repositories Games.Descent

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 pmbaty 1
/*
2
 * This file is part of the DXX-Rebirth project <https://www.dxx-rebirth.com/>.
3
 * It is copyright by its individual contributors, as recorded in the
4
 * project's Git history.  See COPYING.txt at the top level for license
5
 * terms and a link to the Git history.
6
 */
7
//THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
8
//SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
9
//END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
10
//ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
11
//IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
12
//SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
13
//FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
14
//CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
15
//AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
16
//COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
17
//
18
// $Source: /cvsroot/dxx-rebirth/d1x-rebirth/main/snddecom.c,v $
19
// $Revision: 1.1.1.1 $
20
// $Author: zicodxx $
21
// $Date: 2006/03/17 19:43:28 $
22
//
23
// Routines for compressing digital sounds.
24
//
25
// $Log: snddecom.c,v $
26
// Revision 1.1.1.1  2006/03/17 19:43:28  zicodxx
27
// initial import
28
//
29
// Revision 1.1.1.1  1999/06/14 22:11:34  donut
30
// Import of d1x 1.37 source.
31
//
32
// Revision 2.0  1995/02/27  11:29:36  john
33
// New version 2.0, which has no anonymous unions, builds with
34
// Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
35
//
36
// Revision 1.2  1994/11/30  14:08:46  john
37
// First version.
38
// Revision 1.1  1994/11/29  14:33:51  john
39
// Initial revision
40
//
41
 
42
#include "dxxsconf.h"
43
#include "snddecom.h"
44
#include <array>
45
 
46
const std::array<int, 16> index_table{{
47
        -1, -1, -1, -1, 2, 4, 6, 8, -1, -1, -1, -1, 2, 4, 6, 8
48
}};
49
const std::array<int, 89> step_table{{
50
        7, 8, 9, 10, 11, 12, 13, 14,
51
                      16,  1719,  21,  23,  25,  28,
52
                      31,  3437,  41,  45,  50,  55,
53
                      60,  6673,  80,  88,  97, 107,
54
                      118, 130, 143, 157, 173, 190, 209,
55
                      230, 253, 279, 307, 337, 371, 408,
56
                      449, 494, 544, 598, 658, 724, 796,
57
                      876, 963,1060,1166,1282,1411,1552,
58
                      1707,1878,
59
                      2066,2272,2499,2749,3024,3327,3660,4026,
60
                      4428,4871,5358,5894,6484,7132,7845,8630,
61
                      9493,10442,11487,12635,13899,15289,16818,
62
                      18500,20350,22385,24623,27086,29794,32767
63
}};
64
 
65
void sound_decompress(unsigned char *data, int size, unsigned char *outp) {
66
    int newtoken = 1;
67
    int predicted = 0, index = 0, step = 7;
68
    int code, diff, out;
69
    while (size) {
70
        if (newtoken)
71
            code = (*data) & 15;
72
        else {
73
            code = (*(data++)) >> 4;
74
            size--;
75
        }
76
        newtoken ^= 1;
77
        diff = 0;
78
        if (code & 4)
79
            diff += step;
80
        if (code & 2)
81
            diff += (step >> 1);
82
        if (code & 1)
83
            diff += (step >> 2);
84
        diff += (step >> 3);
85
        if (code & 8)
86
            diff = -diff;
87
        out = predicted + diff;
88
        if (out > 32767)
89
            out = 32767;
90
        if (out < -32768)
91
            out = -32768;
92
        predicted = out;
93
        *(outp++) = ((out >> 8) & 255) ^ 0x80;
94
        index += index_table[code];
95
        if (index < 0)
96
            index = 0;
97
        if (index > 88)
98
            index = 88;
99
        step = step_table[index];
100
    }
101
}