From 78baff55e844470302d3620ee91824ab773cbf9e Mon Sep 17 00:00:00 2001 From: tildearrow Date: Sat, 24 Sep 2022 05:43:33 -0500 Subject: [PATCH] update brrUtils --- src/engine/brrUtils.c | 26 ++++++++++++++++---------- src/engine/brrUtils.h | 8 +++++--- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/engine/brrUtils.c b/src/engine/brrUtils.c index 9f0c20bc..123ec165 100644 --- a/src/engine/brrUtils.c +++ b/src/engine/brrUtils.c @@ -22,13 +22,14 @@ #include "brrUtils.h" -void brrEncode(short* buf, unsigned char* out, long len) { - if (len==0) return; +long brrEncode(short* buf, unsigned char* out, long len) { + if (len==0) return 0; // TODO + return 0; } #define DO_ONE_SAMPLE \ - if (next&8) next|=0xfff8; \ + if (next&8) next|=0xfffffff8; \ \ next<<=(buf[0]>>4); /* range */ \ \ @@ -39,10 +40,10 @@ void brrEncode(short* buf, unsigned char* out, long len) { next+=(last1*15)/16; \ break; \ case 8: \ - next+=(last1*61)/32-(last2*15)/16; \ + next+=((last1*61)/32)-((last2*15)/16); \ break; \ case 12: \ - next+=(last1*115)/64-(last2*13)/16; \ + next+=((last1*115)/64)-((last2*13)/16); \ break; \ } \ \ @@ -54,8 +55,10 @@ void brrEncode(short* buf, unsigned char* out, long len) { *out=next; \ out++; -void brrDecode(unsigned char* buf, short* out, long len) { - if (len==0) return; +long brrDecode(unsigned char* buf, short* out, long len) { + if (len==0) return 0; + + long total=0; int last1=0; int last2=0; @@ -68,15 +71,18 @@ void brrDecode(unsigned char* buf, short* out, long len) { unsigned char control=buf[0]; for (unsigned char j=1; j<9; j++) { - next=buf[j]&15; + next=buf[j]>>4; DO_ONE_SAMPLE; - next=buf[j]>>4; + next=buf[j]&15; DO_ONE_SAMPLE; } // end bit + total+=16; if (control&1) break; buf+=9; } -} \ No newline at end of file + + return total; +} diff --git a/src/engine/brrUtils.h b/src/engine/brrUtils.h index 85192e45..ba3a6f53 100644 --- a/src/engine/brrUtils.h +++ b/src/engine/brrUtils.h @@ -32,19 +32,21 @@ extern "C" { * @param buf input data. * @param out output buffer. shall be at least 9*(len/16) shorts in size. * @param len input length (should be a multiple of 16. if it isn't, the output will be padded). + * @return number of written samples. */ -void brrEncode(short* buf, unsigned char* out, long len); +long brrEncode(short* buf, unsigned char* out, long len); /** * read len bytes from buf, decode BRR and output to out. * @param buf input data. * @param out output buffer. shall be at least 16*(len/9) shorts in size. * @param len input length (shall be a multiple of 9). + * @return number of written bytes. */ -void brrDecode(unsigned char* buf, short* out, long len); +long brrDecode(unsigned char* buf, short* out, long len); #ifdef __cplusplus } #endif -#endif \ No newline at end of file +#endif