From 086be2b4748ad2b1f0879b60d6931341617ea2da Mon Sep 17 00:00:00 2001 From: daveluff Date: Tue, 7 Jan 2003 14:41:49 +0000 Subject: [PATCH] Start the ATIS recorded message at a random position into the broadcast when the radio is tuned into it --- src/ATC/ATCVoice.cxx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/ATC/ATCVoice.cxx b/src/ATC/ATCVoice.cxx index 1b7aee420..c319bb492 100644 --- a/src/ATC/ATCVoice.cxx +++ b/src/ATC/ATCVoice.cxx @@ -28,6 +28,7 @@ #include #include #include +#include #include
#include "ATCVoice.hxx" @@ -143,7 +144,8 @@ unsigned char* FGATCVoice::WriteMessage(char* message, int& len, bool& dataOK) { dataOK = false; return(NULL); } - + + unsigned char* tmpbuf = new unsigned char[cumLength]; unsigned char* outbuf = new unsigned char[cumLength]; len = cumLength; unsigned int bufpos = 0; @@ -162,10 +164,17 @@ unsigned char* FGATCVoice::WriteMessage(char* message, int& len, bool& dataOK) { dataOK = false; return(NULL); } - memcpy(outbuf + bufpos, rawSoundData + wdptr[i].offset, wdptr[i].length); + memcpy(tmpbuf + bufpos, rawSoundData + wdptr[i].offset, wdptr[i].length); bufpos += wdptr[i].length; } + // tmpbuf now contains the message starting at the beginning - but we want it to start at a random position. + unsigned int offsetIn = (int)(cumLength * sg_random()); + if(offsetIn > cumLength) offsetIn = cumLength; + memcpy(outbuf, tmpbuf + offsetIn, (cumLength - offsetIn)); + memcpy(outbuf + (cumLength - offsetIn), tmpbuf, offsetIn); + + delete[] tmpbuf; delete[] wdptr; dataOK = true; -- 2.39.5