Mercurial > mplayer.hg
annotate roqav.c @ 4768:a64075b4970a
Fixed (I hope) little bug wich lead to sig11 after last playtree entry
author | albeu |
---|---|
date | Wed, 20 Feb 2002 17:03:35 +0000 |
parents | e69bed07cb27 |
children | 026329111b09 |
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 | 4 based on Dr. Tim Ferguson's RoQ document and accompanying source |
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 | 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 | 17 #define CLAMP_S16(x) if (x < -32768) x = -32768; \ |
18 else if (x > 32767) x = 32767; | |
19 #define SE_16BIT(x) if (x & 0x8000) x -= 0x10000; | |
20 // sign extend a 4-bit value | |
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 | 36 // Initialize the RoQ audio decoder, which is to say, initialize the table |
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 | 40 short *square_array; |
41 short square; | |
42 int i; | |
43 | |
44 square_array = (short *)malloc(256 * sizeof(short)); | |
45 if (!square_array) | |
46 return NULL; | |
47 | |
48 for (i = 0; i < 128; i++) | |
49 { | |
50 square = i * i; | |
51 square_array[i] = square; | |
52 square_array[i + 128] = -square; | |
53 } | |
54 | |
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 | 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 | 65 short *square_array = (short *)context; |
66 int i; | |
67 int predictor[2]; | |
68 int channel_number = 0; | |
69 | |
70 // prepare the initial predictors | |
71 if (channels == 1) | |
72 predictor[0] = LE_16(&input[0]); | |
73 else | |
74 { | |
75 predictor[0] = input[1] << 8; | |
76 predictor[1] = input[0] << 8; | |
77 } | |
78 SE_16BIT(predictor[0]); | |
79 SE_16BIT(predictor[1]); | |
80 | |
81 // decode the samples | |
82 for (i = 2; i < encoded_size; i++) | |
83 { | |
84 predictor[channel_number] += square_array[input[i]]; | |
85 CLAMP_S16(predictor[channel_number]); | |
86 output[i - 2] = predictor[channel_number]; | |
87 | |
88 // toggle channel | |
89 channel_number ^= channels - 1; | |
90 } | |
91 | |
92 // return the number of samples decoded | |
93 return (encoded_size - 2); | |
4450
3da8c5706371
added skeleton decoders for RoQ audio and video format decoders
melanson
parents:
diff
changeset
|
94 } |