A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd

adler32: import adapted implementation from tinf/zlib

This adds an adapted version of the adler32 algorithm from tinf/zlib
which will be necessary to support ZLIB deflate streams in the future.

Change-Id: Ie60e15acb288acf56a2d44e3d3e912e1b3eb2216

+105
+1
firmware/SOURCES
··· 269 269 common/unicode.c 270 270 common/vuprintf.c 271 271 common/zip.c 272 + common/adler32.c 272 273 273 274 /* Display */ 274 275 scroll_engine.c
+75
firmware/common/adler32.c
··· 1 + /*************************************************************************** 2 + * __________ __ ___. 3 + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 + * \/ \/ \/ \/ \/ 8 + * $Id$ 9 + * 10 + * Copyright (C) 2021 James Buren (adaptations from tinf/zlib) 11 + * 12 + * This program is free software; you can redistribute it and/or 13 + * modify it under the terms of the GNU General Public License 14 + * as published by the Free Software Foundation; either version 2 15 + * of the License, or (at your option) any later version. 16 + * 17 + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 18 + * KIND, either express or implied. 19 + * 20 + ****************************************************************************/ 21 + 22 + #include "adler32.h" 23 + #include "system.h" 24 + 25 + /* adler_32 (derived from tinf adler32 which was taken from zlib) 26 + * Adler-32 algorithm taken from the zlib source, which is 27 + * Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler 28 + */ 29 + uint32_t adler_32(const void *src, uint32_t len, uint32_t adler32) 30 + { 31 + const unsigned char *buf = (const unsigned char *)src; 32 + uint32_t s1 = (adler32 & 0xffff); 33 + uint32_t s2 = (adler32 >> 16); 34 + 35 + enum { 36 + A32_BASE = 65521, 37 + A32_NMAX = 5552, 38 + }; 39 + 40 + while (len > 0) { 41 + uint32_t k = MIN(len, A32_NMAX); 42 + uint32_t i; 43 + 44 + for (i = k / 16; i; --i, buf += 16) { 45 + s2 += s1 += buf[0]; 46 + s2 += s1 += buf[1]; 47 + s2 += s1 += buf[2]; 48 + s2 += s1 += buf[3]; 49 + s2 += s1 += buf[4]; 50 + s2 += s1 += buf[5]; 51 + s2 += s1 += buf[6]; 52 + s2 += s1 += buf[7]; 53 + s2 += s1 += buf[8]; 54 + s2 += s1 += buf[9]; 55 + s2 += s1 += buf[10]; 56 + s2 += s1 += buf[11]; 57 + s2 += s1 += buf[12]; 58 + s2 += s1 += buf[13]; 59 + s2 += s1 += buf[14]; 60 + s2 += s1 += buf[15]; 61 + } 62 + 63 + for (i = k % 16; i; --i) { 64 + s1 += *buf++; 65 + s2 += s1; 66 + } 67 + 68 + s1 %= A32_BASE; 69 + s2 %= A32_BASE; 70 + 71 + len -= k; 72 + } 73 + 74 + return (s1 | (s2 << 16)); 75 + }
+29
firmware/include/adler32.h
··· 1 + /*************************************************************************** 2 + * __________ __ ___. 3 + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 + * \/ \/ \/ \/ \/ 8 + * $Id$ 9 + * 10 + * Copyright (C) 2021 James Buren (adaptations from tinf/zlib) 11 + * 12 + * This program is free software; you can redistribute it and/or 13 + * modify it under the terms of the GNU General Public License 14 + * as published by the Free Software Foundation; either version 2 15 + * of the License, or (at your option) any later version. 16 + * 17 + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 18 + * KIND, either express or implied. 19 + * 20 + ****************************************************************************/ 21 + 22 + #include <stdint.h> 23 + 24 + #ifndef _ADLER32_H 25 + #define _ADLER32_H 26 + 27 + uint32_t adler_32(const void *src, uint32_t len, uint32_t adler32); 28 + 29 + #endif