void XMLSoundDefParser::parseScript(Ogre::DataStreamPtr stream)
{
	TiXmlDocument xmlDoc;
	XMLHelper xmlHelper;
	if (!xmlHelper.Load(xmlDoc, stream)) 
	{
		return;
	}

	TiXmlElement* rootElem = xmlDoc.RootElement();

	if (rootElem) {
		for (TiXmlElement* smElem = rootElem->FirstChildElement();
				smElem != 0; smElem = smElem->NextSiblingElement())
		{
			const char* tmp =  smElem->Attribute("name");
			if (!tmp)
			{
				continue;
			}
	
			std::string finalName(tmp);
	
			SoundGroupDefinition* newModel = mManager.createSoundGroupDefinition(finalName);
				
			if (newModel)
			{
				S_LOG_INFO("Sound Model " << finalName << " created.");
	
				readBuffers(newModel, smElem);
			}
		}
	}
}
Beispiel #2
0
void QHexEdit::adjust()
{
    // recalc Graphics
    if (_addressArea)
    {
        _addrDigits = addressWidth();
        _pxPosHexX = _pxGapAdr + _addrDigits*_pxCharWidth + _pxGapAdrHex;
    }
    else
        _pxPosHexX = _pxGapAdrHex;
    _pxPosAdrX = _pxGapAdr;
    _pxPosAsciiX = _pxPosHexX + HEXCHARS_IN_LINE * _pxCharWidth + _pxGapHexAscii;

    // set horizontalScrollBar()
    int pxWidth = _pxPosAsciiX;
    if (_asciiArea)
        pxWidth += BYTES_PER_LINE*_pxCharWidth;
    horizontalScrollBar()->setRange(0, pxWidth - viewport()->width());
    horizontalScrollBar()->setPageStep(viewport()->width());

    // set verticalScrollbar()
    _rowsShown = ((viewport()->height()-4)/_pxCharHeight);
    int lineCount = (int)(_chunks->size() / (qint64)BYTES_PER_LINE) + 1;
    verticalScrollBar()->setRange(0, lineCount - _rowsShown);
    verticalScrollBar()->setPageStep(_rowsShown);

    int value = verticalScrollBar()->value();
    _bPosFirst = (qint64)value * BYTES_PER_LINE;
    _bPosLast = _bPosFirst + (qint64)(_rowsShown * BYTES_PER_LINE) - 1;
    if (_bPosLast >= _chunks->size())
        _bPosLast = _chunks->size() - 1;
    readBuffers();
    setCursorPosition(_cursorPosition);
}
Beispiel #3
0
void QHexEdit::refresh(bool showCursor)
{
    if (showCursor)
        ensureVisible();
    readBuffers();
    viewport()->update();
}
Beispiel #4
0
int FileDecoder::Read(char *outBuffer, size_t size, off_t offset)
{
    if (offset >= Size())
        return 0;

    unsigned int sharesRequired = fecWrapper.GetSharesRequired();
    // read some more in case size is not a multiple of required
    int bytesToRead = (size + sharesRequired - 1) / sharesRequired + 1;
    int minBytesRead = bytesToRead;

    // TODO better to have only one vector? - avoid re-allocating the vectors
    std::vector<std::vector<char> >& readBuffers(threadLocalData.Get().readBuffers);
    readBuffers.resize(sharesRequired);
    for (unsigned int i = 0; i < sharesRequired; ++i) {
        readBuffers[i].resize(bytesToRead);
        int bytesRead = encodedFiles[i]->Read(readBuffers[i].data(), bytesToRead,
                                             offset / sharesRequired + Metadata::size);
        minBytesRead = std::min(minBytesRead, bytesRead);
    }
    if (minBytesRead == 0)
        return 0;

    std::vector<const char*> fecInputPtrs(sharesRequired);
    std::vector<unsigned int> fecInputIndices(fileIndices.begin(), fileIndices.end());
    for (unsigned int i = 0; i < sharesRequired; ++i)
        fecInputPtrs[i] = readBuffers[i].data();

    NormalizeIndices(fecInputPtrs, fecInputIndices);

    std::vector<char>& workBuffer(threadLocalData.Get().workBuffer);
    workBuffer.resize(minBytesRead * sharesRequired);
    std::vector<char*> fecOutputPtrs(sharesRequired);
    for (unsigned int i = 0; i < sharesRequired; ++i)
        fecOutputPtrs[i] = workBuffer.data() + i * minBytesRead;

    fecWrapper.Decode(fecOutputPtrs.data(), fecInputPtrs.data(),
                      fecInputIndices.data(), minBytesRead);

    unsigned int offsetCorrection = offset % sharesRequired;

    size = std::min<size_t>(std::min<size_t>(size, minBytesRead * sharesRequired - offsetCorrection), Size() - offset);
    for (unsigned int i = 0; i < sharesRequired; ++i) {
        const char* decoded = fecInputIndices[i] < sharesRequired ? fecInputPtrs[i] : fecOutputPtrs[i];
        char* out = outBuffer + i - offsetCorrection;
        if (i < offsetCorrection) {
            out += sharesRequired;
            ++decoded;
        }
        CopyToNthElement(out, outBuffer + size, decoded, sharesRequired);
    }
    return size;
}
Beispiel #5
0
void QHexEdit::refresh()
{
    ensureVisible();
    readBuffers();
}
Beispiel #6
0
//Run the CL kernel
//Handles buffer IO
void runCLKernelsWithIO(void)
{
	size_t globalThreads[1];
	size_t localThreads[1];
		
	localThreads[0]= threadsPerWorkgroup;  
		
	//Break up kernel execution to 1 exec per WORK_ITEM_LIMIT work items.
	cl_uint remainingWidth = paddedWidth;
	cl_uint offset = 0;
	cl_event exec_events[1];//An event that tracks kernel execution
		
	while(remainingWidth > WORK_ITEM_LIMIT)
	{	  
	  
	  writeBuffers(offset,WORK_ITEM_LIMIT);
	  //Enqueue a kernel run call.	
	  globalThreads[0] = WORK_ITEM_LIMIT;
	  
	  status = clEnqueueNDRangeKernel(
		  commandQueue,
		  kernel,
		  1,
		  NULL,
		  globalThreads,
		  localThreads,
		  0,
		  NULL,
		  &exec_events[0]);
	  if(status != CL_SUCCESS) exitOnError("Enqueueing kernel onto command queue.(clEnqueueNDRangeKernel)"); 

	
	  status = clWaitForEvents(1,&exec_events[0]);
	  if(status != CL_SUCCESS) exitOnError("Waiting for kernel run to finish.(clWaitForEvents)");
	  
	  readBuffers(offset,WORK_ITEM_LIMIT);
	
	remainingWidth -= WORK_ITEM_LIMIT;
	offset += WORK_ITEM_LIMIT;
	  
	}
		
	//Final kernel run call for remaining work_items
	globalThreads[0] = remainingWidth;
	
	writeBuffers(offset,remainingWidth);
		
	status = clEnqueueNDRangeKernel(
		commandQueue,
		kernel,
		1,
		NULL,
		globalThreads,
		localThreads,
		0,
		NULL,
		&exec_events[0]);
	if(status != CL_SUCCESS) exitOnError("Enqueueing kernel onto command queue.(clEnqueueNDRangeKernel)"); 

	
	status = clWaitForEvents(1,&exec_events[0]);
	if(status != CL_SUCCESS) exitOnError("Waiting for kernel run to finish.(clWaitForEvents)");
	
	readBuffers(offset,remainingWidth);
	
	status = clReleaseEvent(exec_events[0]);
	if(status != CL_SUCCESS) exitOnError("Releasing event object exec_events[0].(clWaitForEvents)");

}
Beispiel #7
0
void run_mem_decoder(short * buf, int len,int max_buf_len)
{	
	int offset=0;
	int bytes_in_len=len*channels;
	char * p=(char *) buf;
//      rtlsdr_dev_t *dev ;
//      int ppm_error ;

	while(bytes_in_len > max_buf_len )
	{
		memcpy(buffer,p+offset,max_buf_len);
		buffer_read=max_buf_len/(channels*sizeof(short));
		bytes_in_len-=max_buf_len;
		offset+=max_buf_len;
		readBuffers();
	}
	memcpy(buffer,p+offset,bytes_in_len);
	buffer_read=bytes_in_len/(channels*sizeof(short));
	readBuffers();
	
	if(time_print_stats && (time(NULL)-tprev >= time_print_stats))
	{
		struct demod_state_t *d = rx_a->decoder;
		tprev=time(NULL);
		fprintf(stderr,
				"A: Received correctly: %d packets, wrong CRC: %d packets, wrong size: %d packets\n",
				d->receivedframes, d->lostframes,
				d->lostframes2);
		d = rx_b->decoder;
			fprintf(stderr,
				"B: Received correctly: %d packets, wrong CRC: %d packets, wrong size: %d packets\n",
				d->receivedframes, d->lostframes,
				d->lostframes2);
	}
// 	Do auto tuning. Checking both channels at regular intervals and calc the
// 	percentage of correct received messages. At correct tuning this should be 
// 	for both channels more ore less equal
	

	if(ppm_auto_time && (time(NULL)-tprev_ppm >= ppm_auto_time))
    {
        struct demod_state_t *da = rx_a->decoder;
        struct demod_state_t *db = rx_b->decoder;

                
        int rx_a_frames = da->receivedframes - prev_a_receivedframes;
        int rx_a_lostframes = da->lostframes - prev_a_lostframes;
        int rx_a_lostframes2 = da->lostframes2 - prev_a_lostframes2;
        int rx_b_frames = db->receivedframes - prev_b_receivedframes;
        int rx_b_lostframes = db->lostframes - prev_b_lostframes;
        int rx_b_lostframes2 = db->lostframes2 - prev_b_lostframes2;
        // check if enough messages are received to do a decent check
        if ( ( rx_a_frames + rx_b_frames ) >= 10 ) 
        {
            //save values for next calculation
            prev_a_receivedframes = da->receivedframes;
            prev_a_lostframes =  da->lostframes;
            prev_a_lostframes2 = da->lostframes2;
            prev_b_receivedframes = db->receivedframes;
            prev_b_lostframes =  db->lostframes;
            prev_b_lostframes2 = db->lostframes2;
            int perc_a;
            int perc_b;
            if ( (rx_a_frames + rx_a_lostframes + rx_a_lostframes2 ) == 0 )
                perc_a = 0;
            else
                perc_a = (int)(rx_a_frames * 100 / ( rx_a_frames + rx_a_lostframes + rx_a_lostframes2 )) ;
            if ( rx_b_frames + rx_b_lostframes + rx_b_lostframes2 == 0 )
                perc_b = 0;
            else
                perc_b = (int)(rx_b_frames * 100 / ( rx_b_frames + rx_b_lostframes + rx_b_lostframes2 ))  ;
            
            int fr_p_min = (int)( rx_a_frames + rx_b_frames )*60 / (time(NULL)-tprev_ppm);
             
            int ppm_corr = (int) round((perc_b - perc_a)/10);
            if (ppm_corr > 3) ppm_corr = 3;
            if (ppm_corr < -3) ppm_corr = -3;
            if ( ppm_corr != 0 )
            {   
                ppm_error = ppm_error + ppm_corr;
                verbose_ppm_set(dev, ppm_error);
            }
            else
                ppm_auto_time = ppm_auto_time * 2;
            if ( ppm_auto_time > 300 )
                ppm_auto_time = 300;
                
            //if(time_print_stats)
                fprintf(stderr,"Sentences per minuut %i, quality Ch.A %i%% Ch.B %i%% ppm error set to %i \n", fr_p_min, perc_a, perc_b, ppm_error );
            
            tprev_ppm=time(NULL);            
        }
        //int curr_ppm=
    }
}
Beispiel #8
0
void runSoundDecoder(int *stop) {
    while (!*stop) {
        buffer_read = fread(buffer, channels * sizeof(short), buffer_l, fp);
        readBuffers();
    }
}