update brrUtils

This commit is contained in:
tildearrow 2022-09-24 05:43:33 -05:00
parent 8eaddcf070
commit 78baff55e8
2 changed files with 21 additions and 13 deletions

View File

@ -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;
}
}
return total;
}

View File

@ -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
#endif