annotate src/musepack/libmpc.h @ 1321:f0b81aeed25f

Thank you for your help, Giacomo. ;-)
author Stany HENRY <StrassBoy@gmail.com>
date Sat, 21 Jul 2007 07:46:47 +0200
parents f34112ab9101
children dc3e28d3b92a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
232
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
1 #ifndef XMMS_MUSEPACK
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
2 #define XMMS_MUSEPACK
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
3
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
4 //xmms headers
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
5 extern "C"
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
6 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
7 #include "audacious/plugin.h"
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
8 #include "audacious/output.h"
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
9 #include "audacious/util.h"
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
10 #include "audacious/configdb.h"
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
11 #include "audacious/titlestring.h"
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
12 #include "audacious/vfs.h"
1304
f34112ab9101 As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents: 1093
diff changeset
13 #include <audacious/i18n.h>
f34112ab9101 As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents: 1093
diff changeset
14 #include "../../config.h"
232
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
15 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
16
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
17 //stdlib headers
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
18 #include <string.h>
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
19 #include <stdio.h>
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
20 #include <stdlib.h>
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
21 #include <unistd.h>
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
22 #include <math.h>
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
23
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
24 //libmpcdec headers
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
25 #undef TRUE
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
26 #undef FALSE
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
27 #include <mpcdec/mpcdec.h>
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
28
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
29 //GTK+ headers
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
30 #include <glib.h>
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
31 #include <gtk/gtk.h>
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
32
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
33 //taglib headers
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
34 #include <taglib/tag.h>
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
35 #include <taglib/apetag.h>
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
36 #include <taglib/mpcfile.h>
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
37
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
38 #ifndef M_LN10
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
39 #define M_LN10 2.3025850929940456840179914546843642
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
40 #endif
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
41
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
42 typedef struct PluginConfig
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
43 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
44 gboolean clipPrevention;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
45 gboolean dynamicBitrate;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
46 gboolean replaygain;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
47 gboolean albumGain;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
48 gboolean isEq;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
49 };
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
50
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
51 typedef struct Widgets
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
52 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
53 GtkWidget* aboutBox;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
54 GtkWidget* configBox;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
55 GtkWidget* bitrateCheck;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
56 GtkWidget* clippingCheck;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
57 GtkWidget* replaygainCheck;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
58 GtkWidget* albumCheck;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
59 GtkWidget* infoBox;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
60 GtkWidget* albumEntry;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
61 GtkWidget* artistEntry;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
62 GtkWidget* titleEntry;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
63 GtkWidget* genreEntry;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
64 GtkWidget* yearEntry;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
65 GtkWidget* trackEntry;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
66 GtkWidget* commentEntry;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
67 GtkWidget* fileEntry;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
68 };
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
69
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
70 typedef struct MpcDecoder
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
71 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
72 char* isError;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
73 double offset;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
74 bool isOutput;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
75 bool isAlive;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
76 bool isPause;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
77 };
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
78
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
79 typedef struct TrackInfo
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
80 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
81 int bitrate;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
82 char* display;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
83 int length;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
84 int sampleFreq;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
85 int channels;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
86 };
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
87
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
88 typedef struct MpcInfo
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
89 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
90 char* title;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
91 char* artist;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
92 char* album;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
93 char* comment;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
94 char* genre;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
95 char* date;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
96 unsigned track;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
97 unsigned year;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
98 };
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
99
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
100 static void mpcOpenPlugin();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
101 static void mpcAboutBox();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
102 static void mpcConfigBox();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
103 static void toggleSwitch(GtkWidget*, gpointer);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
104 static void saveConfigBox(GtkWidget*, gpointer);
260
4f7b72c88319 [svn] So input.c wants to have the old-style function available...
chainsaw
parents: 254
diff changeset
105 static int mpcIsOurFile(char*);
4f7b72c88319 [svn] So input.c wants to have the old-style function available...
chainsaw
parents: 254
diff changeset
106 static int mpcIsOurFD(char*,VFSFile*);
567
1e987b380776 [svn] - update to new plugin API
nenolod
parents: 260
diff changeset
107 static void mpcPlay(InputPlayback *data);
1e987b380776 [svn] - update to new plugin API
nenolod
parents: 260
diff changeset
108 static void mpcStop(InputPlayback *data);
1e987b380776 [svn] - update to new plugin API
nenolod
parents: 260
diff changeset
109 static void mpcPause(InputPlayback *data, short);
1e987b380776 [svn] - update to new plugin API
nenolod
parents: 260
diff changeset
110 static void mpcSeek(InputPlayback *data, int);
232
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
111 static void mpcSetEq(int, float, float*);
567
1e987b380776 [svn] - update to new plugin API
nenolod
parents: 260
diff changeset
112 static int mpcGetTime(InputPlayback *data);
232
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
113 static void mpcGetSongInfo(char*, char**, int*);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
114 static void freeTags(MpcInfo&);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
115 static MpcInfo getTags(const char*);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
116 static void mpcFileInfoBox(char*);
1044
b1128efde471 [svn] - get rid of all warnings gcc 4.2.0 emits with my build configuration.
yaz
parents: 567
diff changeset
117 static void mpcGtkPrintLabel(GtkWidget*, const char*, ...);
b1128efde471 [svn] - get rid of all warnings gcc 4.2.0 emits with my build configuration.
yaz
parents: 567
diff changeset
118 static GtkWidget* mpcGtkTagLabel(const char*, int, int, int, int, GtkWidget*);
232
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
119 static GtkWidget* mpcGtkTagEntry(int, int, int, int, int, GtkWidget*);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
120 static GtkWidget* mpcGtkLabel(GtkWidget*);
1044
b1128efde471 [svn] - get rid of all warnings gcc 4.2.0 emits with my build configuration.
yaz
parents: 567
diff changeset
121 static GtkWidget* mpcGtkButton(const char*, GtkWidget*);
232
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
122 static void removeTags(GtkWidget*, gpointer);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
123 static void saveTags(GtkWidget*, gpointer);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
124 static void closeInfoBox(GtkWidget*, gpointer);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
125 static char* mpcGenerateTitle(const MpcInfo&, char*);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
126 static void lockAcquire();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
127 static void lockRelease();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
128 static void* decodeStream(void*);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
129 static int processBuffer(MPC_SAMPLE_FORMAT*, char*, mpc_decoder&);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
130 static void* endThread(char*, FILE*, bool);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
131 static bool isAlive();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
132 static void setAlive(bool);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
133 static double getOffset();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
134 static void setOffset(double);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
135 static bool isPause();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
136 static void setReplaygain(mpc_streaminfo&, mpc_decoder&);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
137 static TitleInput* mpcGetSongTuple(char *);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
138
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
139 #ifdef MPC_FIXED_POINT
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
140 inline static int shiftSigned(MPC_SAMPLE_FORMAT val, int shift)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
141 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
142 if (shift > 0)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
143 val <<= shift;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
144 else if (shift < 0)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
145 val >>= -shift;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
146 return (int) val;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
147 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
148 #endif
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
149
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
150 inline static void copyBuffer(MPC_SAMPLE_FORMAT* pInBuf, char* pOutBuf, unsigned pLength)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
151 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
152 unsigned pSize = 16;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
153 int clipMin = -1 << (pSize - 1);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
154 int clipMax = (1 << (pSize - 1)) - 1;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
155 int floatScale = 1 << (pSize - 1);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
156 for (unsigned n = 0; n < 2 * pLength; n++)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
157 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
158 int val;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
159 #ifdef MPC_FIXED_POINT
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
160 val = shiftSigned(pInBuf[n], pSize - MPC_FIXED_POINT_SCALE_SHIFT);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
161 #else
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
162 val = (int) (pInBuf[n] * floatScale);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
163 #endif
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
164 if (val < clipMin)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
165 val = clipMin;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
166 else if (val > clipMax)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
167 val = clipMax;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
168 unsigned shift = 0;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
169 do
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
170 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
171 pOutBuf[n * 2 + (shift / 8)] = (unsigned char) ((val >> shift) & 0xFF);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
172 shift += 8;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
173 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
174 while (shift < pSize);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
175 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
176 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
177
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
178 #endif