summaryrefslogtreecommitdiff
path: root/apps/codecs/libpcm
diff options
context:
space:
mode:
authorMichael Giacomelli <giac2000@hotmail.com>2010-01-27 18:10:08 +0000
committerMichael Giacomelli <giac2000@hotmail.com>2010-01-27 18:10:08 +0000
commite04e2938e79c40a8455f2c713d339ed0d41ad6ef (patch)
tree4e07c810bbf2ca8272889430a4818a2e4a644d41 /apps/codecs/libpcm
parent4de4a3fa1c1f10fbaa544195aad98cc914563e9f (diff)
downloadrockbox-e04e2938e79c40a8455f2c713d339ed0d41ad6ef.tar.gz
rockbox-e04e2938e79c40a8455f2c713d339ed0d41ad6ef.zip
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
Diffstat (limited to 'apps/codecs/libpcm')
-rw-r--r--apps/codecs/libpcm/SOURCES1
-rw-r--r--apps/codecs/libpcm/ieee_float.c147
-rw-r--r--apps/codecs/libpcm/support_formats.h3
3 files changed, 151 insertions, 0 deletions
diff --git a/apps/codecs/libpcm/SOURCES b/apps/codecs/libpcm/SOURCES
index e921584f7c..89be3452b1 100644
--- a/apps/codecs/libpcm/SOURCES
+++ b/apps/codecs/libpcm/SOURCES
@@ -1,3 +1,4 @@
1linear_pcm.c 1linear_pcm.c
2itut_g711.c 2itut_g711.c
3dvi_adpcm.c 3dvi_adpcm.c
4ieee_float.c
diff --git a/apps/codecs/libpcm/ieee_float.c b/apps/codecs/libpcm/ieee_float.c
new file mode 100644
index 0000000000..a5c50e845e
--- /dev/null
+++ b/apps/codecs/libpcm/ieee_float.c
@@ -0,0 +1,147 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2009 Yoshihisa Uchida
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#include "codeclib.h"
22#include "pcm_common.h"
23
24/*
25 * IEEE float
26 */
27
28static struct pcm_format *fmt;
29
30static bool set_format(struct pcm_format *format, const unsigned char *fmtpos)
31{
32 fmt = format;
33
34 (void)fmtpos;
35
36 if (fmt->bitspersample != 32 && fmt->bitspersample != 64)
37 {
38 DEBUGF("CODEC_ERROR: ieee float must be 32 or 64 bitspersample %d\n", fmt->bitspersample);
39 return false;
40 }
41
42 fmt->bytespersample = fmt->bitspersample >> 3;
43 fmt->blockalign = fmt->bytespersample;
44
45 /* chunksize is computed so that one chunk is about 1/50s. */
46 fmt->chunksize = (ci->id3->frequency * fmt->channels / 50) * fmt->blockalign;
47
48 return true;
49}
50
51static uint32_t get_seek_pos(long seek_time)
52{
53 uint32_t newpos;
54
55 newpos = ((uint64_t)(seek_time * ci->id3->frequency * fmt->channels / 1000LL))*fmt->blockalign;
56 return newpos;
57}
58
59static int decode(const uint8_t *inbuf, size_t inbufsize,
60 int32_t *outbuf, int *outbufsize)
61{
62 uint32_t i;
63 int32_t pcm;
64 int16_t exp;
65 int sgn;
66
67 if (fmt->bitspersample == 32)
68 {
69 for (i = 0; i < inbufsize; i += 4)
70 {
71 if (fmt->is_little_endian)
72 {
73 pcm = (inbuf[0]<<5)|(inbuf[1]<<13)|((inbuf[2]|0x80)<<21);
74 exp = ((inbuf[2]>>7)|((inbuf[3]&0x7f)<<1)) - 127;
75 sgn = inbuf[3] & 0x80;
76 }
77 else
78 {
79 pcm = (inbuf[3]<<5)|(inbuf[2]<<13)|((inbuf[1]|0x80)<<21);
80 exp = ((inbuf[1]>>7)|((inbuf[0]&0x7f)<<1)) - 127;
81 sgn = inbuf[0] & 0x80;
82 }
83 if (exp > -29 && exp < 0)
84 {
85 pcm >>= -exp;
86 if (sgn)
87 pcm = -pcm;
88 }
89 else if (exp < -28)
90 pcm = 0;
91 else
92 pcm = (sgn)?-(1<<28):(1<<28)-1;
93
94 outbuf[i/4] = pcm;
95 inbuf += 4;
96 }
97 *outbufsize = inbufsize >> 2;
98 }
99 else
100 {
101 for (i = 0; i < inbufsize; i += 8)
102 {
103 if (fmt->is_little_endian)
104 {
105 pcm = inbuf[3]|(inbuf[4]<<8)|(inbuf[5]<<16)|(((inbuf[6]&0x0f)|0x10)<<24);
106 exp = (((inbuf[6]&0xf0)>>4)|((inbuf[7]&0x7f)<<4)) - 1023;
107 sgn = inbuf[7] & 0x80;
108 }
109 else
110 {
111 pcm = inbuf[4]|(inbuf[3]<<8)|(inbuf[2]<<16)|(((inbuf[1]&0x0f)|0x10)<<24);
112 exp = (((inbuf[1]&0xf0)>>4)|((inbuf[0]&0x7f)<<4)) - 1023;
113 sgn = inbuf[0] & 0x80;
114 }
115 if (exp > -29 && exp < 0)
116 {
117 pcm >>= -exp;
118 if (sgn)
119 pcm = -pcm;
120 }
121 else if (exp < -28)
122 pcm = 0;
123 else
124 pcm = (sgn)?-(1<<28):(1<<28)-1;
125
126 outbuf[i/8] = pcm;
127 inbuf += 8;
128 }
129 *outbufsize = inbufsize >> 3;
130 }
131
132 if (fmt->channels == 2)
133 *outbufsize >>= 1;
134
135 return CODEC_OK;
136}
137
138static const struct pcm_codec codec = {
139 set_format,
140 get_seek_pos,
141 decode,
142 };
143
144const struct pcm_codec *get_ieee_float_codec(void)
145{
146 return &codec;
147}
diff --git a/apps/codecs/libpcm/support_formats.h b/apps/codecs/libpcm/support_formats.h
index 9a1f4f764d..0a6ea339f4 100644
--- a/apps/codecs/libpcm/support_formats.h
+++ b/apps/codecs/libpcm/support_formats.h
@@ -34,4 +34,7 @@ const struct pcm_codec *get_itut_g711_mulaw_codec(void);
34 34
35/* Intel DVI ADPCM */ 35/* Intel DVI ADPCM */
36const struct pcm_codec *get_dvi_adpcm_codec(void); 36const struct pcm_codec *get_dvi_adpcm_codec(void);
37
38/* IEEE float */
39const struct pcm_codec *get_ieee_float_codec(void);
37#endif 40#endif