summaryrefslogtreecommitdiff
path: root/apps/codecs/libpcm/itut_g711.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/codecs/libpcm/itut_g711.c')
-rw-r--r--apps/codecs/libpcm/itut_g711.c44
1 files changed, 19 insertions, 25 deletions
diff --git a/apps/codecs/libpcm/itut_g711.c b/apps/codecs/libpcm/itut_g711.c
index 520ca46a7a..9a38031882 100644
--- a/apps/codecs/libpcm/itut_g711.c
+++ b/apps/codecs/libpcm/itut_g711.c
@@ -109,49 +109,43 @@ static const int16_t ulaw2linear16[256] ICONST_ATTR = {
109 109
110static struct pcm_format *fmt; 110static struct pcm_format *fmt;
111 111
112static bool set_format(struct pcm_format *format, const unsigned char *fmtpos) 112static bool set_format(struct pcm_format *format)
113{ 113{
114 fmt = format; 114 fmt = format;
115 115
116 (void)fmtpos;
117
118 if (fmt->bitspersample != 8) 116 if (fmt->bitspersample != 8)
119 { 117 {
120 DEBUGF("CODEC_ERROR: alaw and mulaw must have 8 bitspersample\n"); 118 DEBUGF("CODEC_ERROR: alaw and mulaw must have 8 bitspersample: %d\n",
119 fmt->bitspersample);
121 return false; 120 return false;
122 } 121 }
123 122
124 if (fmt->totalsamples == 0) 123 if (fmt->totalsamples == 0)
125 { 124 {
126 fmt->bytespersample = fmt->channels; 125 fmt->bytespersample = 1;
127 fmt->totalsamples = fmt->numbytes/fmt->bytespersample; 126 fmt->totalsamples = fmt->numbytes / (fmt->bytespersample * fmt->channels);
128 } 127 }
129 128
130 /* chunksize is computed so that one chunk is about 1/50s. 129 fmt->samplesperblock = fmt->blockalign / (fmt->bytespersample * fmt->channels);
131 * this make 4096 for 44.1kHz 16bits stereo.
132 * It also has to be a multiple of blockalign */
133 fmt->chunksize = (1 + fmt->avgbytespersec / (50*fmt->blockalign))*fmt->blockalign;
134 130
135 /* check that the output buffer is big enough (convert to samplespersec, 131 /* chunksize = about 1/50[sec] data */
136 then round to the blockalign multiple below) */ 132 fmt->chunksize = (ci->id3->frequency / (50 * fmt->samplesperblock))
137 if ((((uint64_t)fmt->chunksize * ci->id3->frequency * fmt->channels * fmt->bitspersample)>>3) 133 * fmt->blockalign;
138 /(uint64_t)fmt->avgbytespersec >= PCM_CHUNK_SIZE)
139 fmt->chunksize = ((uint64_t)PCM_CHUNK_SIZE * fmt->avgbytespersec
140 /((uint64_t)ci->id3->frequency * fmt->channels * 2
141 * fmt->blockalign)) * fmt->blockalign;
142 134
143 return true; 135 return true;
144} 136}
145 137
146static uint32_t get_seek_pos(long seek_time) 138static struct pcm_pos *get_seek_pos(long seek_time,
139 uint8_t *(*read_buffer)(size_t *realsize))
147{ 140{
148 uint32_t newpos; 141 static struct pcm_pos newpos;
149 142 uint32_t newblock = ((uint64_t)seek_time * ci->id3->frequency)
150 /* use avgbytespersec to round to the closest blockalign multiple, 143 / (1000LL * fmt->samplesperblock);
151 add firstblockposn. 64-bit casts to avoid overflows. */ 144
152 newpos = (((uint64_t)fmt->avgbytespersec*(seek_time - 1)) 145 (void)read_buffer;
153 / (1000LL*fmt->blockalign))*fmt->blockalign; 146 newpos.pos = newblock * fmt->blockalign;
154 return newpos; 147 newpos.samples = newblock * fmt->samplesperblock;
148 return &newpos;
155} 149}
156 150
157static int decode_alaw(const uint8_t *inbuf, size_t inbufsize, 151static int decode_alaw(const uint8_t *inbuf, size_t inbufsize,