Implement some of the sound stuff (not working)

This commit is contained in:
simon.kagstrom 2009-11-04 17:41:54 +00:00
parent 3a72e6a87c
commit 977f3042f0
4 changed files with 65 additions and 1 deletions

View File

@ -77,6 +77,10 @@ Network::Network(const char *remote_host, int port)
this->screen = (Uint8 *)malloc(DISPLAY_X * DISPLAY_Y);
assert(this->screen);
this->sound_head = this->sound_tail = 0;
memset(this->sound_active, 0, sizeof(this->sound_active));
memset(this->sound_network, 0, sizeof(this->sound_network));
/* Assume black screen */
memset(this->screen, 0, DISPLAY_X * DISPLAY_Y);
memset(this->screenshot, 0, sizeof(this->screenshot));
@ -397,6 +401,44 @@ void Network::EncodeTextMessage(char *str)
}
static int bytes = 0;
void Network::PushSound(uint8 adr, uint8 val)
{
NetworkUpdateSoundInfo *cur = &this->sound_active[this->sound_head];
cur->adr = adr;
cur->val = val;
cur->delay_cycles = TheC64->CycleCounter - sound_last_cycles;
/* Update the cycle counter */
sound_last_cycles = TheC64->CycleCounter;
this->sound_head++;
if (this->sound_head >= NETWORK_SOUND_BUF_SIZE)
this->sound_head = 0;
if (this->sound_head >= this->sound_tail)
this->sound_tail = (this->sound_head + 1) % NETWORK_SOUND_BUF_SIZE;
bytes += 3;
}
void Network::FlushSound(void)
{
struct NetworkUpdate *dst = this->cur_ud;
struct NetworkUpdateSound *snd = (NetworkUpdateSound *)dst->data;
struct NetworkUpdateSoundInfo *snd_info = snd->info;
static int last_cycles = 0;
snd->flags = 0;
snd->n_items = 0;
if (SDL_GetTicks() - last_cycles < 125)
return;
printf("Flushing sound (%d bytes in %d ms)\n", bytes, SDL_GetTicks() - last_cycles);
last_cycles = SDL_GetTicks();
bytes = 0;
}
void Network::EncodeJoystickUpdate(Uint8 v)
{
struct NetworkUpdate *dst = this->cur_ud;

View File

@ -16,7 +16,7 @@
#define FRODO_NETWORK_MAGIC 0x1976
#define NETWORK_UPDATE_SIZE (256 * 1024)
#define NETWORK_SOUND_BUF_SIZE 4096
#define NETWORK_SOUND_BUF_SIZE 8192
#define SCREENSHOT_FACTOR 4
#define SCREENSHOT_X (DISPLAY_X / SCREENSHOT_FACTOR)
@ -179,6 +179,10 @@ public:
void EncodeTextMessage(char *str);
void PushSound(uint8 addr, uint8 val);
void FlushSound(void);
bool DecodeUpdate(C64Display *display, uint8 *js, MOS6581 *dst);
@ -356,6 +360,12 @@ protected:
network_connection_state_t network_connection_state;
NetworkUpdateSoundInfo sound_active[NETWORK_SOUND_BUF_SIZE];
NetworkUpdateSoundInfo sound_network[NETWORK_SOUND_BUF_SIZE];
int sound_head;
int sound_tail;
uint32 sound_last_cycles;
public:
static bool networking_started;
};

View File

@ -910,11 +910,21 @@ void DigitalRenderer::Reset(void)
* Write to register
*/
#include "C64.h"
extern C64 *TheC64;
void DigitalRenderer::WriteRegister(uint16 adr, uint8 byte)
{
if (!ready)
return;
if (TheC64) {
if (TheC64->network_connection_type == MASTER)
TheC64->peer->PushSound(adr, byte);
else if (TheC64->network_connection_type == CLIENT)
return;
}
int v = adr/7; // Voice number
switch (adr) {

View File

@ -144,6 +144,8 @@ void DigitalRenderer::EmulateLine(void)
{
if (!ready)
return;
if (TheC64->network_connection_type == MASTER)
TheC64->peer->FlushSound();
this->PushVolume(volume);
}