Sound network stuff (not working yet)

This commit is contained in:
simon.kagstrom 2009-02-02 19:51:58 +00:00
parent a0a3097dec
commit 568e6eb5b7
3 changed files with 39 additions and 1 deletions

View File

@ -376,6 +376,27 @@ size_t Network::EncodeSoundBuffer(struct NetworkUpdate *dst, Uint8 *buf, size_t
return dst->size; return dst->size;
} }
void Network::EncodeSound()
{
NetworkUpdate *dst = (NetworkUpdate *)this->cur_ud;
int cnt = 0;
/* Nothing to encode? */
if (!this->is_master ||
Network::sample_head == Network::sample_tail)
return;
while (Network::sample_tail != Network::sample_head)
{
Network::sample_tail = (Network::sample_tail + 1) % NETWORK_SOUND_BUF_SIZE;
}
}
void Network::PushSound(uint8 vol)
{
Network::sample_buf[Network::sample_head] = vol;
Network::sample_head = (Network::sample_head + 1) % NETWORK_SOUND_BUF_SIZE;
}
void Network::EncodeJoystickUpdate(Uint8 v) void Network::EncodeJoystickUpdate(Uint8 v)
{ {
struct NetworkUpdate *dst = this->cur_ud; struct NetworkUpdate *dst = this->cur_ud;
@ -680,4 +701,8 @@ int Network::n_peers;
int Network::listen_sock; int Network::listen_sock;
Network *Network::peers[MAX_NETWORK_PEERS]; Network *Network::peers[MAX_NETWORK_PEERS];
uint8 Network::sample_buf[NETWORK_SOUND_BUF_SIZE];
int Network::sample_head;
int Network::sample_tail;
#include "NetworkUnix.h" #include "NetworkUnix.h"

View File

@ -11,6 +11,7 @@
#define MAX_NETWORK_PEERS 8 #define MAX_NETWORK_PEERS 8
#define NETWORK_UPDATE_SIZE (256 * 1024) #define NETWORK_UPDATE_SIZE (256 * 1024)
#define NETWORK_SOUND_BUF_SIZE 1024
enum enum
{ {
STOP = 99, STOP = 99,
@ -55,6 +56,8 @@ public:
~Network(); ~Network();
void EncodeSound();
void EncodeDisplay(Uint8 *master, Uint8 *remote); void EncodeDisplay(Uint8 *master, Uint8 *remote);
void EncodeJoystickUpdate(Uint8 v); void EncodeJoystickUpdate(Uint8 v);
@ -112,6 +115,8 @@ public:
static void RemovePeer(Network *peer); static void RemovePeer(Network *peer);
static void PushSound(uint8 vol);
/* Listener-related */ /* Listener-related */
static Network *peers[MAX_NETWORK_PEERS]; static Network *peers[MAX_NETWORK_PEERS];
static int n_peers; static int n_peers;
@ -205,6 +210,7 @@ protected:
Uint8 *raw_buf; Uint8 *raw_buf;
Uint8 *rle_buf; Uint8 *rle_buf;
Uint8 *diff_buf; Uint8 *diff_buf;
Uint8 *sound_buf;
Uint32 *square_updated; Uint32 *square_updated;
size_t traffic, last_traffic; size_t traffic, last_traffic;
@ -222,6 +228,11 @@ protected:
/* Listener-related */ /* Listener-related */
static int listen_sock; static int listen_sock;
/* Sound */
static uint8 sample_buf[NETWORK_SOUND_BUF_SIZE];
static int sample_head;
static int sample_tail;
}; };
#endif /* NETWORK_H */ #endif /* NETWORK_H */

View File

@ -30,6 +30,7 @@
#include "SID.h" #include "SID.h"
#include "Prefs.h" #include "Prefs.h"
#include "Network.h"
#ifdef __BEOS__ #ifdef __BEOS__
#include <media/SoundPlayer.h> #include <media/SoundPlayer.h>
@ -1210,6 +1211,7 @@ void DigitalRenderer::calc_buffer(int16 *buf, long count)
int32 sum_output = SampleTab[master_volume] << 8; int32 sum_output = SampleTab[master_volume] << 8;
int32 sum_output_filter = 0; int32 sum_output_filter = 0;
Network::PushSound(master_volume);
// Loop for all three voices // Loop for all three voices
for (int j=0; j<3; j++) { for (int j=0; j<3; j++) {
DRVoice *v = &voice[j]; DRVoice *v = &voice[j];