diff --git a/Src/Network.cpp b/Src/Network.cpp index 7bef0a8..ae1a24c 100644 --- a/Src/Network.cpp +++ b/Src/Network.cpp @@ -376,6 +376,27 @@ size_t Network::EncodeSoundBuffer(struct NetworkUpdate *dst, Uint8 *buf, size_t 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) { struct NetworkUpdate *dst = this->cur_ud; @@ -680,4 +701,8 @@ int Network::n_peers; int Network::listen_sock; 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" diff --git a/Src/Network.h b/Src/Network.h index 80ee0f2..4f1798d 100644 --- a/Src/Network.h +++ b/Src/Network.h @@ -10,7 +10,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 { STOP = 99, @@ -55,6 +56,8 @@ public: ~Network(); + void EncodeSound(); + void EncodeDisplay(Uint8 *master, Uint8 *remote); void EncodeJoystickUpdate(Uint8 v); @@ -112,6 +115,8 @@ public: static void RemovePeer(Network *peer); + static void PushSound(uint8 vol); + /* Listener-related */ static Network *peers[MAX_NETWORK_PEERS]; static int n_peers; @@ -205,6 +210,7 @@ protected: Uint8 *raw_buf; Uint8 *rle_buf; Uint8 *diff_buf; + Uint8 *sound_buf; Uint32 *square_updated; size_t traffic, last_traffic; @@ -222,6 +228,11 @@ protected: /* Listener-related */ static int listen_sock; + + /* Sound */ + static uint8 sample_buf[NETWORK_SOUND_BUF_SIZE]; + static int sample_head; + static int sample_tail; }; #endif /* NETWORK_H */ diff --git a/Src/SID.cpp b/Src/SID.cpp index 1e95cc8..7b98bd9 100644 --- a/Src/SID.cpp +++ b/Src/SID.cpp @@ -30,6 +30,7 @@ #include "SID.h" #include "Prefs.h" +#include "Network.h" #ifdef __BEOS__ #include @@ -1210,6 +1211,7 @@ void DigitalRenderer::calc_buffer(int16 *buf, long count) int32 sum_output = SampleTab[master_volume] << 8; int32 sum_output_filter = 0; + Network::PushSound(master_volume); // Loop for all three voices for (int j=0; j<3; j++) { DRVoice *v = &voice[j];