1
0
Fork 0
forked from len0rd/rockbox

Commit FS#10423 by Yoshihisa Uchida. Adds support for floating point PCM to libpcm.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24348 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Michael Giacomelli 2010-01-27 18:10:08 +00:00
parent 4de4a3fa1c
commit e04e2938e7
5 changed files with 159 additions and 2 deletions

View file

@ -34,15 +34,19 @@ enum {
AIFC_FORMAT_PCM = FOURCC('N', 'O', 'N', 'E'), /* AIFC PCM Format (big endian) */
AIFC_FORMAT_ALAW = FOURCC('a', 'l', 'a', 'w'), /* AIFC ALaw compressed */
AIFC_FORMAT_MULAW = FOURCC('u', 'l', 'a', 'w'), /* AIFC uLaw compressed */
AIFC_FORMAT_IEEE_FLOAT32 = FOURCC('f', 'l', '3', '2'), /* AIFC IEEE float 32 bit */
AIFC_FORMAT_IEEE_FLOAT64 = FOURCC('f', 'l', '6', '4'), /* AIFC IEEE float 64 bit */
};
static const struct pcm_entry pcm_codecs[] = {
{ AIFC_FORMAT_PCM, get_linear_pcm_codec },
{ AIFC_FORMAT_ALAW, get_itut_g711_alaw_codec },
{ AIFC_FORMAT_MULAW, get_itut_g711_mulaw_codec },
{ AIFC_FORMAT_IEEE_FLOAT32, get_ieee_float_codec },
{ AIFC_FORMAT_IEEE_FLOAT64, get_ieee_float_codec },
};
#define NUM_FORMATS 3
#define NUM_FORMATS 5
static int32_t samples[PCM_CHUNK_SIZE] IBSS_ATTR;

View file

@ -1,3 +1,4 @@
linear_pcm.c
itut_g711.c
dvi_adpcm.c
ieee_float.c

View file

@ -0,0 +1,147 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2009 Yoshihisa Uchida
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include "codeclib.h"
#include "pcm_common.h"
/*
* IEEE float
*/
static struct pcm_format *fmt;
static bool set_format(struct pcm_format *format, const unsigned char *fmtpos)
{
fmt = format;
(void)fmtpos;
if (fmt->bitspersample != 32 && fmt->bitspersample != 64)
{
DEBUGF("CODEC_ERROR: ieee float must be 32 or 64 bitspersample %d\n", fmt->bitspersample);
return false;
}
fmt->bytespersample = fmt->bitspersample >> 3;
fmt->blockalign = fmt->bytespersample;
/* chunksize is computed so that one chunk is about 1/50s. */
fmt->chunksize = (ci->id3->frequency * fmt->channels / 50) * fmt->blockalign;
return true;
}
static uint32_t get_seek_pos(long seek_time)
{
uint32_t newpos;
newpos = ((uint64_t)(seek_time * ci->id3->frequency * fmt->channels / 1000LL))*fmt->blockalign;
return newpos;
}
static int decode(const uint8_t *inbuf, size_t inbufsize,
int32_t *outbuf, int *outbufsize)
{
uint32_t i;
int32_t pcm;
int16_t exp;
int sgn;
if (fmt->bitspersample == 32)
{
for (i = 0; i < inbufsize; i += 4)
{
if (fmt->is_little_endian)
{
pcm = (inbuf[0]<<5)|(inbuf[1]<<13)|((inbuf[2]|0x80)<<21);
exp = ((inbuf[2]>>7)|((inbuf[3]&0x7f)<<1)) - 127;
sgn = inbuf[3] & 0x80;
}
else
{
pcm = (inbuf[3]<<5)|(inbuf[2]<<13)|((inbuf[1]|0x80)<<21);
exp = ((inbuf[1]>>7)|((inbuf[0]&0x7f)<<1)) - 127;
sgn = inbuf[0] & 0x80;
}
if (exp > -29 && exp < 0)
{
pcm >>= -exp;
if (sgn)
pcm = -pcm;
}
else if (exp < -28)
pcm = 0;
else
pcm = (sgn)?-(1<<28):(1<<28)-1;
outbuf[i/4] = pcm;
inbuf += 4;
}
*outbufsize = inbufsize >> 2;
}
else
{
for (i = 0; i < inbufsize; i += 8)
{
if (fmt->is_little_endian)
{
pcm = inbuf[3]|(inbuf[4]<<8)|(inbuf[5]<<16)|(((inbuf[6]&0x0f)|0x10)<<24);
exp = (((inbuf[6]&0xf0)>>4)|((inbuf[7]&0x7f)<<4)) - 1023;
sgn = inbuf[7] & 0x80;
}
else
{
pcm = inbuf[4]|(inbuf[3]<<8)|(inbuf[2]<<16)|(((inbuf[1]&0x0f)|0x10)<<24);
exp = (((inbuf[1]&0xf0)>>4)|((inbuf[0]&0x7f)<<4)) - 1023;
sgn = inbuf[0] & 0x80;
}
if (exp > -29 && exp < 0)
{
pcm >>= -exp;
if (sgn)
pcm = -pcm;
}
else if (exp < -28)
pcm = 0;
else
pcm = (sgn)?-(1<<28):(1<<28)-1;
outbuf[i/8] = pcm;
inbuf += 8;
}
*outbufsize = inbufsize >> 3;
}
if (fmt->channels == 2)
*outbufsize >>= 1;
return CODEC_OK;
}
static const struct pcm_codec codec = {
set_format,
get_seek_pos,
decode,
};
const struct pcm_codec *get_ieee_float_codec(void)
{
return &codec;
}

View file

@ -34,4 +34,7 @@ const struct pcm_codec *get_itut_g711_mulaw_codec(void);
/* Intel DVI ADPCM */
const struct pcm_codec *get_dvi_adpcm_codec(void);
/* IEEE float */
const struct pcm_codec *get_ieee_float_codec(void);
#endif

View file

@ -45,6 +45,7 @@ enum
{
WAVE_FORMAT_UNKNOWN = 0x0000, /* Microsoft Unknown Wave Format */
WAVE_FORMAT_PCM = 0x0001, /* Microsoft PCM Format */
WAVE_FORMAT_IEEE_FLOAT = 0x0003, /* IEEE Float */
WAVE_FORMAT_ALAW = 0x0006, /* Microsoft ALAW */
WAVE_FORMAT_MULAW = 0x0007, /* Microsoft MULAW */
WAVE_FORMAT_DVI_ADPCM = 0x0011, /* Intel's DVI ADPCM */
@ -56,6 +57,7 @@ enum
const struct pcm_entry wave_codecs[] = {
{ WAVE_FORMAT_UNKNOWN, 0 },
{ WAVE_FORMAT_PCM, get_linear_pcm_codec },
{ WAVE_FORMAT_IEEE_FLOAT, get_ieee_float_codec },
{ WAVE_FORMAT_ALAW, get_itut_g711_alaw_codec },
{ WAVE_FORMAT_MULAW, get_itut_g711_mulaw_codec },
{ WAVE_FORMAT_DVI_ADPCM, get_dvi_adpcm_codec },
@ -63,7 +65,7 @@ const struct pcm_entry wave_codecs[] = {
{ IBM_FORMAT_ALAW, get_itut_g711_alaw_codec },
};
#define NUM_FORMATS 7
#define NUM_FORMATS 8
static const struct pcm_codec *get_wave_codec(uint32_t formattag)
{