summaryrefslogtreecommitdiff
path: root/apps/codecs/libpcm/linear_pcm.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/codecs/libpcm/linear_pcm.c')
-rw-r--r--apps/codecs/libpcm/linear_pcm.c39
1 files changed, 19 insertions, 20 deletions
diff --git a/apps/codecs/libpcm/linear_pcm.c b/apps/codecs/libpcm/linear_pcm.c
index 4db27ca2b3..5360d79901 100644
--- a/apps/codecs/libpcm/linear_pcm.c
+++ b/apps/codecs/libpcm/linear_pcm.c
@@ -29,12 +29,10 @@
29 29
30static struct pcm_format *fmt; 30static struct pcm_format *fmt;
31 31
32static bool set_format(struct pcm_format *format, const unsigned char *fmtpos) 32static bool set_format(struct pcm_format *format)
33{ 33{
34 fmt = format; 34 fmt = format;
35 35
36 (void)fmtpos;
37
38 if (fmt->bitspersample > 32) 36 if (fmt->bitspersample > 32)
39 { 37 {
40 DEBUGF("CODEC_ERROR: pcm with more than 32 bitspersample " 38 DEBUGF("CODEC_ERROR: pcm with more than 32 bitspersample "
@@ -42,33 +40,34 @@ static bool set_format(struct pcm_format *format, const unsigned char *fmtpos)
42 return false; 40 return false;
43 } 41 }
44 42
43 fmt->bytespersample = fmt->bitspersample >> 3;
44
45 if (fmt->totalsamples == 0) 45 if (fmt->totalsamples == 0)
46 {
47 fmt->bytespersample = (((fmt->bitspersample - 1)/8 + 1)*fmt->channels);
48 fmt->totalsamples = fmt->numbytes/fmt->bytespersample; 46 fmt->totalsamples = fmt->numbytes/fmt->bytespersample;
49 }
50 47
51 /* chunksize is computed so that one chunk is about 1/50s. 48 fmt->samplesperblock = fmt->blockalign / (fmt->bytespersample * fmt->channels);
52 * this make 4096 for 44.1kHz 16bits stereo. 49
53 * It also has to be a multiple of blockalign */ 50 /* chunksize = about 1/50[sec] data */
54 fmt->chunksize = (1 + fmt->avgbytespersec / (50*fmt->blockalign))*fmt->blockalign; 51 fmt->chunksize = (ci->id3->frequency / (50 * fmt->samplesperblock))
52 * fmt->blockalign;
55 53
56 return true; 54 return true;
57} 55}
58 56
59static uint32_t get_seek_pos(long seek_time) 57static struct pcm_pos *get_seek_pos(long seek_time,
58 uint8_t *(*read_buffer)(size_t *realsize))
60{ 59{
61 uint32_t newpos; 60 static struct pcm_pos newpos;
62 61 uint32_t newblock = ((uint64_t)seek_time * ci->id3->frequency)
63 /* use avgbytespersec to round to the closest blockalign multiple, 62 / (1000LL * fmt->samplesperblock);
64 add firstblockposn. 64-bit casts to avoid overflows. */ 63
65 newpos = (((uint64_t)fmt->avgbytespersec*(seek_time - 1)) 64 (void)read_buffer;
66 / (1000LL*fmt->blockalign))*fmt->blockalign; 65 newpos.pos = newblock * fmt->blockalign;
67 return newpos; 66 newpos.samples = newblock * fmt->samplesperblock;
67 return &newpos;
68} 68}
69 69
70static int decode(const uint8_t *inbuf, size_t inbufsize, 70static int decode(const uint8_t *inbuf, size_t inbufsize, int32_t *outbuf, int *outbufsize)
71 int32_t *outbuf, int *outbufsize)
72{ 71{
73 uint32_t i; 72 uint32_t i;
74 73