Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
F
ffmpeg.wasm-core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Linshizhi
ffmpeg.wasm-core
Commits
d94728c3
Commit
d94728c3
authored
Jan 10, 2004
by
Michael Niedermayer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleanup
Originally committed as revision 2684 to
svn://svn.ffmpeg.org/ffmpeg/trunk
parent
821e46f4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
71 deletions
+29
-71
adpcm.c
libavcodec/adpcm.c
+29
-71
No files found.
libavcodec/adpcm.c
View file @
d94728c3
...
...
@@ -299,7 +299,7 @@ static int adpcm_decode_init(AVCodecContext * avctx)
return
0
;
}
static
inline
short
adpcm_ima_expand_nibble
(
ADPCMChannelStatus
*
c
,
char
nibble
)
static
inline
short
adpcm_ima_expand_nibble
(
ADPCMChannelStatus
*
c
,
char
nibble
,
int
shift
)
{
int
step_index
;
int
predictor
;
...
...
@@ -315,34 +315,7 @@ static inline short adpcm_ima_expand_nibble(ADPCMChannelStatus *c, char nibble)
/* perform direct multiplication instead of series of jumps proposed by
* the reference ADPCM implementation since modern CPUs can do the mults
* quickly enough */
diff
=
((
2
*
delta
+
1
)
*
step
)
>>
3
;
predictor
=
c
->
predictor
;
if
(
sign
)
predictor
-=
diff
;
else
predictor
+=
diff
;
CLAMP_TO_SHORT
(
predictor
);
c
->
predictor
=
predictor
;
c
->
step_index
=
step_index
;
return
(
short
)
predictor
;
}
static
inline
short
adpcm_4xa_expand_nibble
(
ADPCMChannelStatus
*
c
,
char
nibble
)
{
int
step_index
;
int
predictor
;
int
sign
,
delta
,
diff
,
step
;
step
=
step_table
[
c
->
step_index
];
step_index
=
c
->
step_index
+
index_table
[(
unsigned
)
nibble
];
if
(
step_index
<
0
)
step_index
=
0
;
else
if
(
step_index
>
88
)
step_index
=
88
;
sign
=
nibble
&
8
;
delta
=
nibble
&
7
;
diff
=
(
delta
*
step
+
(
step
>>
1
))
>>
3
;
// difference to code above
diff
=
((
2
*
delta
+
1
)
*
step
)
>>
shift
;
predictor
=
c
->
predictor
;
if
(
sign
)
predictor
-=
diff
;
else
predictor
+=
diff
;
...
...
@@ -505,9 +478,9 @@ static int adpcm_decode_frame(AVCodecContext *avctx,
samples
++
;
for
(
m
=
32
;
n
>
0
&&
m
>
0
;
n
--
,
m
--
)
{
/* in QuickTime, IMA is encoded by chuncks of 34 bytes (=64 samples) */
*
samples
=
adpcm_ima_expand_nibble
(
cs
,
src
[
0
]
&
0x0F
);
*
samples
=
adpcm_ima_expand_nibble
(
cs
,
src
[
0
]
&
0x0F
,
3
);
samples
+=
avctx
->
channels
;
*
samples
=
adpcm_ima_expand_nibble
(
cs
,
(
src
[
0
]
>>
4
)
&
0x0F
);
*
samples
=
adpcm_ima_expand_nibble
(
cs
,
(
src
[
0
]
>>
4
)
&
0x0F
,
3
);
samples
+=
avctx
->
channels
;
src
++
;
}
...
...
@@ -524,44 +497,29 @@ static int adpcm_decode_frame(AVCodecContext *avctx,
if
(
avctx
->
block_align
!=
0
&&
buf_size
>
avctx
->
block_align
)
buf_size
=
avctx
->
block_align
;
// XXX: do as per-channel loop
cs
=
&
(
c
->
status
[
0
]);
cs
->
predictor
=
(
*
src
++
)
&
0x0FF
;
cs
->
predictor
|=
((
*
src
++
)
<<
8
)
&
0x0FF00
;
if
(
cs
->
predictor
&
0x8000
)
cs
->
predictor
-=
0x10000
;
CLAMP_TO_SHORT
(
cs
->
predictor
);
// XXX: is this correct ??: *samples++ = cs->predictor;
cs
->
step_index
=
*
src
++
;
if
(
cs
->
step_index
<
0
)
cs
->
step_index
=
0
;
if
(
cs
->
step_index
>
88
)
cs
->
step_index
=
88
;
if
(
*
src
++
)
av_log
(
avctx
,
AV_LOG_ERROR
,
"unused byte should be null !!
\n
"
);
/* unused */
if
(
st
)
{
cs
=
&
(
c
->
status
[
1
]);
cs
->
predictor
=
(
*
src
++
)
&
0x0FF
;
cs
->
predictor
|=
((
*
src
++
)
<<
8
)
&
0x0FF00
;
for
(
i
=
0
;
i
<
avctx
->
channels
;
i
++
){
cs
=
&
(
c
->
status
[
i
]);
cs
->
predictor
=
*
src
++
;
cs
->
predictor
|=
(
*
src
++
)
<<
8
;
if
(
cs
->
predictor
&
0x8000
)
cs
->
predictor
-=
0x10000
;
CLAMP_TO_SHORT
(
cs
->
predictor
);
// XXX: is this correct ??: *samples++ = cs->predictor;
// XXX: is this correct ??: *samples++ = cs->predictor;
cs
->
step_index
=
*
src
++
;
cs
->
step_index
=
*
src
++
;
if
(
cs
->
step_index
<
0
)
cs
->
step_index
=
0
;
if
(
cs
->
step_index
>
88
)
cs
->
step_index
=
88
;
src
++
;
/* if != 0 -> out-of-sync
*/
if
(
*
src
++
)
av_log
(
avctx
,
AV_LOG_ERROR
,
"unused byte should be null !!
\n
"
);
/* unused
*/
}
for
(
m
=
4
;
src
<
(
buf
+
buf_size
);)
{
*
samples
++
=
adpcm_ima_expand_nibble
(
&
c
->
status
[
0
],
src
[
0
]
&
0x0F
);
*
samples
++
=
adpcm_ima_expand_nibble
(
&
c
->
status
[
0
],
src
[
0
]
&
0x0F
,
3
);
if
(
st
)
*
samples
++
=
adpcm_ima_expand_nibble
(
&
c
->
status
[
1
],
src
[
4
]
&
0x0F
);
*
samples
++
=
adpcm_ima_expand_nibble
(
&
c
->
status
[
0
],
(
src
[
0
]
>>
4
)
&
0x0F
);
*
samples
++
=
adpcm_ima_expand_nibble
(
&
c
->
status
[
1
],
src
[
4
]
&
0x0F
,
3
);
*
samples
++
=
adpcm_ima_expand_nibble
(
&
c
->
status
[
0
],
(
src
[
0
]
>>
4
)
&
0x0F
,
3
);
if
(
st
)
{
*
samples
++
=
adpcm_ima_expand_nibble
(
&
c
->
status
[
1
],
(
src
[
4
]
>>
4
)
&
0x0F
);
*
samples
++
=
adpcm_ima_expand_nibble
(
&
c
->
status
[
1
],
(
src
[
4
]
>>
4
)
&
0x0F
,
3
);
if
(
!--
m
)
{
m
=
4
;
src
+=
4
;
...
...
@@ -585,12 +543,12 @@ static int adpcm_decode_frame(AVCodecContext *avctx,
m
=
(
buf_size
-
(
src
-
buf
))
>>
st
;
for
(
i
=
0
;
i
<
m
;
i
++
)
{
*
samples
++
=
adpcm_
4xa_expand_nibble
(
&
c
->
status
[
0
],
src
[
i
]
&
0x0F
);
*
samples
++
=
adpcm_
ima_expand_nibble
(
&
c
->
status
[
0
],
src
[
i
]
&
0x0F
,
4
);
if
(
st
)
*
samples
++
=
adpcm_
4xa_expand_nibble
(
&
c
->
status
[
1
],
src
[
i
+
m
]
&
0x0F
);
*
samples
++
=
adpcm_
4xa_expand_nibble
(
&
c
->
status
[
0
],
src
[
i
]
>>
4
);
*
samples
++
=
adpcm_
ima_expand_nibble
(
&
c
->
status
[
1
],
src
[
i
+
m
]
&
0x0F
,
4
);
*
samples
++
=
adpcm_
ima_expand_nibble
(
&
c
->
status
[
0
],
src
[
i
]
>>
4
,
4
);
if
(
st
)
*
samples
++
=
adpcm_
4xa_expand_nibble
(
&
c
->
status
[
1
],
src
[
i
+
m
]
>>
4
);
*
samples
++
=
adpcm_
ima_expand_nibble
(
&
c
->
status
[
1
],
src
[
i
+
m
]
>>
4
,
4
);
}
src
+=
m
<<
st
;
...
...
@@ -664,16 +622,16 @@ static int adpcm_decode_frame(AVCodecContext *avctx,
/* take care of the top nibble (always left or mono channel) */
*
samples
++
=
adpcm_ima_expand_nibble
(
&
c
->
status
[
0
],
(
src
[
0
]
>>
4
)
&
0x0F
);
(
src
[
0
]
>>
4
)
&
0x0F
,
3
);
/* take care of the bottom nibble, which is right sample for
* stereo, or another mono sample */
if
(
st
)
*
samples
++
=
adpcm_ima_expand_nibble
(
&
c
->
status
[
1
],
src
[
0
]
&
0x0F
);
src
[
0
]
&
0x0F
,
3
);
else
*
samples
++
=
adpcm_ima_expand_nibble
(
&
c
->
status
[
0
],
src
[
0
]
&
0x0F
);
src
[
0
]
&
0x0F
,
3
);
src
++
;
}
...
...
@@ -703,11 +661,11 @@ static int adpcm_decode_frame(AVCodecContext *avctx,
/* process the first predictor of the sum channel */
DK3_GET_NEXT_NIBBLE
();
adpcm_ima_expand_nibble
(
&
c
->
status
[
0
],
nibble
);
adpcm_ima_expand_nibble
(
&
c
->
status
[
0
],
nibble
,
3
);
/* process the diff channel predictor */
DK3_GET_NEXT_NIBBLE
();
adpcm_ima_expand_nibble
(
&
c
->
status
[
1
],
nibble
);
adpcm_ima_expand_nibble
(
&
c
->
status
[
1
],
nibble
,
3
);
/* process the first pair of stereo PCM samples */
diff_channel
=
(
diff_channel
+
c
->
status
[
1
].
predictor
)
/
2
;
...
...
@@ -716,7 +674,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx,
/* process the second predictor of the sum channel */
DK3_GET_NEXT_NIBBLE
();
adpcm_ima_expand_nibble
(
&
c
->
status
[
0
],
nibble
);
adpcm_ima_expand_nibble
(
&
c
->
status
[
0
],
nibble
,
3
);
/* process the second pair of stereo PCM samples */
diff_channel
=
(
diff_channel
+
c
->
status
[
1
].
predictor
)
/
2
;
...
...
@@ -730,14 +688,14 @@ static int adpcm_decode_frame(AVCodecContext *avctx,
if
(
st
)
{
*
samples
++
=
adpcm_ima_expand_nibble
(
&
c
->
status
[
0
],
(
src
[
0
]
>>
4
)
&
0x0F
);
(
src
[
0
]
>>
4
)
&
0x0F
,
3
);
*
samples
++
=
adpcm_ima_expand_nibble
(
&
c
->
status
[
1
],
src
[
0
]
&
0x0F
);
src
[
0
]
&
0x0F
,
3
);
}
else
{
*
samples
++
=
adpcm_ima_expand_nibble
(
&
c
->
status
[
0
],
(
src
[
0
]
>>
4
)
&
0x0F
);
(
src
[
0
]
>>
4
)
&
0x0F
,
3
);
*
samples
++
=
adpcm_ima_expand_nibble
(
&
c
->
status
[
0
],
src
[
0
]
&
0x0F
);
src
[
0
]
&
0x0F
,
3
);
}
src
++
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment