annotate decoders/libmpg123/frame.c @ 583:fbb3f1abdd9e

Automated merge with http://hg.assembla.com/SDL_sound_CoreAudio
author Ryan C. Gordon <icculus@icculus.org>
date Tue, 09 Nov 2010 12:11:56 -0500
parents 7e08477b0fc1
children
rev   line source
562
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1 /*
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2 frame: Heap of routines dealing with the core mpg123 data structure.
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
3
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
4 copyright 2008 by the mpg123 project - free software under the terms of the LGPL 2.1
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
5 see COPYING and AUTHORS files in distribution or http://mpg123.org
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
6 initially written by Thomas Orgis
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
7 */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
8
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
9 #include "mpg123lib_intern.h"
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
10 #include "getcpuflags.h"
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
11 #include "debug.h"
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
12
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
13 #define IGNORESHIFT 2
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
14
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
15 static void frame_fixed_reset(mpg123_handle *fr);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
16
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
17 /* that's doubled in decode_ntom.c */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
18 #define NTOM_MUL (32768)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
19 #define aligned_pointer(p,type,alignment) \
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
20 (((char*)(p)-(char*)NULL) % (alignment)) \
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
21 ? (type*)((char*)(p) + (alignment) - (((char*)(p)-(char*)NULL) % (alignment))) \
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
22 : (type*)(p)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
23 void frame_default_pars(mpg123_pars *mp)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
24 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
25 mp->outscale = MAXOUTBURST;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
26 #ifdef GAPLESS
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
27 mp->flags = MPG123_GAPLESS;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
28 #else
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
29 mp->flags = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
30 #endif
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
31 mp->force_rate = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
32 mp->down_sample = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
33 mp->rva = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
34 mp->halfspeed = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
35 mp->doublespeed = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
36 mp->verbose = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
37 mp->icy_interval = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
38 #ifndef WIN32
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
39 mp->timeout = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
40 #endif
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
41 mp->resync_limit = 1024;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
42 #ifdef FRAME_INDEX
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
43 mp->index_size = INDEX_SIZE;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
44 #endif
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
45 mpg123_fmt_all(mp);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
46 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
47
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
48 void frame_init(mpg123_handle *fr)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
49 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
50 frame_init_par(fr, NULL);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
51 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
52
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
53 void frame_init_par(mpg123_handle *fr, mpg123_pars *mp)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
54 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
55 fr->own_buffer = FALSE;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
56 fr->buffer.data = NULL;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
57 fr->rawbuffs = NULL;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
58 fr->rawdecwin = NULL;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
59 fr->conv16to8_buf = NULL;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
60 fr->xing_toc = NULL;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
61 fr->cpu_opts.type = defopt;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
62 fr->cpu_opts.class = (defopt == mmx || defopt == sse || defopt == dreidnowext) ? mmxsse : normal;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
63 /* these two look unnecessary, check guarantee for synth_ntom_set_step (in control_generic, even)! */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
64 fr->ntom_val[0] = NTOM_MUL>>1;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
65 fr->ntom_val[1] = NTOM_MUL>>1;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
66 fr->ntom_step = NTOM_MUL;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
67 /* unnecessary: fr->buffer.size = fr->buffer.fill = 0; */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
68 mpg123_reset_eq(fr);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
69 init_icy(&fr->icy);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
70 init_id3(fr);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
71 /* frame_outbuffer is missing... */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
72 /* frame_buffers is missing... that one needs cpu opt setting! */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
73 /* after these... frame_reset is needed before starting full decode */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
74 invalidate_format(&fr->af);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
75 fr->rdat.r_read = NULL;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
76 fr->rdat.r_lseek = NULL;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
77 fr->decoder_change = 1;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
78 fr->err = MPG123_OK;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
79 if(mp == NULL) frame_default_pars(&fr->p);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
80 else memcpy(&fr->p, mp, sizeof(struct mpg123_pars_struct));
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
81
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
82 fr->down_sample = 0; /* Initialize to silence harmless errors when debugging. */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
83 frame_fixed_reset(fr); /* Reset only the fixed data, dynamic buffers are not there yet! */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
84 #ifdef FRAME_INDEX
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
85 fi_init(&fr->index);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
86 frame_index_setup(fr); /* Apply the size setting. */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
87 #endif
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
88 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
89
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
90 mpg123_pars attribute_align_arg *mpg123_new_pars(int *error)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
91 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
92 mpg123_pars *mp = malloc(sizeof(struct mpg123_pars_struct));
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
93 if(mp != NULL){ frame_default_pars(mp); if(error != NULL) *error = MPG123_OK; }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
94 else if(error != NULL) *error = MPG123_OUT_OF_MEM;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
95 return mp;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
96 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
97
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
98 void attribute_align_arg mpg123_delete_pars(mpg123_pars* mp)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
99 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
100 if(mp != NULL) free(mp);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
101 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
102
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
103 int attribute_align_arg mpg123_reset_eq(mpg123_handle *mh)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
104 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
105 int i;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
106 mh->have_eq_settings = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
107 for(i=0; i < 32; ++i) mh->equalizer[0][i] = mh->equalizer[1][i] = DOUBLE_TO_REAL(1.0);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
108
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
109 return MPG123_OK;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
110 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
111
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
112 int frame_outbuffer(mpg123_handle *fr)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
113 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
114 size_t size = mpg123_safe_buffer()*AUDIOBUFSIZE;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
115 if(!fr->own_buffer) fr->buffer.data = NULL;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
116 if(fr->buffer.data != NULL && fr->buffer.size != size)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
117 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
118 free(fr->buffer.data);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
119 fr->buffer.data = NULL;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
120 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
121 fr->buffer.size = size;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
122 if(fr->buffer.data == NULL) fr->buffer.data = (unsigned char*) malloc(fr->buffer.size);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
123 if(fr->buffer.data == NULL)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
124 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
125 fr->err = MPG123_OUT_OF_MEM;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
126 return -1;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
127 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
128 fr->own_buffer = TRUE;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
129 fr->buffer.fill = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
130 return 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
131 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
132
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
133 int attribute_align_arg mpg123_replace_buffer(mpg123_handle *mh, unsigned char *data, size_t size)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
134 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
135 if(data == NULL || size < mpg123_safe_buffer())
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
136 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
137 mh->err = MPG123_BAD_BUFFER;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
138 return MPG123_ERR;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
139 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
140 if(mh->own_buffer && mh->buffer.data != NULL) free(mh->buffer.data);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
141 mh->own_buffer = FALSE;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
142 mh->buffer.data = data;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
143 mh->buffer.size = size;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
144 mh->buffer.fill = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
145 return MPG123_OK;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
146 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
147
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
148 #ifdef FRAME_INDEX
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
149 int frame_index_setup(mpg123_handle *fr)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
150 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
151 int ret = MPG123_ERR;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
152 if(fr->p.index_size >= 0)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
153 { /* Simple fixed index. */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
154 fr->index.grow_size = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
155 debug1("resizing index to %li", fr->p.index_size);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
156 ret = fi_resize(&fr->index, (size_t)fr->p.index_size);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
157 debug2("index resized... %lu at %p", (unsigned long)fr->index.size, (void*)fr->index.data);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
158 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
159 else
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
160 { /* A growing index. We give it a start, though. */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
161 fr->index.grow_size = (size_t)(- fr->p.index_size);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
162 if(fr->index.size < fr->index.grow_size)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
163 ret = fi_resize(&fr->index, fr->index.grow_size);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
164 else
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
165 ret = MPG123_OK; /* We have minimal size already... and since growing is OK... */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
166 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
167 debug2("set up frame index of size %lu (ret=%i)", (unsigned long)fr->index.size, ret);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
168
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
169 return ret;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
170 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
171 #endif
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
172
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
173 int frame_buffers(mpg123_handle *fr)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
174 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
175 int buffssize = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
176 debug1("frame %p buffer", (void*)fr);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
177 /*
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
178 the used-to-be-static buffer of the synth functions, has some subtly different types/sizes
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
179
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
180 2to1, 4to1, ntom, generic, i386: real[2][2][0x110]
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
181 mmx, sse: short[2][2][0x110]
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
182 i586(_dither): 4352 bytes; int/long[2][2][0x110]
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
183 i486: int[2][2][17*FIR_BUFFER_SIZE]
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
184 altivec: static real __attribute__ ((aligned (16))) buffs[4][4][0x110]
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
185
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
186 Huh, altivec looks like fun. Well, let it be large... then, the 16 byte alignment seems to be implicit on MacOSX malloc anyway.
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
187 Let's make a reasonable attempt to allocate enough memory...
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
188 Keep in mind: biggest ones are i486 and altivec (mutually exclusive!), then follows i586 and normal real.
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
189 mmx/sse use short but also real for resampling.
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
190 Thus, minimum is 2*2*0x110*sizeof(real).
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
191 */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
192 if(fr->cpu_opts.type == altivec) buffssize = 4*4*0x110*sizeof(real);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
193 #ifdef OPT_I486
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
194 else if(fr->cpu_opts.type == ivier) buffssize = 2*2*17*FIR_BUFFER_SIZE*sizeof(int);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
195 #endif
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
196 else if(fr->cpu_opts.type == ifuenf || fr->cpu_opts.type == ifuenf_dither || fr->cpu_opts.type == dreidnow)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
197 buffssize = 2*2*0x110*4; /* don't rely on type real, we need 4352 bytes */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
198
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
199 if(2*2*0x110*sizeof(real) > buffssize)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
200 buffssize = 2*2*0x110*sizeof(real);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
201 buffssize += 15; /* For 16-byte alignment (SSE likes that). */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
202
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
203 if(fr->rawbuffs != NULL && fr->rawbuffss != buffssize)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
204 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
205 free(fr->rawbuffs);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
206 fr->rawbuffs = NULL;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
207 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
208
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
209 if(fr->rawbuffs == NULL) fr->rawbuffs = (unsigned char*) malloc(buffssize);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
210 if(fr->rawbuffs == NULL) return -1;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
211 fr->rawbuffss = buffssize;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
212 fr->short_buffs[0][0] = aligned_pointer(fr->rawbuffs,short,16);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
213 fr->short_buffs[0][1] = fr->short_buffs[0][0] + 0x110;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
214 fr->short_buffs[1][0] = fr->short_buffs[0][1] + 0x110;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
215 fr->short_buffs[1][1] = fr->short_buffs[1][0] + 0x110;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
216 fr->real_buffs[0][0] = aligned_pointer(fr->rawbuffs,real,16);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
217 fr->real_buffs[0][1] = fr->real_buffs[0][0] + 0x110;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
218 fr->real_buffs[1][0] = fr->real_buffs[0][1] + 0x110;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
219 fr->real_buffs[1][1] = fr->real_buffs[1][0] + 0x110;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
220 #ifdef OPT_I486
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
221 if(fr->cpu_opts.type == ivier)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
222 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
223 fr->int_buffs[0][0] = (int*) fr->rawbuffs;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
224 fr->int_buffs[0][1] = fr->int_buffs[0][0] + 17*FIR_BUFFER_SIZE;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
225 fr->int_buffs[1][0] = fr->int_buffs[0][1] + 17*FIR_BUFFER_SIZE;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
226 fr->int_buffs[1][1] = fr->int_buffs[1][0] + 17*FIR_BUFFER_SIZE;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
227 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
228 #endif
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
229 #ifdef OPT_ALTIVEC
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
230 if(fr->cpu_opts.type == altivec)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
231 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
232 int i,j;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
233 fr->areal_buffs[0][0] = (real*) fr->rawbuffs;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
234 for(i=0; i<4; ++i) for(j=0; j<4; ++j)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
235 fr->areal_buffs[i][j] = fr->areal_buffs[0][0] + (i*4+j)*0x110;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
236 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
237 #endif
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
238 /* now the different decwins... all of the same size, actually */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
239 /* The MMX ones want 32byte alignment, which I'll try to ensure manually */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
240 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
241 int decwin_size = (512+32)*sizeof(real);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
242 if(fr->rawdecwin != NULL) free(fr->rawdecwin);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
243 #ifdef OPT_MMXORSSE
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
244 #ifdef OPT_MULTI
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
245 if(fr->cpu_opts.class == mmxsse)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
246 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
247 #endif
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
248 /* decwin_mmx will share, decwins will be appended ... sizeof(float)==4 */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
249 if(decwin_size < (512+32)*4) decwin_size = (512+32)*4;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
250 decwin_size += (512+32)*4 + 31; /* the second window + alignment zone */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
251 /* (512+32)*4/32 == 2176/32 == 68, so one decwin block retains alignment */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
252 #ifdef OPT_MULTI
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
253 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
254 #endif
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
255 #endif
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
256 fr->rawdecwin = (unsigned char*) malloc(decwin_size);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
257 if(fr->rawdecwin == NULL) return -1;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
258 fr->decwin = (real*) fr->rawdecwin;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
259 #ifdef OPT_MMXORSSE
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
260 #ifdef OPT_MULTI
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
261 if(fr->cpu_opts.class == mmxsse)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
262 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
263 #endif
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
264 /* align decwin, assign that to decwin_mmx, append decwins */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
265 /* I need to add to decwin what is missing to the next full 32 byte -- also I want to make gcc -pedantic happy... */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
266 fr->decwin = aligned_pointer(fr->rawdecwin,real,32);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
267 debug1("aligned decwin: %p", (void*)fr->decwin);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
268 fr->decwin_mmx = (float*)fr->decwin;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
269 fr->decwins = fr->decwin_mmx+512+32;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
270 #ifdef OPT_MULTI
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
271 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
272 else debug("no decwins/decwin_mmx for that class");
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
273 #endif
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
274 #endif
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
275 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
276 frame_buffers_reset(fr);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
277 debug1("frame %p buffer done", (void*)fr);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
278 return 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
279 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
280
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
281 int frame_buffers_reset(mpg123_handle *fr)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
282 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
283 fr->buffer.fill = 0; /* hm, reset buffer fill... did we do a flush? */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
284 fr->bsnum = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
285 /* Wondering: could it be actually _wanted_ to retain buffer contents over different files? (special gapless / cut stuff) */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
286 fr->bsbuf = fr->bsspace[1];
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
287 fr->bsbufold = fr->bsbuf;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
288 fr->bitreservoir = 0; /* Not entirely sure if this is the right place for that counter. */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
289 memset(fr->bsspace, 0, 2*(MAXFRAMESIZE+512));
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
290 memset(fr->ssave, 0, 34);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
291 memset(fr->rawbuffs, 0, fr->rawbuffss);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
292 fr->hybrid_blc[0] = fr->hybrid_blc[1] = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
293 memset(fr->hybrid_block, 0, sizeof(real)*2*2*SBLIMIT*SSLIMIT);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
294 /* Not totally, but quite, sure that decwin(s) doesn't need cleaning. */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
295 return 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
296 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
297
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
298 void frame_icy_reset(mpg123_handle* fr)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
299 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
300 if(fr->icy.data != NULL) free(fr->icy.data);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
301 fr->icy.data = NULL;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
302 fr->icy.interval = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
303 fr->icy.next = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
304 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
305
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
306 void frame_free_toc(mpg123_handle *fr)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
307 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
308 if(fr->xing_toc != NULL){ free(fr->xing_toc); fr->xing_toc = NULL; }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
309 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
310
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
311 /* Just copy the Xing TOC over... */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
312 int frame_fill_toc(mpg123_handle *fr, unsigned char* in)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
313 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
314 if(fr->xing_toc == NULL) fr->xing_toc = malloc(100);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
315 if(fr->xing_toc != NULL)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
316 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
317 memcpy(fr->xing_toc, in, 100);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
318 #ifdef DEBUG
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
319 debug("Got a TOC! Showing the values...");
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
320 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
321 int i;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
322 for(i=0; i<100; ++i)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
323 debug2("entry %i = %i", i, fr->xing_toc[i]);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
324 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
325 #endif
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
326 return TRUE;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
327 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
328 return FALSE;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
329 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
330
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
331 /* Prepare the handle for a new track.
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
332 Reset variables, buffers... */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
333 int frame_reset(mpg123_handle* fr)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
334 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
335 frame_buffers_reset(fr);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
336 frame_fixed_reset(fr);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
337 frame_free_toc(fr);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
338 #ifdef FRAME_INDEX
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
339 fi_reset(&fr->index);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
340 #endif
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
341
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
342 return 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
343 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
344
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
345 /* Reset everythign except dynamic memory. */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
346 static void frame_fixed_reset(mpg123_handle *fr)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
347 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
348 frame_icy_reset(fr);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
349 open_bad(fr);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
350 fr->to_decode = FALSE;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
351 fr->to_ignore = FALSE;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
352 fr->metaflags = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
353 fr->outblock = mpg123_safe_buffer();
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
354 fr->num = -1;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
355 fr->accurate = TRUE;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
356 fr->silent_resync = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
357 fr->audio_start = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
358 fr->clip = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
359 fr->oldhead = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
360 fr->firsthead = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
361 fr->vbr = MPG123_CBR;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
362 fr->abr_rate = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
363 fr->track_frames = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
364 fr->track_samples = -1;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
365 fr->framesize=0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
366 fr->mean_frames = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
367 fr->mean_framesize = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
368 fr->freesize = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
369 fr->lastscale = -1;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
370 fr->rva.level[0] = -1;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
371 fr->rva.level[1] = -1;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
372 fr->rva.gain[0] = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
373 fr->rva.gain[1] = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
374 fr->rva.peak[0] = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
375 fr->rva.peak[1] = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
376 fr->fsizeold = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
377 fr->firstframe = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
378 fr->ignoreframe = fr->firstframe-IGNORESHIFT;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
379 fr->lastframe = -1;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
380 fr->fresh = 1;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
381 fr->new_format = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
382 #ifdef GAPLESS
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
383 frame_gapless_init(fr,0,0);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
384 fr->lastoff = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
385 fr->firstoff = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
386 #endif
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
387 fr->bo[0] = 1; /* the usual bo */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
388 fr->bo[1] = 0; /* ditherindex */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
389 #ifdef OPT_I486
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
390 fr->bo[0] = fr->bo[1] = FIR_SIZE-1;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
391 #endif
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
392 reset_id3(fr);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
393 reset_icy(&fr->icy);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
394 /* ICY stuff should go into icy.c, eh? */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
395 fr->icy.interval = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
396 fr->icy.next = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
397 fr->halfphase = 0; /* here or indeed only on first-time init? */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
398 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
399
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
400 void frame_free_buffers(mpg123_handle *fr)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
401 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
402 if(fr->rawbuffs != NULL) free(fr->rawbuffs);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
403 fr->rawbuffs = NULL;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
404 if(fr->rawdecwin != NULL) free(fr->rawdecwin);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
405 fr->rawdecwin = NULL;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
406 if(fr->conv16to8_buf != NULL) free(fr->conv16to8_buf);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
407 fr->conv16to8_buf = NULL;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
408 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
409
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
410 void frame_exit(mpg123_handle *fr)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
411 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
412 if(fr->own_buffer && fr->buffer.data != NULL)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
413 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
414 debug1("freeing buffer at %p", (void*)fr->buffer.data);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
415 free(fr->buffer.data);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
416 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
417 fr->buffer.data = NULL;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
418 frame_free_buffers(fr);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
419 frame_free_toc(fr);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
420 #ifdef FRAME_INDEX
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
421 fi_exit(&fr->index);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
422 #endif
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
423 exit_id3(fr);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
424 clear_icy(&fr->icy);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
425 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
426
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
427 int attribute_align_arg mpg123_info(mpg123_handle *mh, struct mpg123_frameinfo *mi)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
428 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
429 if(mh == NULL) return MPG123_ERR;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
430 if(mi == NULL)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
431 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
432 mh->err = MPG123_ERR_NULL;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
433 return MPG123_ERR;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
434 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
435 mi->version = mh->mpeg25 ? MPG123_2_5 : (mh->lsf ? MPG123_2_0 : MPG123_1_0);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
436 mi->layer = mh->lay;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
437 mi->rate = frame_freq(mh);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
438 switch(mh->mode)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
439 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
440 case 0: mi->mode = MPG123_M_STEREO; break;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
441 case 1: mi->mode = MPG123_M_JOINT; break;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
442 case 2: mi->mode = MPG123_M_DUAL; break;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
443 case 3: mi->mode = MPG123_M_MONO; break;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
444 default: error("That mode cannot be!");
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
445 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
446 mi->mode_ext = mh->mode_ext;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
447 mi->framesize = mh->framesize+4; /* Include header. */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
448 mi->flags = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
449 if(mh->error_protection) mi->flags |= MPG123_CRC;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
450 if(mh->copyright) mi->flags |= MPG123_COPYRIGHT;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
451 if(mh->extension) mi->flags |= MPG123_PRIVATE;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
452 if(mh->original) mi->flags |= MPG123_ORIGINAL;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
453 mi->emphasis = mh->emphasis;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
454 mi->bitrate = frame_bitrate(mh);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
455 mi->abr_rate = mh->abr_rate;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
456 mi->vbr = mh->vbr;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
457 return MPG123_OK;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
458 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
459
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
460
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
461 /*
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
462 Fuzzy frame offset searching (guessing).
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
463 When we don't have an accurate position, we may use an inaccurate one.
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
464 Possibilities:
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
465 - use approximate positions from Xing TOC (not yet parsed)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
466 - guess wildly from mean framesize and offset of first frame / beginning of file.
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
467 */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
468
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
469 off_t frame_fuzzy_find(mpg123_handle *fr, off_t want_frame, off_t* get_frame)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
470 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
471 /* Default is to go to the beginning. */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
472 off_t ret = fr->audio_start;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
473 *get_frame = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
474
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
475 /* But we try to find something better. */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
476 /* Xing VBR TOC works with relative positions, both in terms of audio frames and stream bytes.
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
477 Thus, it only works when whe know the length of things.
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
478 Oh... I assume the offsets are relative to the _total_ file length. */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
479 if(fr->xing_toc != NULL && fr->track_frames > 0 && fr->rdat.filelen > 0)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
480 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
481 /* One could round... */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
482 int toc_entry = (int) ((double)want_frame*100./fr->track_frames);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
483 /* It is an index in the 100-entry table. */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
484 if(toc_entry < 0) toc_entry = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
485 if(toc_entry > 99) toc_entry = 99;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
486
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
487 /* Now estimate back what frame we get. */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
488 *get_frame = (off_t) ((double)toc_entry/100. * fr->track_frames);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
489 fr->accurate = FALSE;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
490 fr->silent_resync = 1;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
491 /* Question: Is the TOC for whole file size (with/without ID3) or the "real" audio data only?
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
492 ID3v1 info could also matter. */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
493 ret = (off_t) ((double)fr->xing_toc[toc_entry]/256.* fr->rdat.filelen);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
494 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
495 else if(fr->mean_framesize > 0)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
496 { /* Just guess with mean framesize (may be exact with CBR files). */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
497 /* Query filelen here or not? */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
498 fr->accurate = FALSE; /* Fuzzy! */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
499 fr->silent_resync = 1;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
500 *get_frame = want_frame;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
501 ret = fr->audio_start+fr->mean_framesize*want_frame;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
502 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
503 debug5("fuzzy: want %li of %li, get %li at %li B of %li B",
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
504 (long)want_frame, (long)fr->track_frames, (long)*get_frame, (long)ret, (long)(fr->rdat.filelen-fr->audio_start));
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
505 return ret;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
506 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
507
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
508 /*
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
509 find the best frame in index just before the wanted one, seek to there
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
510 then step to just before wanted one with read_frame
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
511 do not care tabout the stuff that was in buffer but not played back
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
512 everything that left the decoder is counted as played
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
513
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
514 Decide if you want low latency reaction and accurate timing info or stable long-time playback with buffer!
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
515 */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
516
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
517 off_t frame_index_find(mpg123_handle *fr, off_t want_frame, off_t* get_frame)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
518 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
519 /* default is file start if no index position */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
520 off_t gopos = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
521 *get_frame = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
522 #ifdef FRAME_INDEX
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
523 /* Possibly use VBRI index, too? I'd need an example for this... */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
524 if(fr->index.fill)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
525 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
526 /* find in index */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
527 size_t fi;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
528 /* at index fi there is frame step*fi... */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
529 fi = want_frame/fr->index.step;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
530 if(fi >= fr->index.fill) /* If we are beyond the end of frame index...*/
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
531 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
532 /* When fuzzy seek is allowed, we have some limited tolerance for the frames we want to read rather then jump over. */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
533 if(fr->p.flags & MPG123_FUZZY && want_frame - (fr->index.fill-1)*fr->index.step > 10)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
534 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
535 gopos = frame_fuzzy_find(fr, want_frame, get_frame);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
536 if(gopos > fr->audio_start) return gopos; /* Only in that case, we have a useful guess. */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
537 /* Else... just continue, fuzzyness didn't help. */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
538 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
539 /* Use the last available position, slowly advancing from that one. */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
540 fi = fr->index.fill - 1;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
541 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
542 /* We have index position, that yields frame and byte offsets. */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
543 *get_frame = fi*fr->index.step;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
544 gopos = fr->index.data[fi];
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
545 fr->accurate = TRUE; /* When using the frame index, we are accurate. */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
546 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
547 else
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
548 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
549 #endif
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
550 if(fr->p.flags & MPG123_FUZZY)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
551 return frame_fuzzy_find(fr, want_frame, get_frame);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
552 /* A bit hackish here... but we need to be fresh when looking for the first header again. */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
553 fr->firsthead = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
554 fr->oldhead = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
555 #ifdef FRAME_INDEX
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
556 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
557 #endif
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
558 debug2("index: 0x%lx for frame %li", (unsigned long)gopos, (long) *get_frame);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
559 return gopos;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
560 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
561
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
562 off_t frame_ins2outs(mpg123_handle *fr, off_t ins)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
563 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
564 off_t outs = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
565 switch(fr->down_sample)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
566 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
567 case 0:
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
568 case 1:
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
569 case 2: outs = ins>>fr->down_sample; break;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
570 case 3: outs = ntom_ins2outs(fr, ins); break;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
571 default: error1("Bad down_sample (%i) ... should not be possible!!", fr->down_sample);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
572 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
573 return outs;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
574 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
575
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
576 off_t frame_outs(mpg123_handle *fr, off_t num)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
577 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
578 off_t outs = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
579 switch(fr->down_sample)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
580 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
581 case 0:
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
582 case 1:
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
583 case 2: outs = (spf(fr)>>fr->down_sample)*num; break;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
584 case 3: outs = ntom_frmouts(fr, num); break;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
585 default: error1("Bad down_sample (%i) ... should not be possible!!", fr->down_sample);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
586 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
587 return outs;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
588 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
589
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
590 off_t frame_offset(mpg123_handle *fr, off_t outs)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
591 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
592 off_t num = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
593 switch(fr->down_sample)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
594 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
595 case 0:
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
596 case 1:
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
597 case 2: num = outs/(spf(fr)>>fr->down_sample); break;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
598 case 3: num = ntom_frameoff(fr, outs); break;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
599 default: error("Bad down_sample ... should not be possible!!");
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
600 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
601 return num;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
602 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
603
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
604 #ifdef GAPLESS
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
605 /* input in _input_ samples */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
606 void frame_gapless_init(mpg123_handle *fr, off_t b, off_t e)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
607 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
608 fr->begin_s = b;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
609 fr->end_s = e;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
610 /* These will get proper values later, from above plus resampling info. */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
611 fr->begin_os = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
612 fr->end_os = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
613 debug2("frame_gapless_init: from %lu to %lu samples", (long unsigned)fr->begin_s, (long unsigned)fr->end_s);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
614 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
615
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
616 void frame_gapless_realinit(mpg123_handle *fr)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
617 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
618 fr->begin_os = frame_ins2outs(fr, fr->begin_s);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
619 fr->end_os = frame_ins2outs(fr, fr->end_s);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
620 debug2("frame_gapless_realinit: from %lu to %lu samples", (long unsigned)fr->begin_os, (long unsigned)fr->end_os);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
621 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
622 #endif
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
623
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
624 /* The frame seek... This is not simply the seek to fe*spf(fr) samples in output because we think of _input_ frames here.
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
625 Seek to frame offset 1 may be just seek to 200 samples offset in output since the beginning of first frame is delay/padding.
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
626 Hm, is that right? OK for the padding stuff, but actually, should the decoder delay be better totally hidden or not?
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
627 With gapless, even the whole frame position could be advanced further than requested (since Homey don't play dat). */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
628 void frame_set_frameseek(mpg123_handle *fr, off_t fe)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
629 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
630 fr->firstframe = fe;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
631 #ifdef GAPLESS
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
632 if(fr->p.flags & MPG123_GAPLESS)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
633 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
634 /* Take care of the beginning... */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
635 off_t beg_f = frame_offset(fr, fr->begin_os);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
636 if(fe <= beg_f)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
637 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
638 fr->firstframe = beg_f;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
639 fr->firstoff = fr->begin_os - frame_outs(fr, beg_f);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
640 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
641 else fr->firstoff = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
642 /* The end is set once for a track at least, on the frame_set_frameseek called in get_next_frame() */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
643 if(fr->end_os > 0)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
644 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
645 fr->lastframe = frame_offset(fr,fr->end_os);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
646 fr->lastoff = fr->end_os - frame_outs(fr, fr->lastframe);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
647 } else fr->lastoff = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
648 } else { fr->firstoff = fr->lastoff = 0; fr->lastframe = -1; }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
649 #endif
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
650 fr->ignoreframe = fr->lay == 3 ? fr->firstframe-IGNORESHIFT : fr->firstframe;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
651 #ifdef GAPLESS
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
652 debug5("frame_set_frameseek: begin at %li frames and %li samples, end at %li and %li; ignore from %li",
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
653 (long) fr->firstframe, (long) fr->firstoff,
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
654 (long) fr->lastframe, (long) fr->lastoff, (long) fr->ignoreframe);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
655 #else
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
656 debug3("frame_set_frameseek: begin at %li frames, end at %li; ignore from %li",
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
657 (long) fr->firstframe, (long) fr->lastframe, (long) fr->ignoreframe);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
658 #endif
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
659 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
660
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
661 /* Sample accurate seek prepare for decoder. */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
662 /* This gets unadjusted output samples and takes resampling into account */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
663 void frame_set_seek(mpg123_handle *fr, off_t sp)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
664 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
665 fr->firstframe = frame_offset(fr, sp);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
666 fr->ignoreframe = fr->lay == 3 ? fr->firstframe-IGNORESHIFT : fr->firstframe;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
667 #ifdef GAPLESS /* The sample offset is used for non-gapless mode, too! */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
668 fr->firstoff = sp - frame_outs(fr, fr->firstframe);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
669 debug5("frame_set_seek: begin at %li frames and %li samples, end at %li and %li; ignore from %li",
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
670 (long) fr->firstframe, (long) fr->firstoff,
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
671 (long) fr->lastframe, (long) fr->lastoff, (long) fr->ignoreframe);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
672 #else
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
673 debug3("frame_set_seek: begin at %li frames, end at %li; ignore from %li",
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
674 (long) fr->firstframe, (long) fr->lastframe, (long) fr->ignoreframe);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
675 #endif
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
676 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
677
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
678 /* to vanish */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
679 void frame_outformat(mpg123_handle *fr, int format, int channels, long rate)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
680 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
681 fr->af.encoding = format;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
682 fr->af.rate = rate;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
683 fr->af.channels = channels;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
684 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
685
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
686 /* set synth functions for current frame, optimizations handled by opt_* macros */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
687 int set_synth_functions(mpg123_handle *fr)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
688 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
689 int ds = fr->down_sample;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
690 int p8=0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
691 static func_synth funcs[2][4] = {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
692 { NULL,
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
693 synth_2to1,
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
694 synth_4to1,
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
695 synth_ntom } ,
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
696 { NULL,
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
697 synth_2to1_8bit,
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
698 synth_4to1_8bit,
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
699 synth_ntom_8bit }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
700 };
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
701 static func_synth_mono funcs_mono[2][2][4] = {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
702 { { NULL ,
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
703 synth_2to1_mono2stereo ,
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
704 synth_4to1_mono2stereo ,
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
705 synth_ntom_mono2stereo } ,
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
706 { NULL ,
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
707 synth_2to1_8bit_mono2stereo ,
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
708 synth_4to1_8bit_mono2stereo ,
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
709 synth_ntom_8bit_mono2stereo } } ,
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
710 { { NULL ,
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
711 synth_2to1_mono ,
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
712 synth_4to1_mono ,
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
713 synth_ntom_mono } ,
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
714 { NULL ,
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
715 synth_2to1_8bit_mono ,
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
716 synth_4to1_8bit_mono ,
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
717 synth_ntom_8bit_mono } }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
718 };
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
719
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
720 /* possibly non-constand entries filled here */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
721 funcs[0][0] = (func_synth) opt_synth_1to1(fr);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
722 funcs[1][0] = (func_synth) opt_synth_1to1_8bit(fr);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
723 funcs_mono[0][0][0] = (func_synth_mono) opt_synth_1to1_mono2stereo(fr);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
724 funcs_mono[0][1][0] = (func_synth_mono) opt_synth_1to1_8bit_mono2stereo(fr);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
725 funcs_mono[1][0][0] = (func_synth_mono) opt_synth_1to1_mono(fr);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
726 funcs_mono[1][1][0] = (func_synth_mono) opt_synth_1to1_8bit_mono(fr);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
727
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
728 if(fr->af.encoding & MPG123_ENC_8) p8 = 1;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
729 fr->synth = funcs[p8][ds];
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
730 fr->synth_mono = funcs_mono[fr->af.channels==2 ? 0 : 1][p8][ds];
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
731
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
732 if(p8)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
733 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
734 if(make_conv16to8_table(fr) != 0)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
735 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
736 /* it's a bit more work to get proper error propagation up */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
737 return -1;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
738 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
739 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
740 return 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
741 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
742
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
743 int attribute_align_arg mpg123_volume_change(mpg123_handle *mh, double change)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
744 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
745 if(mh == NULL) return MPG123_ERR;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
746 return mpg123_volume(mh, change + (double) mh->p.outscale / MAXOUTBURST);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
747 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
748
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
749 int attribute_align_arg mpg123_volume(mpg123_handle *mh, double vol)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
750 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
751 if(mh == NULL) return MPG123_ERR;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
752 if(vol >= 0) mh->p.outscale = (double) MAXOUTBURST * vol;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
753 do_rva(mh);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
754 return MPG123_OK;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
755 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
756
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
757 static int get_rva(mpg123_handle *fr, double *peak, double *gain)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
758 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
759 double p = -1;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
760 double g = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
761 int ret = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
762 if(fr->p.rva)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
763 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
764 int rt = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
765 /* Should one assume a zero RVA as no RVA? */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
766 if(fr->p.rva == 2 && fr->rva.level[1] != -1) rt = 1;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
767 if(fr->rva.level[rt] != -1)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
768 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
769 p = fr->rva.peak[rt];
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
770 g = fr->rva.gain[rt];
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
771 ret = 1; /* Success. */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
772 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
773 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
774 if(peak != NULL) *peak = p;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
775 if(gain != NULL) *gain = g;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
776 return ret;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
777 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
778
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
779 /* adjust the volume, taking both fr->outscale and rva values into account */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
780 void do_rva(mpg123_handle *fr)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
781 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
782 double peak = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
783 double gain = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
784 scale_t newscale;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
785 double rvafact = 1;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
786 if(get_rva(fr, &peak, &gain))
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
787 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
788 if(NOQUIET && fr->p.verbose > 1) fprintf(stderr, "Note: doing RVA with gain %f\n", gain);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
789 rvafact = pow(10,gain/20);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
790 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
791
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
792 newscale = fr->p.outscale*rvafact;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
793
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
794 /* if peak is unknown (== 0) this check won't hurt */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
795 if((peak*newscale) > MAXOUTBURST)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
796 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
797 newscale = (scale_t) ((double) MAXOUTBURST/peak);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
798 #ifdef FLOATOUT
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
799 warning2("limiting scale value to %f to prevent clipping with indicated peak factor of %f", newscale, peak);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
800 #else
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
801 warning2("limiting scale value to %li to prevent clipping with indicated peak factor of %f", newscale, peak);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
802 #endif
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
803 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
804 /* first rva setting is forced with fr->lastscale < 0 */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
805 if(newscale != fr->lastscale)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
806 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
807 #ifdef FLOATOUT
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
808 debug3("changing scale value from %f to %f (peak estimated to %f)", fr->lastscale != -1 ? fr->lastscale : fr->p.outscale, newscale, (double) (newscale*peak));
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
809 #else
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
810 debug3("changing scale value from %li to %li (peak estimated to %li)", fr->lastscale != -1 ? fr->lastscale : fr->p.outscale, newscale, (long) (newscale*peak));
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
811 #endif
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
812 fr->lastscale = newscale;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
813 opt_make_decode_tables(fr); /* the actual work */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
814 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
815 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
816
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
817 int attribute_align_arg mpg123_getvolume(mpg123_handle *mh, double *base, double *really, double *rva_db)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
818 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
819 if(mh == NULL) return MPG123_ERR;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
820 if(base) *base = (double)mh->p.outscale/MAXOUTBURST;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
821 if(really) *really = (double)mh->lastscale/MAXOUTBURST;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
822 get_rva(mh, NULL, rva_db);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
823 return MPG123_OK;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
824 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
825
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
826 int frame_cpu_opt(mpg123_handle *fr, const char* cpu)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
827 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
828 char* chosen = ""; /* the chosed decoder opt as string */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
829 int auto_choose = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
830 int done = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
831 if( (cpu == NULL)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
832 || (cpu[0] == 0)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
833 || !strcasecmp(cpu, "auto") )
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
834 auto_choose = 1;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
835 #ifndef OPT_MULTI
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
836 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
837 char **sd = mpg123_decoders(); /* this contains _one_ decoder */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
838 if(!auto_choose && strcasecmp(cpu, sd[0])) done = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
839 else
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
840 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
841 chosen = sd[0];
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
842 done = 1;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
843 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
844 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
845 #else
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
846 fr->cpu_opts.type = nodec;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
847 /* covers any i386+ cpu; they actually differ only in the synth_1to1 function... */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
848 #ifdef OPT_X86
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
849
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
850 #ifdef OPT_MMXORSSE
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
851 fr->cpu_opts.make_decode_tables = make_decode_tables;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
852 fr->cpu_opts.init_layer3_gainpow2 = init_layer3_gainpow2;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
853 fr->cpu_opts.init_layer2_table = init_layer2_table;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
854 #endif
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
855 #ifdef OPT_3DNOW
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
856 fr->cpu_opts.dct36 = dct36;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
857 #endif
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
858 #ifdef OPT_3DNOWEXT
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
859 fr->cpu_opts.dct36 = dct36;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
860 #endif
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
861
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
862 if(cpu_i586(cpu_flags))
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
863 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
864 debug2("standard flags: 0x%08x\textended flags: 0x%08x", cpu_flags.std, cpu_flags.ext);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
865 #ifdef OPT_3DNOWEXT
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
866 if( !done && (auto_choose || !strcasecmp(cpu, "3dnowext"))
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
867 && cpu_3dnow(cpu_flags)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
868 && cpu_3dnowext(cpu_flags)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
869 && cpu_mmx(cpu_flags) )
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
870 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
871 int go = 1;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
872 if(fr->p.force_rate)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
873 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
874 #if defined(K6_FALLBACK) || defined(PENTIUM_FALLBACK)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
875 if(!auto_choose){ if(NOQUIET) error("I refuse to choose 3DNowExt as this will screw up with forced rate!"); }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
876 else if(VERBOSE) fprintf(stderr, "Note: Not choosing 3DNowExt because flexible rate not supported.\n");
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
877
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
878 go = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
879 #else
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
880 if(NOQUIET) error("You will hear some awful sound because of flexible rate being chosen with 3DNowExt decoder!");
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
881 #endif
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
882 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
883 if(go){ /* temporary hack for flexible rate bug, not going indent this - fix it instead! */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
884 chosen = "3DNowExt";
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
885 fr->cpu_opts.type = dreidnowext;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
886 fr->cpu_opts.class = mmxsse;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
887 fr->cpu_opts.dct36 = dct36_3dnowext;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
888 fr->cpu_opts.synth_1to1 = synth_1to1_3dnowext;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
889 fr->cpu_opts.dct64 = dct64_mmx; /* only use the 3dnow version in the synth_1to1_sse */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
890 fr->cpu_opts.make_decode_tables = make_decode_tables_mmx;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
891 fr->cpu_opts.init_layer3_gainpow2 = init_layer3_gainpow2_mmx;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
892 fr->cpu_opts.init_layer2_table = init_layer2_table_mmx;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
893 fr->cpu_opts.mpl_dct64 = dct64_3dnowext;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
894 done = 1;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
895 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
896 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
897 #endif
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
898 #ifdef OPT_SSE
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
899 if( !done && (auto_choose || !strcasecmp(cpu, "sse"))
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
900 && cpu_sse(cpu_flags) && cpu_mmx(cpu_flags) )
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
901 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
902 int go = 1;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
903 if(fr->p.force_rate)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
904 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
905 #ifdef PENTIUM_FALLBACK
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
906 if(!auto_choose){ if(NOQUIET) error("I refuse to choose SSE as this will screw up with forced rate!"); }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
907 else if(VERBOSE) fprintf(stderr, "Note: Not choosing SSE because flexible rate not supported.\n");
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
908
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
909 go = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
910 #else
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
911 if(NOQUIET) error("You will hear some awful sound because of flexible rate being chosen with SSE decoder!");
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
912 #endif
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
913 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
914 if(go){ /* temporary hack for flexible rate bug, not going indent this - fix it instead! */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
915 chosen = "SSE";
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
916 fr->cpu_opts.type = sse;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
917 fr->cpu_opts.class = mmxsse;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
918 fr->cpu_opts.synth_1to1 = synth_1to1_sse;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
919 fr->cpu_opts.dct64 = dct64_mmx; /* only use the sse version in the synth_1to1_sse */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
920 fr->cpu_opts.make_decode_tables = make_decode_tables_mmx;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
921 fr->cpu_opts.init_layer3_gainpow2 = init_layer3_gainpow2_mmx;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
922 fr->cpu_opts.init_layer2_table = init_layer2_table_mmx;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
923 fr->cpu_opts.mpl_dct64 = dct64_sse;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
924 done = 1;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
925 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
926 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
927 #endif
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
928 #ifdef OPT_3DNOW
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
929 fr->cpu_opts.dct36 = dct36;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
930 /* TODO: make autodetection for _all_ x86 optimizations (maybe just for i586+ and keep separate 486 build?) */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
931 /* check cpuflags bit 31 (3DNow!) and 23 (MMX) */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
932 if( !done && (auto_choose || !strcasecmp(cpu, "3dnow"))
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
933 && cpu_3dnow(cpu_flags) && cpu_mmx(cpu_flags) )
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
934 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
935 chosen = "3DNow";
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
936 fr->cpu_opts.type = dreidnow;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
937 fr->cpu_opts.dct36 = dct36_3dnow; /* 3DNow! optimized dct36() */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
938 fr->cpu_opts.synth_1to1 = synth_1to1_3dnow;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
939 fr->cpu_opts.dct64 = dct64_i386; /* use the 3dnow one? */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
940 done = 1;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
941 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
942 #endif
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
943 #ifdef OPT_MMX
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
944 if( !done && (auto_choose || !strcasecmp(cpu, "mmx"))
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
945 && cpu_mmx(cpu_flags) )
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
946 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
947 int go = 1;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
948 if(fr->p.force_rate)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
949 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
950 #ifdef PENTIUM_FALLBACK
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
951 if(!auto_choose){ if(NOQUIET) error("I refuse to choose MMX as this will screw up with forced rate!"); }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
952 else if(VERBOSE) fprintf(stderr, "Note: Not choosing MMX because flexible rate not supported.\n");
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
953
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
954 go = 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
955 #else
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
956 error("You will hear some awful sound because of flexible rate being chosen with MMX decoder!");
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
957 #endif
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
958 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
959 if(go){ /* temporary hack for flexible rate bug, not going indent this - fix it instead! */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
960 chosen = "MMX";
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
961 fr->cpu_opts.type = mmx;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
962 fr->cpu_opts.class = mmxsse;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
963 fr->cpu_opts.synth_1to1 = synth_1to1_mmx;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
964 fr->cpu_opts.dct64 = dct64_mmx;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
965 fr->cpu_opts.make_decode_tables = make_decode_tables_mmx;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
966 fr->cpu_opts.init_layer3_gainpow2 = init_layer3_gainpow2_mmx;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
967 fr->cpu_opts.init_layer2_table = init_layer2_table_mmx;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
968 done = 1;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
969 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
970 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
971 #endif
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
972 #ifdef OPT_I586
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
973 if(!done && (auto_choose || !strcasecmp(cpu, "i586")))
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
974 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
975 chosen = "i586/pentium";
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
976 fr->cpu_opts.type = ifuenf;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
977 fr->cpu_opts.synth_1to1 = synth_1to1_i586;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
978 fr->cpu_opts.synth_1to1_i586_asm = synth_1to1_i586_asm;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
979 fr->cpu_opts.dct64 = dct64_i386;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
980 done = 1;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
981 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
982 #endif
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
983 #ifdef OPT_I586_DITHER
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
984 if(!done && (auto_choose || !strcasecmp(cpu, "i586_dither")))
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
985 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
986 chosen = "dithered i586/pentium";
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
987 fr->cpu_opts.type = ifuenf_dither;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
988 fr->cpu_opts.synth_1to1 = synth_1to1_i586;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
989 fr->cpu_opts.dct64 = dct64_i386;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
990 fr->cpu_opts.synth_1to1_i586_asm = synth_1to1_i586_asm_dither;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
991 done = 1;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
992 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
993 #endif
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
994 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
995 #ifdef OPT_I486 /* that won't cooperate nicely in multi opt mode - forcing i486 in layer3.c */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
996 if(!done && (auto_choose || !strcasecmp(cpu, "i486")))
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
997 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
998 chosen = "i486";
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
999 fr->cpu_opts.type = ivier;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1000 fr->cpu_opts.synth_1to1 = synth_1to1_i386; /* i486 function is special */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1001 fr->cpu_opts.dct64 = dct64_i386;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1002 done = 1;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1003 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1004 #endif
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1005 #ifdef OPT_I386
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1006 if(!done && (auto_choose || !strcasecmp(cpu, "i386")))
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1007 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1008 chosen = "i386";
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1009 fr->cpu_opts.type = idrei;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1010 fr->cpu_opts.synth_1to1 = synth_1to1_i386;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1011 fr->cpu_opts.dct64 = dct64_i386;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1012 done = 1;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1013 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1014 #endif
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1015
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1016 if(done) /* set common x86 functions */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1017 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1018 fr->cpu_opts.synth_1to1_mono = synth_1to1_mono_i386;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1019 fr->cpu_opts.synth_1to1_mono2stereo = synth_1to1_mono2stereo_i386;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1020 fr->cpu_opts.synth_1to1_8bit = synth_1to1_8bit_i386;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1021 fr->cpu_opts.synth_1to1_8bit_mono = synth_1to1_8bit_mono_i386;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1022 fr->cpu_opts.synth_1to1_8bit_mono2stereo = synth_1to1_8bit_mono2stereo_i386;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1023 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1024 #endif /* OPT_X86 */
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1025
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1026 #ifdef OPT_ALTIVEC
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1027 if(!done && (auto_choose || !strcasecmp(cpu, "altivec")))
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1028 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1029 chosen = "AltiVec";
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1030 fr->cpu_opts.type = altivec;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1031 fr->cpu_opts.dct64 = dct64_altivec;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1032 fr->cpu_opts.synth_1to1 = synth_1to1_altivec;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1033 fr->cpu_opts.synth_1to1_mono = synth_1to1_mono_altivec;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1034 fr->cpu_opts.synth_1to1_mono2stereo = synth_1to1_mono2stereo_altivec;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1035 fr->cpu_opts.synth_1to1_8bit = synth_1to1_8bit_altivec;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1036 fr->cpu_opts.synth_1to1_8bit_mono = synth_1to1_8bit_mono_altivec;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1037 fr->cpu_opts.synth_1to1_8bit_mono2stereo = synth_1to1_8bit_mono2stereo_altivec;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1038 done = 1;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1039 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1040 #endif
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1041
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1042 #ifdef OPT_GENERIC
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1043 if(!done && (auto_choose || !strcasecmp(cpu, "generic")))
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1044 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1045 chosen = "generic";
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1046 fr->cpu_opts.type = generic;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1047 fr->cpu_opts.dct64 = dct64;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1048 fr->cpu_opts.synth_1to1 = synth_1to1;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1049 fr->cpu_opts.synth_1to1_mono = synth_1to1_mono;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1050 fr->cpu_opts.synth_1to1_mono2stereo = synth_1to1_mono2stereo;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1051 fr->cpu_opts.synth_1to1_8bit = synth_1to1_8bit;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1052 fr->cpu_opts.synth_1to1_8bit_mono = synth_1to1_8bit_mono;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1053 fr->cpu_opts.synth_1to1_8bit_mono2stereo = synth_1to1_8bit_mono2stereo;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1054 done = 1;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1055 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1056 #endif
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1057 #endif
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1058 if(done)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1059 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1060 if(VERBOSE) fprintf(stderr, "Decoder: %s\n", chosen);
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1061 return 1;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1062 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1063 else
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1064 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1065 if(NOQUIET) error("Could not set optimization!");
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1066 return 0;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1067 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1068 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1069
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1070 enum optdec dectype(const char* decoder)
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1071 {
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1072 if(decoder == NULL) return autodec;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1073 if(!strcasecmp(decoder, "3dnowext")) return dreidnowext;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1074 if(!strcasecmp(decoder, "3dnow")) return dreidnow;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1075 if(!strcasecmp(decoder, "sse")) return sse;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1076 if(!strcasecmp(decoder, "mmx")) return mmx;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1077 if(!strcasecmp(decoder, "generic")) return generic;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1078 if(!strcasecmp(decoder, "altivec")) return altivec;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1079 if(!strcasecmp(decoder, "i386")) return idrei;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1080 if(!strcasecmp(decoder, "i486")) return ivier;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1081 if(!strcasecmp(decoder, "i586")) return ifuenf;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1082 if(!strcasecmp(decoder, "i586_dither")) return ifuenf_dither;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1083 return nodec;
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1084 }
7e08477b0fc1 MP3 decoder upgrade work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1085