1 /*
2 * DFPWM decoder
3 * Copyright (c) 2022 Jack Bruienne
4 * Copyright (c) 2012, 2016 Ben "GreaseMonkey" Russell
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 /**
24 * @file
25 * DFPWM1a decoder
26 */
27
33
37
38 // DFPWM codec from https://github.com/ChenThread/dfpwm/blob/master/1a/
39 // Licensed in the public domain
40
42 uint8_t *outbuf, const uint8_t *inbuf)
43 {
44 unsigned d;
45 for (
int i = 0;
i <
len;
i++) {
46 // get bits
47 d = *(inbuf++);
48 for (int j = 0; j < 8; j++) {
49 int nq, lq, st,
ns, ov;
50 // set target
51 int t = ((d&1) ? 127 : -128);
52 d >>= 1;
53
54 // adjust charge
56 if(nq ==
state->q && nq != t)
57 nq += (t == 127 ? 1 : -1);
60
61 // adjust strength
62 st = (t !=
state->lt ? 0 : 1023);
65 ns += (st != 0 ? 1 : -1);
68
69 // FILTER: perform antijerk
70 ov = (t !=
state->lt ? (nq+lq+1)>>1 : nq);
71
72 // FILTER: perform LPF
75
76 // output sample
77 *(outbuf++) = ov + 128;
78
80 }
81 }
82 }
83
85 {
87
92
94 ctx->bits_per_raw_sample = 8;
95
96 return 0;
97 }
98
100 int *got_frame,
struct AVPacket *packet)
101 {
104
105 if (packet->
size * 8LL %
ctx->ch_layout.nb_channels)
107
108 frame->nb_samples = packet->
size * 8LL /
ctx->ch_layout.nb_channels;
109 if (
frame->nb_samples <= 0) {
112 }
113
116
118
119 *got_frame = 1;
121 }
122
132 };