annotate src/musepack/libmpc.h @ 3085:ac0af6b39272

Introduce new GIO plugin to buildsystem. stdio is now deprecated. Thoughts: - getc()/ungetc() should be moved to VFS core now
author William Pitcock <nenolod@atheme.org>
date Wed, 29 Apr 2009 20:58:36 -0500
parents 3134a0987162
children
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
1954
6acf1bda788b Removed some extraneous includes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1950
diff changeset
4 #include "config.h"
6acf1bda788b Removed some extraneous includes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1950
diff changeset
5
232
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
6 //xmms headers
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
7 extern "C"
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
8 {
2971
3134a0987162 - changed include path from audacious to audlegacy.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2576
diff changeset
9 #include <audlegacy/plugin.h>
3134a0987162 - changed include path from audacious to audlegacy.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2576
diff changeset
10 #include <audlegacy/output.h>
3134a0987162 - changed include path from audacious to audlegacy.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2576
diff changeset
11 #include <audlegacy/i18n.h>
232
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
12 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
13
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
14 //stdlib headers
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
15 #include <string.h>
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
16 #include <stdio.h>
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
17 #include <stdlib.h>
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
18 #include <unistd.h>
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
19 #include <math.h>
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
20
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
21 //libmpcdec headers
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
22 #undef TRUE
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
23 #undef FALSE
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
24 #include <mpcdec/mpcdec.h>
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
25
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
26 //GTK+ headers
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
27 #include <glib.h>
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
28 #include <gtk/gtk.h>
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
29
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
30 //taglib headers
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
31 #include <taglib/tag.h>
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
32 #include <taglib/apetag.h>
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
33 #include <taglib/mpcfile.h>
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
34
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
35 #ifndef M_LN10
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
36 #define M_LN10 2.3025850929940456840179914546843642
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
37 #endif
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
38
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
39 typedef struct PluginConfig
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
40 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
41 gboolean clipPrevention;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
42 gboolean dynamicBitrate;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
43 gboolean replaygain;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
44 gboolean albumGain;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
45 gboolean isEq;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
46 };
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
47
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
48 typedef struct Widgets
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
49 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
50 GtkWidget* aboutBox;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
51 GtkWidget* configBox;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
52 GtkWidget* bitrateCheck;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
53 GtkWidget* clippingCheck;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
54 GtkWidget* replaygainCheck;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
55 GtkWidget* albumCheck;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
56 GtkWidget* infoBox;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
57 GtkWidget* albumEntry;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
58 GtkWidget* artistEntry;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
59 GtkWidget* titleEntry;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
60 GtkWidget* genreEntry;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
61 GtkWidget* yearEntry;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
62 GtkWidget* trackEntry;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
63 GtkWidget* commentEntry;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
64 GtkWidget* fileEntry;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
65 };
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
66
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
67 typedef struct MpcDecoder
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
68 {
2112
c1a825ee8cec Use GLib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2000
diff changeset
69 gchar* isError;
232
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
70 double offset;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
71 bool isOutput;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
72 bool isAlive;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
73 bool isPause;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
74 };
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
75
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
76 typedef struct TrackInfo
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
77 {
2112
c1a825ee8cec Use GLib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2000
diff changeset
78 gint bitrate;
c1a825ee8cec Use GLib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2000
diff changeset
79 gchar* display;
c1a825ee8cec Use GLib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2000
diff changeset
80 gint length;
c1a825ee8cec Use GLib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2000
diff changeset
81 gint sampleFreq;
c1a825ee8cec Use GLib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2000
diff changeset
82 gint channels;
232
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
83 };
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
84
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
85 typedef struct MpcInfo
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
86 {
2112
c1a825ee8cec Use GLib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2000
diff changeset
87 gchar* title;
c1a825ee8cec Use GLib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2000
diff changeset
88 gchar* artist;
c1a825ee8cec Use GLib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2000
diff changeset
89 gchar* album;
c1a825ee8cec Use GLib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2000
diff changeset
90 gchar* comment;
c1a825ee8cec Use GLib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2000
diff changeset
91 gchar* genre;
c1a825ee8cec Use GLib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2000
diff changeset
92 gchar* date;
c1a825ee8cec Use GLib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2000
diff changeset
93 unsigned track;
c1a825ee8cec Use GLib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2000
diff changeset
94 unsigned year;
232
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
95 };
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
96
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
97 static void mpcOpenPlugin();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
98 static void mpcAboutBox();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
99 static void mpcConfigBox();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
100 static void toggleSwitch(GtkWidget*, gpointer);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
101 static void saveConfigBox(GtkWidget*, gpointer);
260
4f7b72c88319 [svn] So input.c wants to have the old-style function available...
chainsaw
parents: 254
diff changeset
102 static int mpcIsOurFile(char*);
4f7b72c88319 [svn] So input.c wants to have the old-style function available...
chainsaw
parents: 254
diff changeset
103 static int mpcIsOurFD(char*,VFSFile*);
567
1e987b380776 [svn] - update to new plugin API
nenolod
parents: 260
diff changeset
104 static void mpcPlay(InputPlayback *data);
1e987b380776 [svn] - update to new plugin API
nenolod
parents: 260
diff changeset
105 static void mpcStop(InputPlayback *data);
1e987b380776 [svn] - update to new plugin API
nenolod
parents: 260
diff changeset
106 static void mpcPause(InputPlayback *data, short);
1e987b380776 [svn] - update to new plugin API
nenolod
parents: 260
diff changeset
107 static void mpcSeek(InputPlayback *data, int);
2000
89a445c53318 make musepack compile again.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 1986
diff changeset
108 //static void mpcSetEq(int, float, float*);
567
1e987b380776 [svn] - update to new plugin API
nenolod
parents: 260
diff changeset
109 static int mpcGetTime(InputPlayback *data);
232
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
110 static void mpcGetSongInfo(char*, char**, int*);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
111 static void freeTags(MpcInfo&);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
112 static MpcInfo getTags(const char*);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
113 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
114 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
115 static GtkWidget* mpcGtkTagLabel(const char*, int, int, int, int, GtkWidget*);
232
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
116 static GtkWidget* mpcGtkTagEntry(int, int, int, int, int, GtkWidget*);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
117 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
118 static GtkWidget* mpcGtkButton(const char*, GtkWidget*);
232
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
119 static void removeTags(GtkWidget*, gpointer);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
120 static void saveTags(GtkWidget*, gpointer);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
121 static void closeInfoBox(GtkWidget*, gpointer);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
122 static char* mpcGenerateTitle(const MpcInfo&, char*);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
123 static void lockAcquire();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
124 static void lockRelease();
1986
4b78df9dcf93 more set_params()
William Pitcock <nenolod@atheme.org>
parents: 1954
diff changeset
125 static void* decodeStream(InputPlayback*);
2000
89a445c53318 make musepack compile again.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 1986
diff changeset
126 static int processBuffer(InputPlayback*, MPC_SAMPLE_FORMAT*, char*, mpc_decoder&);
89a445c53318 make musepack compile again.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 1986
diff changeset
127 //static void* endThread(char*, FILE*, bool);
232
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
128 static bool isAlive();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
129 static void setAlive(bool);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
130 static double getOffset();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
131 static void setOffset(double);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
132 static bool isPause();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
133 static void setReplaygain(mpc_streaminfo&, mpc_decoder&);
1438
dc3e28d3b92a mpc: convert, wma: fixes
William Pitcock <nenolod@atheme-project.org>
parents: 1304
diff changeset
134 static Tuple * mpcGetSongTuple(char *);
232
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
135
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
136 #ifdef MPC_FIXED_POINT
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
137 inline static int shiftSigned(MPC_SAMPLE_FORMAT val, int shift)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
138 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
139 if (shift > 0)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
140 val <<= shift;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
141 else if (shift < 0)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
142 val >>= -shift;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
143 return (int) val;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
144 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
145 #endif
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
146
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
147 inline static void copyBuffer(MPC_SAMPLE_FORMAT* pInBuf, char* pOutBuf, unsigned pLength)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
148 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
149 unsigned pSize = 16;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
150 int clipMin = -1 << (pSize - 1);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
151 int clipMax = (1 << (pSize - 1)) - 1;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
152 int floatScale = 1 << (pSize - 1);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
153 for (unsigned n = 0; n < 2 * pLength; n++)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
154 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
155 int val;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
156 #ifdef MPC_FIXED_POINT
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
157 val = shiftSigned(pInBuf[n], pSize - MPC_FIXED_POINT_SCALE_SHIFT);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
158 #else
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
159 val = (int) (pInBuf[n] * floatScale);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
160 #endif
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
161 if (val < clipMin)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
162 val = clipMin;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
163 else if (val > clipMax)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
164 val = clipMax;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
165 unsigned shift = 0;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
166 do
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
167 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
168 pOutBuf[n * 2 + (shift / 8)] = (unsigned char) ((val >> shift) & 0xFF);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
169 shift += 8;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
170 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
171 while (shift < pSize);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
172 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
173 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
174
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
175 #endif