1 |
|
/* |
2 |
|
* SID.cpp - 6581 emulation |
3 |
|
* |
4 |
< |
* Frodo (C) 1994-1997,2002-2003 Christian Bauer |
4 |
> |
* Frodo Copyright (C) Christian Bauer |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
32 |
|
#include "Prefs.h" |
33 |
|
|
34 |
|
#ifdef __BEOS__ |
35 |
< |
#include <MediaKit.h> |
35 |
> |
#include <media/SoundPlayer.h> |
36 |
|
#endif |
37 |
|
|
38 |
|
#ifdef AMIGA |
354 |
|
// Renderer class |
355 |
|
class DigitalRenderer : public SIDRenderer { |
356 |
|
public: |
357 |
– |
#if defined(__BEOS__) || defined(__riscos__) |
357 |
|
DigitalRenderer(C64 *c64); |
359 |
– |
#else |
360 |
– |
DigitalRenderer(); |
361 |
– |
#endif |
358 |
|
virtual ~DigitalRenderer(); |
359 |
|
|
360 |
|
virtual void Reset(void); |
373 |
|
void calc_buffer(int16 *buf, long count); |
374 |
|
#endif |
375 |
|
|
376 |
+ |
C64 *the_c64; // Pointer to C64 object |
377 |
+ |
|
378 |
|
bool ready; // Flag: Renderer has initialized and is ready |
379 |
|
uint8 volume; // Master volume |
380 |
|
|
415 |
|
int sample_in_ptr; // Index in sample_buf for writing |
416 |
|
|
417 |
|
#ifdef __BEOS__ |
418 |
< |
static bool stream_func(void *arg, char *buf, size_t count, void *header); |
419 |
< |
C64 *the_c64; // Pointer to C64 object |
420 |
< |
BDACStream *the_stream; // Pointer to stream |
423 |
< |
BSubscriber *the_sub; // Pointer to subscriber |
424 |
< |
bool in_stream; // Flag: Subscriber has entered stream |
418 |
> |
static void buffer_proc(void *cookie, void *buffer, size_t size, const media_raw_audio_format &format); |
419 |
> |
BSoundPlayer *the_player; // Pointer to sound player |
420 |
> |
bool player_stopped; // Flag: player stopped |
421 |
|
#endif |
422 |
|
|
423 |
|
#ifdef AMIGA |
437 |
|
int play_buf; // Number of buffer currently playing |
438 |
|
#endif |
439 |
|
|
440 |
< |
#ifdef __linux__ |
440 |
> |
|
441 |
> |
#ifdef HAVE_SDL |
442 |
> |
static void buffer_proc(void *cookie, uint8 *buffer, int size); |
443 |
> |
#else |
444 |
> |
|
445 |
> |
# ifdef __linux__ |
446 |
|
int devfd, sndbufsize, buffer_rate; |
447 |
|
int16 *sound_buffer; |
448 |
< |
#endif |
448 |
> |
# endif |
449 |
|
|
450 |
< |
#ifdef SUN |
450 |
> |
# ifdef SUN |
451 |
|
int fd; |
452 |
|
audio_info status; |
453 |
|
uint_t sent_samples,delta_samples; |
454 |
|
int16 *sound_calc_buf; |
455 |
< |
#endif |
455 |
> |
# endif |
456 |
|
|
457 |
< |
#ifdef __hpux |
457 |
> |
# ifdef __hpux |
458 |
|
int fd; |
459 |
|
audio_status status; |
460 |
|
int16 *sound_calc_buf; |
461 |
|
int linecnt; |
462 |
< |
#endif |
462 |
> |
# endif |
463 |
> |
|
464 |
> |
#endif // ndef HAVE_SDL |
465 |
> |
|
466 |
|
|
467 |
|
#ifdef __mac__ |
468 |
|
SndChannelPtr chan1; |
496 |
|
#ifdef __riscos__ |
497 |
|
int linecnt, sndbufsize; |
498 |
|
uint8 *sound_buffer; |
495 |
– |
C64 *the_c64; |
499 |
|
#endif |
500 |
|
}; |
501 |
|
|
826 |
|
* Constructor |
827 |
|
*/ |
828 |
|
|
826 |
– |
#if defined(__BEOS__) || defined(__riscos__) |
829 |
|
DigitalRenderer::DigitalRenderer(C64 *c64) : the_c64(c64) |
828 |
– |
#else |
829 |
– |
DigitalRenderer::DigitalRenderer() |
830 |
– |
#endif |
830 |
|
{ |
831 |
|
// Link voices together |
832 |
|
voice[0].mod_by = &voice[2]; |
1198 |
|
#ifdef __riscos__ // on RISC OS we have 8 bit logarithmic sound |
1199 |
|
DigitalRenderer_GetTables(&LinToLog, &LogScale); // get translation tables |
1200 |
|
#else |
1202 |
– |
#ifdef __BEOS__ |
1203 |
– |
count >>= 2; // 16 bit stereo output, count is in bytes |
1204 |
– |
#else |
1201 |
|
count >>= 1; // 16 bit mono output, count is in bytes |
1202 |
|
#endif |
1207 |
– |
#endif |
1203 |
|
while (count--) { |
1209 |
– |
int32 sum_output; |
1210 |
– |
int32 sum_output_filter = 0; |
1211 |
– |
|
1204 |
|
// Get current master volume from sample buffer, |
1205 |
|
// calculate sampled voice |
1206 |
|
uint8 master_volume = sample_buf[(sample_count >> 16) % SAMPLE_BUF_SIZE]; |
1207 |
|
sample_count += ((0x138 * 50) << 16) / SAMPLE_FREQ; |
1208 |
< |
sum_output = SampleTab[master_volume] << 8; |
1208 |
> |
int32 sum_output = SampleTab[master_volume] << 8; |
1209 |
> |
int32 sum_output_filter = 0; |
1210 |
|
|
1211 |
|
// Loop for all three voices |
1212 |
|
for (int j=0; j<3; j++) { |
1328 |
|
} |
1329 |
|
|
1330 |
|
// Write to buffer |
1331 |
< |
#ifdef __BEOS__ |
1339 |
< |
int16 audio_data = (sum_output + sum_output_filter) >> 10; |
1340 |
< |
int val = *buf + audio_data; |
1341 |
< |
if (val > 32767) |
1342 |
< |
val = 32767; |
1343 |
< |
if (val < -32768) |
1344 |
< |
val = -32768; |
1345 |
< |
*buf++ = val; |
1346 |
< |
val = *buf + audio_data; |
1347 |
< |
if (val > 32767) |
1348 |
< |
val = 32767; |
1349 |
< |
if (val < -32768) |
1350 |
< |
val = -32768; |
1351 |
< |
*buf++ = val; |
1352 |
< |
#elif defined(__riscos__) // lookup in 8k (13bit) translation table |
1331 |
> |
#if defined(__riscos__) // lookup in 8k (13bit) translation table |
1332 |
|
*buf++ = LinToLog[((sum_output + sum_output_filter) >> 13) & 0x1fff]; |
1333 |
|
#else |
1334 |
|
*buf++ = (sum_output + sum_output_filter) >> 10; |
1344 |
|
#elif defined(AMIGA) |
1345 |
|
#include "SID_Amiga.h" |
1346 |
|
|
1347 |
+ |
#elif defined(HAVE_SDL) |
1348 |
+ |
#include "SID_SDL.h" |
1349 |
+ |
# if defined(__linux__) |
1350 |
+ |
# include "SID_catweasel.h" |
1351 |
+ |
# endif |
1352 |
+ |
|
1353 |
|
#elif defined(__linux__) |
1354 |
|
#include "SID_linux.h" |
1355 |
+ |
#include "SID_catweasel.h" |
1356 |
|
|
1357 |
|
#elif defined(SUN) |
1358 |
|
#include "SID_sun.h" |
1391 |
|
delete the_renderer; |
1392 |
|
|
1393 |
|
// Create new renderer |
1394 |
< |
if (new_type == SIDTYPE_DIGITAL) |
1409 |
< |
#if defined(__BEOS__) || defined(__riscos__) |
1394 |
> |
if (new_type == SIDTYPE_DIGITAL) { |
1395 |
|
the_renderer = new DigitalRenderer(the_c64); |
1411 |
– |
#else |
1412 |
– |
the_renderer = new DigitalRenderer(); |
1413 |
– |
#endif |
1396 |
|
#ifdef AMIGA |
1397 |
< |
else if (new_type == SIDTYPE_SIDCARD) |
1398 |
< |
the_renderer = new SIDCardRenderer(); |
1397 |
> |
} else if (new_type == SIDTYPE_SIDCARD) { |
1398 |
> |
the_renderer = new SIDCardRenderer; |
1399 |
|
#endif |
1400 |
< |
else |
1400 |
> |
#ifdef __linux__ |
1401 |
> |
} else if (new_type == SIDTYPE_SIDCARD) { |
1402 |
> |
the_renderer = new CatweaselRenderer; |
1403 |
> |
#endif |
1404 |
> |
} else { |
1405 |
|
the_renderer = NULL; |
1406 |
+ |
} |
1407 |
|
|
1408 |
|
// Stuff the current register values into the new renderer |
1409 |
|
if (the_renderer != NULL) |