annotate roqav.c @ 4771:ef9079037084

remove uneeded assert (common case at eof)
author atmos4
date Wed, 20 Feb 2002 22:41:54 +0000
parents e69bed07cb27
children 026329111b09
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4450
3da8c5706371 added skeleton decoders for RoQ audio and video format decoders
melanson
parents:
diff changeset
1 /*
3da8c5706371 added skeleton decoders for RoQ audio and video format decoders
melanson
parents:
diff changeset
2 RoQ A/V decoder for the MPlayer program
3da8c5706371 added skeleton decoders for RoQ audio and video format decoders
melanson
parents:
diff changeset
3 by Mike Melanson
4486
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
4 based on Dr. Tim Ferguson's RoQ document and accompanying source
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
5 code found at:
4450
3da8c5706371 added skeleton decoders for RoQ audio and video format decoders
melanson
parents:
diff changeset
6 http://www.csse.monash.edu.au/~timf/videocodec.html
3da8c5706371 added skeleton decoders for RoQ audio and video format decoders
melanson
parents:
diff changeset
7 */
3da8c5706371 added skeleton decoders for RoQ audio and video format decoders
melanson
parents:
diff changeset
8
3da8c5706371 added skeleton decoders for RoQ audio and video format decoders
melanson
parents:
diff changeset
9 #include "config.h"
3da8c5706371 added skeleton decoders for RoQ audio and video format decoders
melanson
parents:
diff changeset
10 #include "bswap.h"
3da8c5706371 added skeleton decoders for RoQ audio and video format decoders
melanson
parents:
diff changeset
11 #include <stdio.h>
4486
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
12 #include <stdlib.h>
4450
3da8c5706371 added skeleton decoders for RoQ audio and video format decoders
melanson
parents:
diff changeset
13
3da8c5706371 added skeleton decoders for RoQ audio and video format decoders
melanson
parents:
diff changeset
14 #define LE_16(x) (le2me_16(*(unsigned short *)(x)))
3da8c5706371 added skeleton decoders for RoQ audio and video format decoders
melanson
parents:
diff changeset
15 #define LE_32(x) (le2me_32(*(unsigned int *)(x)))
3da8c5706371 added skeleton decoders for RoQ audio and video format decoders
melanson
parents:
diff changeset
16
4486
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
17 #define CLAMP_S16(x) if (x < -32768) x = -32768; \
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
18 else if (x > 32767) x = 32767;
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
19 #define SE_16BIT(x) if (x & 0x8000) x -= 0x10000;
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
20 // sign extend a 4-bit value
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
21
4450
3da8c5706371 added skeleton decoders for RoQ audio and video format decoders
melanson
parents:
diff changeset
22 void *roq_decode_video_init(void)
3da8c5706371 added skeleton decoders for RoQ audio and video format decoders
melanson
parents:
diff changeset
23 {
3da8c5706371 added skeleton decoders for RoQ audio and video format decoders
melanson
parents:
diff changeset
24 }
3da8c5706371 added skeleton decoders for RoQ audio and video format decoders
melanson
parents:
diff changeset
25
3da8c5706371 added skeleton decoders for RoQ audio and video format decoders
melanson
parents:
diff changeset
26 void roq_decode_video(
3da8c5706371 added skeleton decoders for RoQ audio and video format decoders
melanson
parents:
diff changeset
27 unsigned char *encoded,
3da8c5706371 added skeleton decoders for RoQ audio and video format decoders
melanson
parents:
diff changeset
28 int encoded_size,
3da8c5706371 added skeleton decoders for RoQ audio and video format decoders
melanson
parents:
diff changeset
29 unsigned char *decoded,
3da8c5706371 added skeleton decoders for RoQ audio and video format decoders
melanson
parents:
diff changeset
30 int width,
3da8c5706371 added skeleton decoders for RoQ audio and video format decoders
melanson
parents:
diff changeset
31 int height,
3da8c5706371 added skeleton decoders for RoQ audio and video format decoders
melanson
parents:
diff changeset
32 void *context)
3da8c5706371 added skeleton decoders for RoQ audio and video format decoders
melanson
parents:
diff changeset
33 {
3da8c5706371 added skeleton decoders for RoQ audio and video format decoders
melanson
parents:
diff changeset
34 }
3da8c5706371 added skeleton decoders for RoQ audio and video format decoders
melanson
parents:
diff changeset
35
4486
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
36 // Initialize the RoQ audio decoder, which is to say, initialize the table
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
37 // of squares.
4450
3da8c5706371 added skeleton decoders for RoQ audio and video format decoders
melanson
parents:
diff changeset
38 void *roq_decode_audio_init(void)
3da8c5706371 added skeleton decoders for RoQ audio and video format decoders
melanson
parents:
diff changeset
39 {
4486
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
40 short *square_array;
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
41 short square;
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
42 int i;
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
43
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
44 square_array = (short *)malloc(256 * sizeof(short));
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
45 if (!square_array)
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
46 return NULL;
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
47
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
48 for (i = 0; i < 128; i++)
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
49 {
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
50 square = i * i;
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
51 square_array[i] = square;
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
52 square_array[i + 128] = -square;
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
53 }
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
54
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
55 return square_array;
4450
3da8c5706371 added skeleton decoders for RoQ audio and video format decoders
melanson
parents:
diff changeset
56 }
3da8c5706371 added skeleton decoders for RoQ audio and video format decoders
melanson
parents:
diff changeset
57
3da8c5706371 added skeleton decoders for RoQ audio and video format decoders
melanson
parents:
diff changeset
58 int roq_decode_audio(
3da8c5706371 added skeleton decoders for RoQ audio and video format decoders
melanson
parents:
diff changeset
59 unsigned short *output,
3da8c5706371 added skeleton decoders for RoQ audio and video format decoders
melanson
parents:
diff changeset
60 unsigned char *input,
4486
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
61 int encoded_size,
4450
3da8c5706371 added skeleton decoders for RoQ audio and video format decoders
melanson
parents:
diff changeset
62 int channels,
3da8c5706371 added skeleton decoders for RoQ audio and video format decoders
melanson
parents:
diff changeset
63 void *context)
3da8c5706371 added skeleton decoders for RoQ audio and video format decoders
melanson
parents:
diff changeset
64 {
4486
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
65 short *square_array = (short *)context;
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
66 int i;
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
67 int predictor[2];
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
68 int channel_number = 0;
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
69
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
70 // prepare the initial predictors
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
71 if (channels == 1)
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
72 predictor[0] = LE_16(&input[0]);
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
73 else
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
74 {
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
75 predictor[0] = input[1] << 8;
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
76 predictor[1] = input[0] << 8;
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
77 }
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
78 SE_16BIT(predictor[0]);
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
79 SE_16BIT(predictor[1]);
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
80
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
81 // decode the samples
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
82 for (i = 2; i < encoded_size; i++)
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
83 {
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
84 predictor[channel_number] += square_array[input[i]];
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
85 CLAMP_S16(predictor[channel_number]);
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
86 output[i - 2] = predictor[channel_number];
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
87
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
88 // toggle channel
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
89 channel_number ^= channels - 1;
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
90 }
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
91
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
92 // return the number of samples decoded
e69bed07cb27 further work on the RoQ audio decoder
melanson
parents: 4450
diff changeset
93 return (encoded_size - 2);
4450
3da8c5706371 added skeleton decoders for RoQ audio and video format decoders
melanson
parents:
diff changeset
94 }