- unsigned char* tmpbuf = new unsigned char[cumLength];
- unsigned char* outbuf = new unsigned char[cumLength];
- len = cumLength;
- unsigned int bufpos = 0;
- for(int i=0; i<word; ++i) {
- /*
- * Sanity check for corrupt/mismatched sound data input - avoids a seg fault
- * (As long as the calling function checks the return value!!)
- * This check should be left in even when the default Flightgear files are known
- * to be OK since it checks for mis-indexing of voice files by 3rd party developers.
- */
- if((wdptr[i].offset + wdptr[i].length) > rawDataSize) {
- SG_LOG(SG_ATC, SG_ALERT, "ERROR - mismatch between ATC .wav and .vce file in ATCVoice.cxx\n");
- SG_LOG(SG_ATC, SG_ALERT, "Offset + length: " << wdptr[i].offset + wdptr[i].length
- << " exceeds rawdata size: " << rawDataSize << endl);
- delete[] wdptr;
- dataOK = false;
- return(NULL);
- }
- memcpy(tmpbuf + bufpos, rawSoundData + wdptr[i].offset, wdptr[i].length);
- bufpos += wdptr[i].length;
+ char* data = (char*)malloc(*len);
+ if (data == 0) {
+ SG_LOG(SG_ATC, SG_ALERT, "ERROR - could not allocate " << *len << " bytes of memory for ATIS sound\n");
+ *len = 0;
+ return 0;
+ }
+
+ // randomize start position
+ unsigned int offsetIn = (unsigned int)(*len * sg_random());
+ if (offsetIn > 0 && offsetIn < *len) {
+ copy(sound.begin() + offsetIn, sound.end(), data);
+ copy(sound.begin(), sound.begin() + offsetIn, data + *len - offsetIn);
+ } else {
+ copy(sound.begin(), sound.end(), data);