Project

General

Profile

audacious-plugins-3.3.1-libsidplayfp.patch

Cristian Morales Vega, September 05, 2012 01:52

View differences:

configure.ac
539 539

  
540 540
if test "x$enable_sid" = "xyes"; then
541 541
        AM_PATH_SIDPLAY(have_sidplay=yes, have_sidplay=no)
542
        PKG_CHECK_MODULES(SIDPLAYFP, [libsidplayfp], [xs_have_sidplayfp=yes], [])
543
        if test "x$xs_have_sidplayfp" = "xyes"; then
544
            have_sidplay=yes
545
            AC_DEFINE([HAVE_SIDPLAYFP], [], [Description])
546
        fi
542 547
else
543 548
        AC_MSG_RESULT([*** SID plugin disabled per user request ***])
544 549
        have_sidplay=no
......
1100 1105
echo "  Commodore 64 audio (SID):               $have_sidplay $xs_have_sidplay2_api"
1101 1106
echo "    -> libSIDPlay1 support:               $xs_have_sidplay1"
1102 1107
echo "    -> libSIDPlay2 support:               $xs_have_sidplay2"
1108
echo "    -> libSIDPlayFP support:              $xs_have_sidplayfp"
1103 1109
echo "    -> distortion patched libSIDPlay2:    $xs_have_distortion"
1104 1110
echo "  Game music (spc, nsf & gbs):            $enable_console"
1105 1111
echo "  PlayStation (psf/psf2) audio:           $enable_psf"
src/sid/xs_sidplayfp.cc
1
/*
2
   XMMS-SID - SIDPlay input plugin for X MultiMedia System (XMMS)
3

  
4
   libSIDPlay FP support
5

  
6
   Programmed and designed by Matti 'ccr' Hamalainen <ccr@tnsp.org>
7
   (C) Copyright 1999-2009 Tecnic Software productions (TNSP)
8

  
9
   This program is free software; you can redistribute it and/or modify
10
   it under the terms of the GNU General Public License as published by
11
   the Free Software Foundation; either version 2 of the License, or
12
   (at your option) any later version.
13

  
14
   This program is distributed in the hope that it will be useful,
15
   but WITHOUT ANY WARRANTY; without even the implied warranty of
16
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
   GNU General Public License for more details.
18

  
19
   You should have received a copy of the GNU General Public License along
20
   with this program; if not, write to the Free Software Foundation, Inc.,
21
   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22
*/
23
#include "xmms-sid.h"
24

  
25
#ifdef HAVE_SIDPLAYFP
26

  
27
#include <stdio.h>
28
#include "xs_sidplayfp.h"
29
#include "xs_config.h"
30

  
31

  
32
#include <sidplayfp/sidplay2.h>
33
#include <sidplayfp/SidTune.h>
34
#include <sidplayfp/sidbuilder.h>
35

  
36
class xs_sidplayfp_t {
37
public:
38
    sidplay2 *currEng;
39
    sidbuilder *currBuilder;
40
    sid2_config_t currConfig;
41
    SidTune *currTune;
42
    guint8 *buf;
43
    size_t bufSize;
44

  
45
    xs_sidplayfp_t(void);
46
    virtual ~xs_sidplayfp_t(void) { ; }
47
};
48

  
49

  
50
#ifdef HAVE_RESID_BUILDER
51
#  include <sidplayfp/builders/resid.h>
52
#endif
53
#ifdef HAVE_HARDSID_BUILDER
54
#  include <sidplayfp/builders/hardsid.h>
55
#endif
56

  
57

  
58
xs_sidplayfp_t::xs_sidplayfp_t(void)
59
:currEng(NULL)
60
{
61
    buf = NULL;
62
    bufSize = 0;
63
    currTune = NULL;
64
    currBuilder = NULL;
65
}
66

  
67

  
68
/* We need to 'export' all this pseudo-C++ crap */
69
extern "C" {
70

  
71

  
72
/* Return song information
73
 */
74
#define TFUNCTION   xs_sidplayfp_getinfo
75
#define TFUNCTION2  xs_sidplayfp_updateinfo
76
#define TTUNEINFO   SidTuneInfo
77
#define TTUNE       SidTune
78
#define TENGINE     xs_sidplayfp_t
79
#include "xs_sidplay.h"
80

  
81

  
82
/* Check if we can play the given file
83
 */
84
gboolean xs_sidplayfp_probe(xs_file_t *f)
85
{
86
    gchar tmpBuf[5];
87

  
88
    if (f == NULL) return FALSE;
89

  
90
    if (xs_fread(tmpBuf, sizeof(gchar), 4, f) != 4)
91
        return FALSE;
92

  
93
    if (!strncmp(tmpBuf, "PSID", 4) || !strncmp(tmpBuf, "RSID", 4))
94
        return TRUE;
95
    else
96
        return FALSE;
97
}
98

  
99

  
100
/* Initialize SIDPlayFP
101
 */
102
gboolean xs_sidplayfp_init(xs_status_t * status)
103
{
104
    gint tmpFreq, i;
105
    xs_sidplayfp_t *engine;
106
    sid_filter_t tmpFilter;
107
    xs_sid_filter_t *f;
108
    assert(status != NULL);
109

  
110
    /* Allocate internal structures */
111
    engine = new xs_sidplayfp_t();
112
    status->sidEngine = engine;
113
    if (!engine) return FALSE;
114

  
115
    /* Initialize the engine */
116
    engine->currEng = new sidplay2;
117
    if (!engine->currEng) {
118
        xs_error("[SIDPlayFP] Could not initialize emulation engine.\n");
119
        return FALSE;
120
    }
121

  
122
    /* Get current configuration */
123
    engine->currConfig = engine->currEng->config();
124

  
125
    /* Configure channels and stuff */
126
    switch (status->audioChannels) {
127

  
128
    case XS_CHN_AUTOPAN:
129
        engine->currConfig.playback = sid2_stereo;
130
        break;
131

  
132
    case XS_CHN_STEREO:
133
        engine->currConfig.playback = sid2_stereo;
134
        break;
135

  
136
    case XS_CHN_MONO:
137
    default:
138
        engine->currConfig.playback = sid2_mono;
139
        status->audioChannels = XS_CHN_MONO;
140
        break;
141
    }
142

  
143

  
144
    /* Memory mode settings */
145
    switch (xs_cfg.memoryMode) {
146
    case XS_MPU_BANK_SWITCHING:
147
        engine->currConfig.environment = sid2_envBS;
148
        break;
149

  
150
    case XS_MPU_TRANSPARENT_ROM:
151
        engine->currConfig.environment = sid2_envTP;
152
        break;
153

  
154
    case XS_MPU_PLAYSID_ENVIRONMENT:
155
        engine->currConfig.environment = sid2_envPS;
156
        break;
157

  
158
    case XS_MPU_REAL:
159
    default:
160
        engine->currConfig.environment = sid2_envR;
161
        xs_cfg.memoryMode = XS_MPU_REAL;
162
        break;
163
    }
164

  
165

  
166
    /* Audio parameters sanity checking and setup */
167
    tmpFreq = status->audioFrequency;
168

  
169
    if (status->oversampleEnable)
170
        tmpFreq = (tmpFreq * status->oversampleFactor);
171

  
172
    engine->currConfig.frequency = tmpFreq;
173

  
174
    /* Convert filter */
175
    f = &(xs_cfg.sid2Filter);
176
    XSDEBUG("using filter '%s', %d points\n", f->name, f->npoints);
177
    if (f->npoints > XS_SIDPLAY2_NFPOINTS) {
178
        xs_error("[SIDPlayFP] Invalid number of filter curve points (%d > %d)\n",
179
            f->npoints, XS_SIDPLAY2_NFPOINTS);
180
        f->npoints = XS_SIDPLAY2_NFPOINTS;
181
    }
182

  
183
    tmpFilter.points = f->npoints;
184
    for (i = 0; i < f->npoints; i++) {
185
        tmpFilter.cutoff[i][0] = f->points[i].x;
186
        tmpFilter.cutoff[i][1] = f->points[i].y;
187
    }
188

  
189
    /* Initialize builder object */
190
    XSDEBUG("init builder #%i, maxsids=%i\n", xs_cfg.sid2Builder, (engine->currEng->info()).maxsids);
191
#ifdef HAVE_RESID_BUILDER
192
    if (xs_cfg.sid2Builder == XS_BLD_RESID) {
193
        ReSIDBuilder *rs = new ReSIDBuilder("ReSID builder");
194
        engine->currBuilder = (sidbuilder *) rs;
195
        if (rs) {
196
            /* Builder object created, initialize it */
197
            rs->create((engine->currEng->info()).maxsids);
198
            if (!*rs) {
199
                xs_error("reSID->create() failed.\n");
200
                return FALSE;
201
            }
202

  
203
            rs->filter(xs_cfg.emulateFilters);
204
            if (!*rs) {
205
                xs_error("reSID->filter(%d) failed.\n", xs_cfg.emulateFilters);
206
                return FALSE;
207
            }
208

  
209
            // FIXME FIX ME: support other configurable parameters ...
210
            // ... WHEN/IF resid-builder+libsidplay2 gets fixed
211
            rs->sampling(tmpFreq);
212
            if (!*rs) {
213
                xs_error("reSID->sampling(%d) failed.\n", tmpFreq);
214
                return FALSE;
215
            }
216
            if (tmpFilter.points > 0)
217
                rs->filter((sid_filter_t *) &tmpFilter);
218
            else
219
                rs->filter((sid_filter_t *) NULL);
220

  
221
            if (!*rs) {
222
                xs_error("reSID->filter(NULL) failed.\n");
223
                return FALSE;
224
            }
225
        }
226
    }
227
#endif
228
#ifdef HAVE_HARDSID_BUILDER
229
    if (xs_cfg.sid2Builder == XS_BLD_HARDSID) {
230
        HardSIDBuilder *hs = new HardSIDBuilder("HardSID builder");
231
        engine->currBuilder = (sidbuilder *) hs;
232
        if (hs) {
233
            /* Builder object created, initialize it */
234
            hs->create((engine->currEng->info()).maxsids);
235
            if (!*hs) {
236
                xs_error("hardSID->create() failed.\n");
237
                return FALSE;
238
            }
239

  
240
            hs->filter(xs_cfg.emulateFilters);
241
            if (!*hs) {
242
                xs_error("hardSID->filter(%d) failed.\n", xs_cfg.emulateFilters);
243
                return FALSE;
244
            }
245
        }
246
    }
247
#endif
248

  
249
    if (!engine->currBuilder) {
250
        xs_error("[SIDPlayFP] Could not initialize SIDBuilder object.\n");
251
        return FALSE;
252
    }
253

  
254
    engine->currConfig.sidEmulation = engine->currBuilder;
255
    XSDEBUG("%s\n", engine->currBuilder->credits());
256

  
257
    /* Clockspeed settings */
258
    switch (xs_cfg.clockSpeed) {
259
    case XS_CLOCK_NTSC:
260
        engine->currConfig.clockDefault = SID2_CLOCK_NTSC;
261
        break;
262

  
263
    default:
264
        xs_error("[SIDPlayFP] Invalid clockSpeed=%d, falling back to PAL.\n",
265
            xs_cfg.clockSpeed);
266

  
267
    case XS_CLOCK_PAL:
268
        engine->currConfig.clockDefault = SID2_CLOCK_PAL;
269
        xs_cfg.clockSpeed = XS_CLOCK_PAL;
270
        break;
271
    }
272

  
273

  
274
    /* Configure rest of the emulation */
275
    if (xs_cfg.forceSpeed) {
276
        engine->currConfig.clockForced = true;
277
        engine->currConfig.clockSpeed = engine->currConfig.clockDefault;
278
    } else {
279
        engine->currConfig.clockForced = false;
280
        engine->currConfig.clockSpeed = SID2_CLOCK_CORRECT;
281
    }
282

  
283

  
284
    if (xs_cfg.mos8580)
285
        engine->currConfig.sidDefault = SID2_MOS8580;
286
    else
287
        engine->currConfig.sidDefault = SID2_MOS6581;
288

  
289
    if (xs_cfg.forceModel)
290
        engine->currConfig.sidModel = engine->currConfig.sidDefault;
291
    else
292
        engine->currConfig.sidModel = SID2_MODEL_CORRECT;
293

  
294

  
295
    /* XXX: Should this be configurable? libSIDPlay1 does not support it, though */
296
    engine->currConfig.sidSamples = TRUE;
297

  
298

  
299
    /* Now set the emulator configuration */
300
    if (engine->currEng->config(engine->currConfig) < 0) {
301
        xs_error("[SIDPlayFP] Emulator engine configuration failed!\n");
302
        return FALSE;
303
    }
304

  
305
    /* Create the sidtune */
306
    engine->currTune = new SidTune(0);
307
    if (!engine->currTune) {
308
        xs_error("[SIDPlayFP] Could not initialize SIDTune object.\n");
309
        return FALSE;
310
    }
311

  
312
    return TRUE;
313
}
314

  
315

  
316
/* Close SIDPlayFP engine
317
 */
318
void xs_sidplayfp_close(xs_status_t * status)
319
{
320
    xs_sidplayfp_t *engine;
321
    assert(status != NULL);
322

  
323
    engine = (xs_sidplayfp_t *) status->sidEngine;
324

  
325
    /* Free internals */
326
    if (engine->currBuilder) {
327
        delete engine->currBuilder;
328
        engine->currBuilder = NULL;
329
    }
330

  
331
    if (engine->currEng) {
332
        delete engine->currEng;
333
        engine->currEng = NULL;
334
    }
335

  
336
    if (engine->currTune) {
337
        delete engine->currTune;
338
        engine->currTune = NULL;
339
    }
340

  
341
    xs_sidplayfp_delete(status);
342

  
343
    delete engine;
344
    status->sidEngine = NULL;
345
}
346

  
347

  
348
/* Initialize current song and sub-tune
349
 */
350
gboolean xs_sidplayfp_initsong(xs_status_t * status)
351
{
352
    xs_sidplayfp_t *engine;
353
    assert(status != NULL);
354

  
355
    engine = (xs_sidplayfp_t *) status->sidEngine;
356
    if (engine == NULL) return FALSE;
357

  
358
    if (!engine->currTune->selectSong(status->currSong)) {
359
        xs_error("[SIDPlayFP] currTune->selectSong() failed\n");
360
        return FALSE;
361
    }
362

  
363
    if (engine->currEng->load(engine->currTune) < 0) {
364
        xs_error("[SIDPlayFP] currEng->load() failed\n");
365
        return FALSE;
366
    }
367

  
368
    status->isInitialized = TRUE;
369

  
370
    return TRUE;
371
}
372

  
373

  
374
/* Emulate and render audio data to given buffer
375
 */
376
guint xs_sidplayfp_fillbuffer(xs_status_t * status, gchar * audioBuffer, guint audioBufSize)
377
{
378
    xs_sidplayfp_t *engine;
379
    assert(status != NULL);
380

  
381
    engine = (xs_sidplayfp_t *) status->sidEngine;
382
    if (!engine) return 0;
383

  
384
    return engine->currEng->play((short *)audioBuffer, audioBufSize);
385
}
386

  
387

  
388
/* Load a given SID-tune file
389
 */
390
gboolean xs_sidplayfp_load(xs_status_t * status, const gchar * pcFilename)
391
{
392
    xs_sidplayfp_t *engine;
393
    assert(status != NULL);
394
    status->isInitialized = FALSE;
395

  
396
    engine = (xs_sidplayfp_t *) status->sidEngine;
397
    if (!engine) return FALSE;
398

  
399
    /* Try to get the tune */
400
    if (!pcFilename) return FALSE;
401

  
402
    if (xs_fload_buffer(pcFilename, &(engine->buf), &(engine->bufSize)) != 0)
403
        return FALSE;
404

  
405
    if (!engine->currTune->read(engine->buf, engine->bufSize))
406
        return FALSE;
407

  
408
    return TRUE;
409
}
410

  
411

  
412
/* Delete INTERNAL information
413
 */
414
void xs_sidplayfp_delete(xs_status_t * status)
415
{
416
    xs_sidplayfp_t *engine;
417
    assert(status != NULL);
418

  
419
    engine = (xs_sidplayfp_t *) status->sidEngine;
420
    if (engine == NULL) return;
421

  
422
    g_free(engine->buf);
423
    engine->buf = NULL;
424
    engine->bufSize = 0;
425
}
426

  
427

  
428
/* Hardware backend flushing
429
 */
430
void xs_sidplayfp_flush(xs_status_t * status)
431
{
432
    assert(status != NULL);
433

  
434
#ifdef HAVE_HARDSID_BUILDER
435
    if (xs_cfg.sid2Builder == XS_BLD_HARDSID)
436
        ((HardSIDBuilder *) status->currBuilder)->flush();
437
#endif
438
}
439

  
440

  
441
}    /* extern "C" */
442
#endif    /* HAVE_SIDPLAYFP */
src/sid/xs_sidplayfp.h
1
#ifndef XS_SIDPLAYFP_H
2
#define XS_SIDPLAYFP_H
3

  
4
#include "xs_player.h"
5
#include "xs_support.h"
6
#include "xs_slsup.h"
7

  
8
#ifdef __cplusplus
9
extern "C" {
10
#endif
11

  
12
gboolean    xs_sidplayfp_probe(xs_file_t *);
13
void        xs_sidplayfp_close(xs_status_t *);
14
gboolean    xs_sidplayfp_init(xs_status_t *);
15
gboolean    xs_sidplayfp_initsong(xs_status_t *);
16
guint        xs_sidplayfp_fillbuffer(xs_status_t *, gchar *, guint);
17
gboolean    xs_sidplayfp_load(xs_status_t *, const gchar *);
18
void        xs_sidplayfp_delete(xs_status_t *);
19
xs_tuneinfo_t*    xs_sidplayfp_getinfo(const gchar *);
20
gboolean    xs_sidplayfp_updateinfo(xs_status_t *);
21
void        xs_sidplayfp_flush(xs_status_t *);
22

  
23
#ifdef __cplusplus
24
}
25
#endif
26
#endif /* XS_SIDPLAY2_H */
src/sid/Makefile
9 9
       xs_filter.c	\
10 10
       xs_sidplay1.cc	\
11 11
       xs_sidplay2.cc	\
12
       xs_sidplayfp.cc	\
12 13
       xs_slsup.c	\
13 14
       xs_player.c	\
14 15
       xmms-sid.c
......
20 21

  
21 22
CFLAGS += ${PLUGIN_CFLAGS}
22 23
CXXFLAGS += ${PLUGIN_CFLAGS}
23
CPPFLAGS += ${PLUGIN_CPPFLAGS} -D_REENTRANT -I../.. -DAUDACIOUS_PLUGIN ${SIDPLAY1_CFLAGS} ${SIDPLAY2_CFLAGS} ${BUILDERS_CFLAGS} ${GLIB_CFLAGS}
24
LIBS += -lm ${BUILDERS_LDFLAGS} ${SIDPLAY1_LIBS} ${SIDPLAY2_LIBS} ${BUILDERS_LIBS} ${GLIB_LIBS} -lstdc++
24
CPPFLAGS += ${PLUGIN_CPPFLAGS} -D_REENTRANT -I../.. -DAUDACIOUS_PLUGIN ${SIDPLAY1_CFLAGS} ${SIDPLAY2_CFLAGS} ${SIDPLAYFP_CFLAGS} ${BUILDERS_CFLAGS} ${GLIB_CFLAGS}
25
LIBS += -lm ${BUILDERS_LDFLAGS} ${SIDPLAY1_LIBS} ${SIDPLAY2_LIBS} -Wl,--no-as-needed ${SIDPLAYFP_LIBS} -Wl,--as-needed ${BUILDERS_LIBS} ${GLIB_LIBS} -lstdc++
src/sid/xs_config.c
53 53
    xs_cfg.sid1Filter.fm = XS_SIDPLAY1_FM;
54 54
    xs_cfg.sid1Filter.ft = XS_SIDPLAY1_FT;
55 55

  
56
#ifdef HAVE_SIDPLAYFP
57
    xs_cfg.playerEngine = XS_ENG_SIDPLAYFP;
58
    xs_cfg.memoryMode = XS_MPU_REAL;
59
#else
56 60
#ifdef HAVE_SIDPLAY2
57 61
    xs_cfg.playerEngine = XS_ENG_SIDPLAY2;
58 62
    xs_cfg.memoryMode = XS_MPU_REAL;
......
64 68
#error This should not happen! No emulator engines configured in!
65 69
#endif
66 70
#endif
71
#endif
67 72

  
68 73
    xs_cfg.clockSpeed = XS_CLOCK_PAL;
69 74
    xs_cfg.forceSpeed = FALSE;
src/sid/xs_config.h
12 12
 */
13 13
enum XS_EMUENGINE {
14 14
    XS_ENG_SIDPLAY1 = 1,
15
    XS_ENG_SIDPLAY2
15
    XS_ENG_SIDPLAY2,
16
    XS_ENG_SIDPLAYFP
16 17
};
17 18

  
18 19

  
src/sid/xs_player.c
6 6
#ifdef HAVE_SIDPLAY2
7 7
#include "xs_sidplay2.h"
8 8
#endif
9
#ifdef HAVE_SIDPLAYFP
10
#include "xs_sidplayfp.h"
11
#endif
9 12

  
10 13

  
11 14
/* List of emulator engines
......
31 34
     xs_sidplay2_flush
32 35
    },
33 36
#endif
37
#ifdef HAVE_SIDPLAYFP
38
    {XS_ENG_SIDPLAYFP,
39
     xs_sidplayfp_probe,
40
     xs_sidplayfp_init, xs_sidplayfp_close,
41
     xs_sidplayfp_initsong, xs_sidplayfp_fillbuffer,
42
     xs_sidplayfp_load, xs_sidplayfp_delete,
43
     xs_sidplayfp_getinfo, xs_sidplayfp_updateinfo,
44
     xs_sidplayfp_flush
45
    },
46
#endif
34 47
};
35 48

  
36 49
static const gint xs_nenginelist = (sizeof(xs_enginelist) / sizeof(xs_enginelist[0]));
src/sid/xs_sidplay.h
65 65
        myInfo.songs, myInfo.startSong,
66 66
        myInfo.infoString[0], myInfo.infoString[1], myInfo.infoString[2],
67 67
        myInfo.loadAddr, myInfo.initAddr, myInfo.playAddr,
68
        myInfo.dataFileLen, myInfo.formatString, myInfo.sidModel);
68
        myInfo.dataFileLen, myInfo.formatString, myInfo.sidModel1);
69 69
    
70 70
    /* NOTICE! libSIDPlay[12] headers specifically state that sidModel,
71 71
     * songSpeed and clockSpeed are "undefined" before song initialization,
......
110 110
     * SIDTUNE_SIDMODEL_* similarly to our enums in xs_config.h ...
111 111
     */
112 112
    i = myStatus->tuneInfo;
113
    i->sidModel = myInfo.sidModel;
113
    i->sidModel = myInfo.sidModel1;
114 114

  
115 115
    if ((myStatus->currSong > 0) && (myStatus->currSong <= i->nsubTunes)) {
116 116
        gint tmpSpeed = -1;
extra.mk.in
91 91
SIDPLAY1_LIBS ?= @SIDPLAY1_LIBS@
92 92
SIDPLAY2_CFLAGS ?= @SIDPLAY2_CFLAGS@
93 93
SIDPLAY2_LIBS ?= @SIDPLAY2_LIBS@
94
SIDPLAYFP_CFLAGS ?= @SIDPLAYFP_CFLAGS@
95
SIDPLAYFP_LIBS ?= @SIDPLAYFP_LIBS@
94 96
SNDFILE_CFLAGS ?= @SNDFILE_CFLAGS@
95 97
SNDFILE_LIBS ?= @SNDFILE_LIBS@
96 98
SNDIO_LIBS ?= @SNDIO_LIBS@