Add support for 16 bit 'half float' format PCM.
I'm not 100% sure that the rounding of denormals is correct. As compared to foobar2000, some samples are off by +1 LSB. However, since I can't output 24 bit PCM easily with rockbox, I'm not sure if this is due to a bug or just how rockbox rounds. In practice I don't think it matters so I'm just going to commit this for now. Change-Id: Ic0792fcb172e4369a5512d202121c2b918b36079
This commit is contained in:
parent
3a39f77ed6
commit
d594b36133
1 changed files with 28 additions and 1 deletions
|
@ -38,7 +38,7 @@ static bool set_format(struct pcm_format *format)
|
|||
return false;
|
||||
}
|
||||
|
||||
if (fmt->bitspersample != 32 && fmt->bitspersample != 64)
|
||||
if (fmt->bitspersample != 16 && fmt->bitspersample != 32 && fmt->bitspersample != 64)
|
||||
{
|
||||
DEBUGF("CODEC_ERROR: ieee float must be 32 or 64 bitspersample: %d\n",
|
||||
fmt->bitspersample);
|
||||
|
@ -114,6 +114,33 @@ static int decode(const uint8_t *inbuf, size_t inbufsize,
|
|||
}
|
||||
*outbufsize = inbufsize >> 2;
|
||||
}
|
||||
else if (fmt->bitspersample == 16)
|
||||
{
|
||||
for (i = 0; i < inbufsize; i += 2)
|
||||
{
|
||||
pcm = inbuf[0]|((inbuf[1]&0x03)<<8);
|
||||
exp = ((inbuf[1]&0x7c)>>2)-15;
|
||||
sgn = (inbuf[1] & 0x80)>>7;
|
||||
|
||||
if(exp == -15)
|
||||
pcm =0;
|
||||
else
|
||||
{
|
||||
pcm+=1<<10;
|
||||
exp+=2; /*shift by 2 for rockbox fixed format*/
|
||||
if(exp>=0)
|
||||
pcm <<= (exp);
|
||||
else
|
||||
pcm >>= (-exp);
|
||||
|
||||
if (sgn)
|
||||
pcm = -pcm;
|
||||
}
|
||||
outbuf[i/2] = pcm;
|
||||
inbuf += 2;
|
||||
}
|
||||
*outbufsize = inbufsize >> 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < inbufsize; i += 8)
|
||||
|
|
Loading…
Reference in a new issue