ReactOS 0.4.16-dev-136-g52192f1
format.c File Reference
#include "mpg123lib_intern.h"
#include "sample.h"
#include "debug.h"
#include "swap_bytes_impl.h"
Include dependency graph for format.c:

Go to the source code of this file.

Macros

#define MPG123_FLOAT_ENC   MPG123_ENC_FLOAT_32
 
#define ENCRANGE(range)   imax(f0, range[0]), imin(f2, range[1])
 

Functions

static int good_enc (const int enc)
 
void attribute_align_arg mpg123_rates (const long **list, size_t *number)
 
void attribute_align_arg mpg123_encodings (const int **list, size_t *number)
 
int attribute_align_arg mpg123_encsize (int encoding)
 
static int rate2num (mpg123_pars *mp, long r)
 
static int enc2num (int encoding)
 
static int cap_fit (mpg123_pars *p, struct audioformat *nf, int f0, int f2)
 
static int imin (int a, int b)
 
static int imax (int a, int b)
 
static int enc_chan_fit (mpg123_pars *p, long rate, struct audioformat *nnf, int f0, int f2, int try_float)
 
int frame_output_format (mpg123_handle *fr)
 
int attribute_align_arg mpg123_format_none (mpg123_handle *mh)
 
int attribute_align_arg mpg123_fmt_none (mpg123_pars *mp)
 
int attribute_align_arg mpg123_format_all (mpg123_handle *mh)
 
int attribute_align_arg mpg123_fmt_all (mpg123_pars *mp)
 
int attribute_align_arg mpg123_format2 (mpg123_handle *mh, long rate, int channels, int encodings)
 
int attribute_align_arg mpg123_format (mpg123_handle *mh, long rate, int channels, int encodings)
 
int attribute_align_arg mpg123_fmt2 (mpg123_pars *mp, long rate, int channels, int encodings)
 
int attribute_align_arg mpg123_fmt (mpg123_pars *mp, long rate, int channels, int encodings)
 
int attribute_align_arg mpg123_format_support (mpg123_handle *mh, long rate, int encoding)
 
int attribute_align_arg mpg123_fmt_support (mpg123_pars *mp, long rate, int encoding)
 
void invalidate_format (struct audioformat *af)
 
off_t decoder_synth_bytes (mpg123_handle *fr, off_t s)
 
off_t samples_to_bytes (mpg123_handle *fr, off_t s)
 
off_t bytes_to_samples (mpg123_handle *fr, off_t b)
 
off_t outblock_bytes (mpg123_handle *fr, off_t s)
 
static void chop_fourth_byte (struct outbuffer *buf)
 
static void conv_s32_to_u32 (struct outbuffer *buf)
 
static void conv_s16_to_u16 (struct outbuffer *buf)
 
static void conv_s16_to_f32 (struct outbuffer *buf)
 
static void conv_s16_to_s32 (struct outbuffer *buf)
 
void swap_endian (struct outbuffer *buf, int block)
 
void postprocess_buffer (mpg123_handle *fr)
 

Variables

static const long my_rates [MPG123_RATES]
 
static const int my_encodings [MPG123_ENCODINGS]
 
static const int enc_float_range [2] = { 6, 8 }
 
static const int enc_8bit_range [2] = { 8, 12 }
 
static const int enc_24bit_range [2] = { 2, 6 }
 
static const int enc_16bit_range [2] = { 0, 2}
 
static const int good_encodings []
 
static const charbufsizeerr = "Fatal: Buffer too small for postprocessing!"
 

Macro Definition Documentation

◆ ENCRANGE

#define ENCRANGE (   range)    imax(f0, range[0]), imin(f2, range[1])

◆ MPG123_FLOAT_ENC

#define MPG123_FLOAT_ENC   MPG123_ENC_FLOAT_32

Definition at line 80 of file format.c.

Function Documentation

◆ bytes_to_samples()

off_t bytes_to_samples ( mpg123_handle fr,
off_t  b 
)

Definition at line 570 of file format.c.

571{
572 return b / fr->af.encsize / fr->af.channels;
573}
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
struct audioformat af
Definition: frame.h:268

◆ cap_fit()

static int cap_fit ( mpg123_pars p,
struct audioformat nf,
int  f0,
int  f2 
)
static

Definition at line 158 of file format.c.

159{
160 int i;
161 int c = nf->channels-1;
162 int rn = rate2num(p, nf->rate);
163 if(rn >= 0) for(i=f0;i<f2;i++)
164 {
165 if(p->audio_caps[c][rn][i])
166 {
167 nf->encoding = my_encodings[i];
168 return 1;
169 }
170 }
171 return 0;
172}
const GLubyte * c
Definition: glext.h:8905
GLfloat GLfloat p
Definition: glext.h:8902
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static int rate2num(mpg123_pars *mp, long r)
Definition: format.c:138
static const int my_encodings[MPG123_ENCODINGS]
Definition: format.c:40
#define f2(x, y, z)
Definition: sha1.c:31
int encoding
Definition: frame.h:50
int channels
Definition: frame.h:54
long rate
Definition: frame.h:55

Referenced by enc_chan_fit().

◆ chop_fourth_byte()

static void chop_fourth_byte ( struct outbuffer buf)
static

Definition at line 590 of file format.c.

591{
592 unsigned char *wpos = buf->data;
593 unsigned char *rpos = buf->data;
594 size_t blocks = buf->fill/4;
595 size_t i;
596 for(i=0; i<blocks; ++i,wpos+=3,rpos+=4)
597 DROP4BYTE(wpos, rpos)
598 buf->fill = wpos-buf->data;
599}
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
static int blocks
Definition: mkdosfs.c:527
#define DROP4BYTE(w, r)
Definition: sample.h:191

Referenced by postprocess_buffer().

◆ conv_s16_to_f32()

static void conv_s16_to_f32 ( struct outbuffer buf)
static

Definition at line 635 of file format.c.

636{
637 ssize_t i;
638 int16_t *in = (int16_t*) buf->data;
639 float *out = (float*) buf->data;
640 size_t count = buf->fill/sizeof(int16_t);
641 /* Does that make any sense? In x86, there is an actual instruction to divide
642 float by integer ... but then, if we have that FPU, we don't really need
643 fixed point decoder hacks ...? */
644 float scale = 1./SHORT_SCALE;
645
646 if(buf->size < count*sizeof(float))
647 {
648 error1("%s", bufsizeerr);
649 return;
650 }
651
652 /* Work from the back since output is bigger. */
653 for(i=count-1; i>=0; --i)
654 out[i] = (float)in[i] * scale;
655
656 buf->fill = count*sizeof(float);
657}
INT16 int16_t
Definition: types.h:70
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLenum GLenum GLenum GLenum GLenum scale
Definition: glext.h:9032
GLuint in
Definition: glext.h:9616
static float(__cdecl *square_half_float)(float x
#define SHORT_SCALE
#define int16_t
Definition: nsiface.idl:55
static FILE * out
Definition: regtests2xml.c:44
int ssize_t
Definition: rosdhcp.h:48
#define error1(s, a)
Definition: debug.h:125
static const char * bufsizeerr
Definition: format.c:618

Referenced by postprocess_buffer().

◆ conv_s16_to_s32()

static void conv_s16_to_s32 ( struct outbuffer buf)
static

Definition at line 661 of file format.c.

662{
663 ssize_t i;
664 int16_t *in = (int16_t*) buf->data;
665 int32_t *out = (int32_t*) buf->data;
666 size_t count = buf->fill/sizeof(int16_t);
667
668 if(buf->size < count*sizeof(int32_t))
669 {
670 error1("%s", bufsizeerr);
671 return;
672 }
673
674 /* Work from the back since output is bigger. */
675 for(i=count-1; i>=0; --i)
676 {
677 out[i] = in[i];
678 /* Could just shift bytes, but would have to mess with sign bit. */
679 out[i] *= S32_RESCALE;
680 }
681
682 buf->fill = count*sizeof(int32_t);
683}
INT32 int32_t
Definition: types.h:71
#define S32_RESCALE
#define int32_t
Definition: nsiface.idl:56

Referenced by postprocess_buffer().

◆ conv_s16_to_u16()

static void conv_s16_to_u16 ( struct outbuffer buf)
static

Definition at line 623 of file format.c.

624{
625 size_t i;
626 int16_t *ssamples = (int16_t*) buf->data;
627 uint16_t *usamples = (uint16_t*)buf->data;
628 size_t count = buf->fill/sizeof(int16_t);
629
630 for(i=0; i<count; ++i)
631 usamples[i] = CONV_SU16(ssamples[i]);
632}
unsigned short int uint16_t
Definition: acefiex.h:54
#define CONV_SU16(s)
Definition: sample.h:164

Referenced by postprocess_buffer().

◆ conv_s32_to_u32()

static void conv_s32_to_u32 ( struct outbuffer buf)
static

Definition at line 601 of file format.c.

602{
603 size_t i;
604 int32_t *ssamples = (int32_t*) buf->data;
605 uint32_t *usamples = (uint32_t*) buf->data;
606 size_t count = buf->fill/sizeof(int32_t);
607
608 for(i=0; i<count; ++i)
609 usamples[i] = CONV_SU32(ssamples[i]);
610}
UINT32 uint32_t
Definition: types.h:75
#define CONV_SU32(s)
Definition: sample.h:155

Referenced by postprocess_buffer().

◆ decoder_synth_bytes()

off_t decoder_synth_bytes ( mpg123_handle fr,
off_t  s 
)

Definition at line 558 of file format.c.

559{
560 return s * fr->af.dec_encsize * fr->af.channels;
561}
GLdouble s
Definition: gl.h:2039

◆ enc2num()

static int enc2num ( int  encoding)
static

Definition at line 149 of file format.c.

150{
151 int i;
152 for(i=0;i<MPG123_ENCODINGS;++i)
153 if(my_encodings[i] == encoding) return i;
154
155 return -1;
156}
#define MPG123_ENCODINGS
static char * encoding
Definition: xmllint.c:155

Referenced by mpg123_fmt_support().

◆ enc_chan_fit()

static int enc_chan_fit ( mpg123_pars p,
long  rate,
struct audioformat nnf,
int  f0,
int  f2,
int  try_float 
)
static

Definition at line 188 of file format.c.

190{
191#define ENCRANGE(range) imax(f0, range[0]), imin(f2, range[1])
192 struct audioformat nf = *nnf;
193 nf.rate = rate;
195 goto eend;
197 goto eend;
198 if(try_float &&
200 goto eend;
201 if(cap_fit(p, &nf, ENCRANGE(enc_8bit_range)))
202 goto eend;
203
204 /* try again with different stereoness */
205 if(nf.channels == 2 && !(p->flags & MPG123_FORCE_STEREO)) nf.channels = 1;
206 else if(nf.channels == 1 && !(p->flags & MPG123_FORCE_MONO)) nf.channels = 2;
207
209 goto eend;
211 goto eend;
212 if(try_float &&
214 goto eend;
215 if(cap_fit(p, &nf, ENCRANGE(enc_8bit_range)))
216 goto eend;
217 return FALSE;
218eend:
219 *nnf = nf;
220 return TRUE;
221#undef ENCRANGE
222}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
@ MPG123_FORCE_MONO
Definition: mpg123.h:213
@ MPG123_FORCE_STEREO
Definition: mpg123.h:217
int rate
Definition: pcmconverter.c:97
static const int enc_16bit_range[2]
Definition: format.c:67
static const int enc_24bit_range[2]
Definition: format.c:65
static int cap_fit(mpg123_pars *p, struct audioformat *nf, int f0, int f2)
Definition: format.c:158
#define ENCRANGE(range)
static const int enc_8bit_range[2]
Definition: format.c:63
static const int enc_float_range[2]
Definition: format.c:61

Referenced by frame_output_format().

◆ frame_output_format()

int frame_output_format ( mpg123_handle fr)

Definition at line 226 of file format.c.

227{
228 struct audioformat nf;
229 int f0=0;
230 int f2=MPG123_ENCODINGS+1; // Include all encodings by default.
231 mpg123_pars *p = &fr->p;
232 int try_float = (p->flags & MPG123_FLOAT_FALLBACK) ? 0 : 1;
233 /* initialize new format, encoding comes later */
234 nf.channels = fr->stereo;
235
236 // I intended the forcing stuff to be weaved into the format support table,
237 // but this probably will never happen, as this would change library behaviour.
238 // One could introduce an additional effective format table that takes for
239 // forcings into account, but that would have to be updated on any flag
240 // change. Tedious.
241 if(p->flags & MPG123_FORCE_8BIT)
242 {
243 f0 = enc_8bit_range[0];
244 f2 = enc_8bit_range[1];
245 }
246 if(p->flags & MPG123_FORCE_FLOAT)
247 {
248 try_float = 1;
249 f0 = enc_float_range[0];
250 f2 = enc_float_range[1];
251 }
252
253 /* force stereo is stronger */
254 if(p->flags & MPG123_FORCE_MONO) nf.channels = 1;
255 if(p->flags & MPG123_FORCE_STEREO) nf.channels = 2;
256
257 // Strategy update: Avoid too early triggering of the NtoM decoder.
258 // Main target is the native rate, with any encoding.
259 // Then, native rate with any channel count and any encoding.
260 // Then, it's down_sample from native rate.
261 // As last resort: NtoM rate.
262 // So the priority is 1. rate 2. channels 3. encoding.
263 // As encodings go, 16 bit is tranditionally preferred as efficient choice.
264 // Next in line are wider float and integer encodings, then 8 bit as
265 // last resort.
266
267#ifndef NO_NTOM
268 if(p->force_rate)
269 {
270 if(enc_chan_fit(p, p->force_rate, &nf, f0, f2, try_float))
271 goto end;
272 // Keep the order consistent if float is considered fallback only.
273 if(!try_float &&
274 enc_chan_fit(p, p->force_rate, &nf, f0, f2, TRUE))
275 goto end;
276
277 merror( "Unable to set up output format! Constraints: %s%s%liHz."
278 , ( p->flags & MPG123_FORCE_STEREO ? "stereo, " :
279 (p->flags & MPG123_FORCE_MONO ? "mono, " : "") )
280 , ( p->flags & MPG123_FORCE_FLOAT ? "float, " :
281 (p->flags & MPG123_FORCE_8BIT ? "8bit, " : "") )
282 , p->force_rate );
283/* if(NOQUIET && p->verbose <= 1) print_capabilities(fr); */
284
286 return -1;
287 }
288#endif
289 // Native decoder rate first.
290 if(enc_chan_fit(p, frame_freq(fr)>>p->down_sample, &nf, f0, f2, try_float))
291 goto end;
292 // Then downsamplings.
293 if(p->flags & MPG123_AUTO_RESAMPLE && p->down_sample < 2)
294 {
295 if(enc_chan_fit( p, frame_freq(fr)>>(p->down_sample+1), &nf
296 , f0, f2, try_float ))
297 goto end;
298 if(p->down_sample < 1 && enc_chan_fit( p, frame_freq(fr)>>2, &nf
299 , f0, f2, try_float ))
300 goto end;
301 }
302 // And again the whole deal with float fallback.
303 if(!try_float)
304 {
305 if(enc_chan_fit(p, frame_freq(fr)>>p->down_sample, &nf, f0, f2, TRUE))
306 goto end;
307 // Then downsamplings.
308 if(p->flags & MPG123_AUTO_RESAMPLE && p->down_sample < 2)
309 {
310 if(enc_chan_fit( p, frame_freq(fr)>>(p->down_sample+1), &nf
311 , f0, f2, TRUE ))
312 goto end;
313 if(p->down_sample < 1 && enc_chan_fit( p, frame_freq(fr)>>2, &nf
314 , f0, f2, TRUE ))
315 goto end;
316 }
317 }
318#ifndef NO_NTOM
319 // Try to find any rate that works and resample using NtoM hackery.
320 if( p->flags & MPG123_AUTO_RESAMPLE && fr->p.down_sample == 0)
321 {
322 int i;
323 int rn = rate2num(p, frame_freq(fr));
324 int rrn;
325 if(rn < 0) return 0;
326 /* Try higher rates first. */
327 for(rrn=rn+1; rrn<MPG123_RATES; ++rrn)
328 if(enc_chan_fit(p, my_rates[rrn], &nf, f0, f2, try_float))
329 goto end;
330 /* Then lower rates. */
331 for(i=f0;i<f2;i++) for(rrn=rn-1; rrn>=0; --rrn)
332 if(enc_chan_fit(p, my_rates[rrn], &nf, f0, f2, try_float))
333 goto end;
334 // And again for float fallback.
335 if(!try_float)
336 {
337 /* Try higher rates first. */
338 for(rrn=rn+1; rrn<MPG123_RATES; ++rrn)
339 if(enc_chan_fit(p, my_rates[rrn], &nf, f0, f2, TRUE))
340 goto end;
341 /* Then lower rates. */
342 for(i=f0;i<f2;i++) for(rrn=rn-1; rrn>=0; --rrn)
343 if(enc_chan_fit(p, my_rates[rrn], &nf, f0, f2, TRUE))
344 goto end;
345 }
346 }
347#endif
348
349 /* Here is the _bad_ end. */
350 merror( "Unable to set up output format! Constraints: %s%s%li, %li or %liHz."
351 , ( p->flags & MPG123_FORCE_STEREO ? "stereo, " :
352 (p->flags & MPG123_FORCE_MONO ? "mono, " : "") )
353 , ( p->flags & MPG123_FORCE_FLOAT ? "float, " :
354 (p->flags & MPG123_FORCE_8BIT ? "8bit, " : "") )
355 , frame_freq(fr), frame_freq(fr)>>1, frame_freq(fr)>>2 );
356/* if(NOQUIET && p->verbose <= 1) print_capabilities(fr); */
357
359 return -1;
360
361end: /* Here is the _good_ end. */
362 /* we had a successful match, now see if there's a change */
363 if(nf.rate == fr->af.rate && nf.channels == fr->af.channels && nf.encoding == fr->af.encoding)
364 {
365 debug2("Old format with %i channels, and FORCE_MONO=%li", nf.channels, p->flags & MPG123_FORCE_MONO);
366 return 0; /* the same format as before */
367 }
368 else /* a new format */
369 {
370 debug1("New format with %i channels!", nf.channels);
371 fr->af.rate = nf.rate;
372 fr->af.channels = nf.channels;
373 fr->af.encoding = nf.encoding;
374 /* Cache the size of one sample in bytes, for ease of use. */
375 fr->af.encsize = mpg123_encsize(fr->af.encoding);
376 if(fr->af.encsize < 1)
377 {
378 error1("Some unknown encoding??? (%i)", fr->af.encoding);
379
381 return -1;
382 }
383 /* Set up the decoder synth format. Might differ. */
384#ifdef NO_SYNTH32
385 /* Without high-precision synths, 16 bit signed is the basis for
386 everything higher than 8 bit. */
387 if(fr->af.encsize > 2)
388 fr->af.dec_enc = MPG123_ENC_SIGNED_16;
389 else
390 {
391#endif
392 switch(fr->af.encoding)
393 {
394#ifndef NO_32BIT
398 fr->af.dec_enc = MPG123_ENC_SIGNED_32;
399 break;
400#endif
401#ifndef NO_16BIT
403 fr->af.dec_enc = MPG123_ENC_SIGNED_16;
404 break;
405#endif
406 default:
407 fr->af.dec_enc = fr->af.encoding;
408 }
409#ifdef NO_SYNTH32
410 }
411#endif
412 fr->af.dec_encsize = mpg123_encsize(fr->af.dec_enc);
413 return 1;
414 }
415}
GLuint GLuint end
Definition: gl.h:1545
@ MPG123_ENC_UNSIGNED_32
Definition: fmt123.h:72
@ MPG123_ENC_SIGNED_16
Definition: fmt123.h:58
@ MPG123_ENC_UNSIGNED_24
Definition: fmt123.h:76
@ MPG123_ENC_SIGNED_24
Definition: fmt123.h:74
@ MPG123_ENC_SIGNED_32
Definition: fmt123.h:70
@ MPG123_ENC_UNSIGNED_16
Definition: fmt123.h:60
@ MPG123_BAD_OUTFORMAT
Definition: mpg123.h:384
@ MPG123_FORCE_FLOAT
Definition: mpg123.h:224
@ MPG123_FORCE_8BIT
Definition: mpg123.h:218
@ MPG123_AUTO_RESAMPLE
Definition: mpg123.h:229
@ MPG123_FLOAT_FALLBACK
Definition: mpg123.h:253
int attribute_align_arg mpg123_encsize(int encoding)
Definition: format.c:131
#define frame_freq
Definition: intsym.h:239
#define MPG123_RATES
#define debug1(s, a)
Definition: debug.h:61
#define debug2(s, a, b)
Definition: debug.h:62
#define merror(s,...)
Definition: debug.h:122
static int enc_chan_fit(mpg123_pars *p, long rate, struct audioformat *nnf, int f0, int f2, int try_float)
Definition: format.c:188
static const long my_rates[MPG123_RATES]
Definition: format.c:33
struct mpg123_pars_struct p
Definition: frame.h:289

◆ good_enc()

static int good_enc ( const int  enc)
static

Definition at line 109 of file format.c.

110{
111 size_t i;
112 for(i=0; i<sizeof(good_encodings)/sizeof(int); ++i)
113 if(enc == good_encodings[i]) return TRUE;
114
115 return FALSE;
116}
static const int good_encodings[]
Definition: format.c:84

Referenced by mpg123_fmt2(), and mpg123_fmt_all().

◆ imax()

static int imax ( int  a,
int  b 
)
static

Definition at line 179 of file format.c.

180{
181 return a > b ? a : b;
182}
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
#define a
Definition: ke_i.h:78
#define b
Definition: ke_i.h:79

Referenced by pwlarc_intersect().

◆ imin()

static int imin ( int  a,
int  b 
)
static

Definition at line 174 of file format.c.

175{
176 return a < b ? a : b;
177}

Referenced by Pos_InitPage(), and pwlarc_intersect().

◆ invalidate_format()

void invalidate_format ( struct audioformat af)

Definition at line 550 of file format.c.

551{
552 af->encoding = 0;
553 af->rate = 0;
554 af->channels = 0;
555}

◆ outblock_bytes()

off_t outblock_bytes ( mpg123_handle fr,
off_t  s 
)

Definition at line 576 of file format.c.

577{
578 int encsize = (fr->af.encoding & MPG123_ENC_24)
579 ? 4 /* Intermediate 32 bit. */
580 : (fr->af.encsize > fr->af.dec_encsize
581 ? fr->af.encsize
582 : fr->af.dec_encsize);
583 return s * encsize * fr->af.channels;
584}
@ MPG123_ENC_24
Definition: fmt123.h:50

◆ postprocess_buffer()

void postprocess_buffer ( mpg123_handle fr)

Definition at line 700 of file format.c.

701{
702 /*
703 This caters for the final output formats that are never produced by
704 decoder synth directly (wide unsigned and 24 bit formats) or that are
705 missing because of limited decoder precision (16 bit synth but 32 or
706 24 bit output).
707 */
708 switch(fr->af.dec_enc)
709 {
710#ifndef NO_32BIT
712 switch(fr->af.encoding)
713 {
716 break;
720 break;
723 break;
724 }
725 break;
726#endif
727#ifndef NO_16BIT
729 switch(fr->af.encoding)
730 {
733 break;
734#ifndef NO_REAL
737 break;
738#endif
739#ifndef NO_32BIT
742 break;
746 break;
751 break;
755 break;
756#endif
757 }
758 break;
759#endif
760 }
761 if(fr->p.flags & MPG123_FORCE_ENDIAN)
762 {
763 if(
764#ifdef WORDS_BIGENDIAN
765 !(
766#endif
767 fr->p.flags & MPG123_BIG_ENDIAN
768#ifdef WORDS_BIGENDIAN
769 )
770#endif
771 )
772 swap_endian(&fr->buffer, mpg123_encsize(fr->af.encoding));
773 }
774}
@ MPG123_ENC_FLOAT_32
Definition: fmt123.h:78
@ MPG123_BIG_ENDIAN
Definition: mpg123.h:245
@ MPG123_FORCE_ENDIAN
Definition: mpg123.h:239
void swap_endian(struct outbuffer *buf, int block)
Definition: format.c:689
static void conv_s16_to_s32(struct outbuffer *buf)
Definition: format.c:661
static void conv_s32_to_u32(struct outbuffer *buf)
Definition: format.c:601
static void conv_s16_to_u16(struct outbuffer *buf)
Definition: format.c:623
static void chop_fourth_byte(struct outbuffer *buf)
Definition: format.c:590
static void conv_s16_to_f32(struct outbuffer *buf)
Definition: format.c:635
struct outbuffer buffer
Definition: frame.h:267

◆ rate2num()

static int rate2num ( mpg123_pars mp,
long  r 
)
static

Definition at line 138 of file format.c.

139{
140 int i;
141 for(i=0;i<MPG123_RATES;i++) if(my_rates[i] == r) return i;
142#ifndef NO_NTOM
143 if(mp && mp->force_rate != 0 && mp->force_rate == r) return MPG123_RATES;
144#endif
145
146 return -1;
147}
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
long force_rate
Definition: frame.h:65

Referenced by cap_fit(), frame_output_format(), mpg123_fmt2(), and mpg123_fmt_support().

◆ samples_to_bytes()

off_t samples_to_bytes ( mpg123_handle fr,
off_t  s 
)

Definition at line 565 of file format.c.

566{
567 return s * fr->af.encsize * fr->af.channels;
568}

◆ swap_endian()

void swap_endian ( struct outbuffer buf,
int  block 
)

Definition at line 689 of file format.c.

690{
691 size_t count;
692
693 if(block >= 2)
694 {
695 count = buf->fill/(unsigned int)block;
696 swap_bytes(buf->data, (size_t)block, count);
697 }
698}
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
static void swap_bytes(void *buf, size_t samplesize, size_t samplecount)
static unsigned int block
Definition: xmlmemory.c:101

Referenced by postprocess_buffer().

Variable Documentation

◆ bufsizeerr

const char* bufsizeerr = "Fatal: Buffer too small for postprocessing!"
static

Definition at line 618 of file format.c.

Referenced by conv_s16_to_f32(), and conv_s16_to_s32().

◆ enc_16bit_range

const int enc_16bit_range[2] = { 0, 2}
static

Definition at line 67 of file format.c.

Referenced by enc_chan_fit().

◆ enc_24bit_range

const int enc_24bit_range[2] = { 2, 6 }
static

Definition at line 65 of file format.c.

Referenced by enc_chan_fit().

◆ enc_8bit_range

const int enc_8bit_range[2] = { 8, 12 }
static

Definition at line 63 of file format.c.

Referenced by enc_chan_fit(), and frame_output_format().

◆ enc_float_range

const int enc_float_range[2] = { 6, 8 }
static

Definition at line 61 of file format.c.

Referenced by enc_chan_fit(), and frame_output_format().

◆ good_encodings

const int good_encodings[]
static

◆ my_encodings

◆ my_rates

const long my_rates[MPG123_RATES]
static
Initial value:
=
{
8000, 11025, 12000,
16000, 22050, 24000,
32000, 44100, 48000,
}

Definition at line 33 of file format.c.

Referenced by frame_output_format(), mpg123_rates(), and rate2num().