Exemple #1
0
/* ChapelBase.chpl:663 */
static void init_elts4(_ddata_chpldev_Task x, int64_t s, int64_t _ln, c_string _fn) {
  range_int64_t_bounded_F call_tmp;
  _ref_range_int64_t_bounded_F ret_to_arg_ref_tmp_ = NULL;
  range_int64_t_bounded_F _ic__F0_this;
  int64_t i;
  int64_t ret;
  int64_t end;
  int64_t ret2;
  chpldev_Task this8;
  chpldev_Task wrap_call_tmp;
  int64_t call_tmp2;
  ret_to_arg_ref_tmp_ = &call_tmp;
  _build_range(INT64(1), s, ret_to_arg_ref_tmp_, _ln, _fn);
  _ic__F0_this = call_tmp;
  ret = (&_ic__F0_this)->_low;
  ret2 = (&_ic__F0_this)->_high;
  end = ret2;
  for (i = ret; ((i <= end)); i += INT64(1)) {
    (&this8)->state = taskState_pending;
    (&this8)->lineno = UINT32(0);
    (&this8)->filename = "";
    (&this8)->tl_info = UINT64(0);
    (&this8)->state = taskState_pending;
    (&this8)->lineno = UINT32(0);
    (&this8)->filename = "";
    (&this8)->tl_info = UINT64(0);
    wrap_call_tmp = _construct_chpldev_Task(taskState_pending, UINT32(0), "", UINT64(0), &this8, _ln, _fn);
    call_tmp2 = (i - INT64(1));
    *(x + call_tmp2) = wrap_call_tmp;
  }
  return;
}
Exemple #2
0
/* DSIUtil.chpl:163 */
static uint64_t intCeilXDivByY(uint64_t x, uint64_t y, int64_t _ln, c_string _fn) {
  uint64_t call_tmp;
  uint64_t call_tmp2;
  uint64_t call_tmp3;
  call_tmp = (x - UINT64(1));
  call_tmp2 = (call_tmp / y);
  call_tmp3 = (UINT64(1) + call_tmp2);
  return call_tmp3;
}
const indri::infnet::EvaluatorNode::MResults& indri::infnet::ContextSimpleCountAccumulator::getResults() {
  _results.clear();

  _results[ "collectionFrequency" ].push_back( indri::api::ScoredExtentResult( _occurrences, 0 ) );
  _results[ "collTermCnt" ].push_back( indri::api::ScoredExtentResult( _size, 0 ) );
  _results[ "docFrequency" ].push_back( indri::api::ScoredExtentResult(UINT64(_documentOccurrences), 0 ) );
  _results[ "docCnt" ].push_back( indri::api::ScoredExtentResult( UINT64(_documentCount), 0 ) );

  return _results;
}
const indri::infnet::EvaluatorNode::MResults& indri::infnet::ContextCountAccumulator::getResults() {
  // we must be finished, so now is a good time to add our results to the ListCache
  _results.clear();

  _results[ "occurrences" ].push_back( indri::api::ScoredExtentResult( _occurrences, 0 ) );
  _results[ "contextSize" ].push_back( indri::api::ScoredExtentResult( _contextSize, 0 ) );
  _results[ "documentOccurrences" ].push_back( indri::api::ScoredExtentResult(UINT64(_documentOccurrences), 0 ) );
  _results[ "documentCount" ].push_back( indri::api::ScoredExtentResult( UINT64(_documentCount), 0 ) );
   
  return _results;
}
Exemple #5
0
UINT64 stream_fill(imgtool_stream *f, unsigned char b, UINT64 sz)
{
	UINT64 outsz;
	char buf[1024];

	outsz = 0;
	memset(buf, b, std::min(sz, UINT64(sizeof(buf))));

	while(sz)
	{
		outsz += stream_write(f, buf, std::min(sz, UINT64(sizeof(buf))));
		sz -= std::min(sz, UINT64(sizeof(buf)));
	}
	return outsz;
}
UINT64 fsGetFileSize (HANDLE hFile)
{
	DWORD dw1, dw2;
	dw1 = GetFileSize (hFile, &dw2);

	return dw1 | UINT64 (dw2) << 32;
}
Exemple #7
0
int stream_seek(imgtool_stream *s, INT64 pos, int where)
{
	UINT64 size;

	size = stream_size(s);

	switch(where)
	{
		case SEEK_CUR:
			pos += s->position;
			break;
		case SEEK_END:
			pos += size;
			break;
	}

	if (pos < 0)
		s->position = 0;
	else
		s->position = std::min(size, UINT64(pos));

	if (s->position < pos)
		stream_fill(s, '\0', pos - s->position);

	return 0;
}
Exemple #8
0
fsInternetResult fsHttpFiles::LoadFile()
{
	UINT uToRead = 1000;		
	const FLOAT fInc = 1.2f;	

	fsInternetResult ir;    

	UINT64 uFileSize = m_httpFile.GetFileSize ();
	UINT64 uMax = uFileSize;	
	UINT64 uPos = 0;	
	DWORD dwRead;	

	if (uMax == _UI64_MAX)	
		uMax = 100000;		

	SAFE_DELETE_ARRAY (m_pszFileBuffer);

	fsnew (m_pszFileBuffer, char, int (uMax+1));

	int cZeroReads = 0;
	
	do
	{
		if (uToRead > uFileSize - uPos)
			uToRead = UINT (uFileSize - uPos);
		
		if (uPos + uToRead > uMax) 
		{

			
			uMax = UINT64 ((INT64)uMax * fInc);

			
			LPSTR psz = 0;
			fsnew (psz, char, int (uMax+1));
			CopyMemory (psz, m_pszFileBuffer, UINT (uPos));
			delete [] m_pszFileBuffer;
			m_pszFileBuffer = psz;
		}

		ir = m_httpFile.Read (LPBYTE (m_pszFileBuffer+uPos), uToRead, &dwRead);
		if (ir != IR_SUCCESS)
		{
			delete m_pszFileBuffer;
			return ir;
		}

		uPos += dwRead;	

		if (dwRead == 0)
		{
			cZeroReads ++;
			if (cZeroReads < 3 && uFileSize != _UI64_MAX)
				dwRead = 1; 
		}
		else
			cZeroReads = 0;   

	}
static uint64_t intCeilXDivByY_chpl(uint64_t x_chpl, uint64_t y_chpl, int64_t _ln_chpl, int32_t _fn_chpl) {
#line 118 "DSIUtil.chpl"
  uint64_t call_tmp_chpl;
#line 118 "DSIUtil.chpl"
  uint64_t call_tmp_chpl2;
#line 118 "DSIUtil.chpl"
  uint64_t call_tmp_chpl3;
#line 163 "DSIUtil.chpl"
  call_tmp_chpl = (x_chpl - UINT64(1));
#line 163 "DSIUtil.chpl"
  call_tmp_chpl2 = (call_tmp_chpl / y_chpl);
#line 163 "DSIUtil.chpl"
  call_tmp_chpl3 = (UINT64(1) + call_tmp_chpl2);
#line 163 "DSIUtil.chpl"
  return call_tmp_chpl3;
#line 163 "DSIUtil.chpl"
}
Exemple #10
0
int main()
{
    log_serial = new Serial(DEBUG_TX, DEBUG_RX);
    log_serial->baud(9600);
    DigitalIn sw2(SW2);
    DigitalIn sw3(SW3);

    for (int i = 0; i < SERVO_COUNT; i++) {
        paint_heads[i] = PAINT_NEUTRAL;
    }

    radio_init(1500);

    const uint64_t remote_addr64 = UINT64(0x0013A200, 0x40d4f162);
    const XBeeLib::RemoteXBeeZB remoteDevice = XBeeLib::RemoteXBeeZB(
            remote_addr64);

    packet pkt;
    const char *data = "what's up man?";
    strncpy((char *) &pkt.data, data, 100);
    pkt.len = strlen(data);

    radio_send(pkt);
    radio_bcast(pkt);
    radio_send(pkt, remoteDevice);

    uint8_t current_head = 0;

    log_serial->printf("Hello!\r\n");

    while (true) {
        packet pkt;
        if (radio_recv(pkt, 0)) {
            printf(
                    "\r\nGot a %s RX packet [%08lx:%08lx|%04x], "
                    "len %d\r\nData: ",
                    pkt.broadcast ? "BROADCAST" : "UNICAST",
                    uint32_t (pkt.remote_addr64 >> 32),
                    uint32_t (pkt.remote_addr64 & 0xFFFFFFFF),
                    pkt.remote_addr16,
                    pkt.len);
            printf("%.*s\r\n", pkt.len, pkt.data);
        }

        if (sw2 == 0) {
            printf("painting\r\n");
            while (sw2 == 0);
            paint_heads[current_head % SERVO_COUNT] = PAINT_SPRAY;
            wait(PAINT_TIME);
            paint_heads[current_head % SERVO_COUNT] = PAINT_NEUTRAL;
        }

        if (sw3 == 0) {
            printf("head %d\r\n", current_head);
            current_head++;
            while (sw3 == 0);
        }
    }
Exemple #11
0
inline UINT32 sample_number_to_field(const movie_info &info, UINT32 samplenum, UINT32 &offset)
{
	UINT32 guess = (UINT64(samplenum) * UINT64(info.iframerate) + (UINT64(info.samplerate) * UINT64(1000000) - 1)) / (UINT64(info.samplerate) * UINT64(1000000));
	while (1)
	{
		UINT32 fieldstart = field_to_sample_number(info, guess);
		UINT32 fieldend = field_to_sample_number(info, guess + 1);
		if (samplenum >= fieldstart && samplenum < fieldend)
		{
			offset = samplenum - fieldstart;
			return guess;
		}
		else if (samplenum < fieldstart)
			guess--;
		else
			guess++;
	}
}
Exemple #12
0
void h8_sci_device::clock_start(int mode)
{
	// Happens when back-to-back
	if(clock_state & mode)
		return;

	if(!clock_state) {
		cpu->synchronize();
		clock_state = mode;
		switch(clock_mode) {
		case CLKM_INTERNAL_ASYNC:
		case CLKM_INTERNAL_ASYNC_OUT:
		case CLKM_INTERNAL_SYNC_OUT:
			logerror("%s: Starting internal clock\n", tag());
			clock_base = cpu->get_cycle();
			cpu->internal_update();
			break;

		case CLKM_EXTERNAL_RATE_ASYNC:
			logerror("%s: Simulating external clock async\n", tag());
			clock_base = UINT64(cpu->get_cycle()*internal_to_external_ratio);
			cpu->internal_update();
			break;

		case CLKM_EXTERNAL_RATE_SYNC:
			logerror("%s: Simulating external clock sync\n", tag());
			clock_base = UINT64(cpu->get_cycle()*2*internal_to_external_ratio);
			cpu->internal_update();
			break;

		case CLKM_EXTERNAL_ASYNC:
			logerror("%s: Waiting for external clock async\n", tag());
			ext_clock_counter = 15;
			break;

		case CLKM_EXTERNAL_SYNC:
			logerror("%s: Waiting for external clock sync\n", tag());
			break;
		}
	} else
		clock_state |= mode;
}
Exemple #13
0
    UINT64 Hash64(const BYTE *k, UINT Length)
    {
        UINT a, b, c, LocalLength;

        /* Set up the internal state */
        LocalLength = Length;
        a = b = 0x9e3779b9;  /* the golden ratio; an arbitrary value */
        c = 0x9b9773e9;

        /*---------------------------------------- handle most of the key */
        while (LocalLength >= 12)
        {
            a += (k[0] + ((UINT)k[1]<<8) + ((UINT)k[2]<<16) + ((UINT)k[3]<<24));
            b += (k[4] + ((UINT)k[5]<<8) + ((UINT)k[6]<<16) + ((UINT)k[7]<<24));
            c += (k[8] + ((UINT)k[9]<<8) + ((UINT)k[10]<<16)+ ((UINT)k[11]<<24));
            HashMix(a, b, c);
            k += 12;
            LocalLength -= 12;
        }

        /*------------------------------------- handle the last 11 bytes */
        c += Length;
        switch(LocalLength)              /* all the case statements fall through */
        {
            case 11: c += ((UINT)k[10]<<24);
            case 10: c += ((UINT)k[9]<<16);
            case 9 : c += ((UINT)k[8]<<8);
        /* the first byte of c is reserved for the length */
            case 8 : b += ((UINT)k[7]<<24);
            case 7 : b += ((UINT)k[6]<<16);
            case 6 : b += ((UINT)k[5]<<8);
        case 5 : b += k[4];
            case 4 : a += ((UINT)k[3]<<24);
            case 3 : a += ((UINT)k[2]<<16);
            case 2 : a += ((UINT)k[1]<<8);
        case 1 : a += k[0];
        /* case 0: nothing left to add */
        }
        HashMix(a, b, c);
        /*-------------------------------------------- report the result */
        return UINT64(c) + UINT64(UINT64(a) << 32);
    }
Exemple #14
0
UINT64 stream_transfer(imgtool_stream *dest, imgtool_stream *source, UINT64 sz)
{
	UINT64 result = 0;
	UINT64 readsz;
	char buf[1024];

	while(sz && (readsz = stream_read(source, buf, std::min(sz, UINT64(sizeof(buf))))))
	{
		stream_write(dest, buf, readsz);
		sz -= readsz;
		result += readsz;
	}
	return result;
}
Exemple #15
0
/* ===================================================================== */
VOID DumpHistogram(std::ostream& out)
{
    const UINT64 cutoff = KnobCutoff.Value();
    const UINT64 maxlines = KnobMaxLines.Value();
    FLT64 factor = KnobDecayFactor.Value();

    out << "\033[0;0H";
    out << "\033[2J";
    out << "\033[44m";
    out << "Functions with at least " << cutoff << " invocations in the last " <<
        KnobThreshold.Value() << " calls ";
    out << "\033[0m";
    out << endl;

    
    VEC CountMap;
    
    for (ADDR_CNT_MAP::iterator bi = RtnMap.begin(); bi != RtnMap.end(); bi++)
    {
        if( bi->second < cutoff ) continue;

        CountMap.push_back(*bi);
#if 0
        out << setw(18) << (void *)(bi->first) << " " <<
            setw(10) << bi->second <<
            "   " << Target2String(bi->first) << endl;
#endif
    }

    sort( CountMap.begin(), CountMap.end(), CompareLess );
    UINT64 lines = 0;
    for (VEC::iterator bi = CountMap.begin(); bi != CountMap.end(); bi++)
    {
        out << setw(18) << (void *)(bi->first) << " " <<
            setw(10) << bi->second <<
            "   " << Target2String(bi->first) << endl;
        lines++;
        if (lines >= maxlines) break;
    }
    
    for (ADDR_CNT_MAP::iterator bi = RtnMap.begin(); bi != RtnMap.end(); bi++)
    {
        bi->second = UINT64(bi->second * factor);
    }
    
    //out << "Total Functions: " << CountMap.size() << endl;
    
}
Exemple #16
0
UINT CSupSubFile::ThreadProc()
{
	CFile f;
	if (!f.Open(m_fname, CFile::modeRead | CFile::typeBinary | CFile::shareDenyNone)) {
		return 1;
	}

	CAutoLock cAutoLock(&m_csCritSec);

	f.SeekToBegin();

	CMemFile m_sub;
	m_sub.SetLength(f.GetLength());
	m_sub.SeekToBegin();

	int len;
	BYTE buff[65536] = { 0 };
	while ((len = f.Read(buff, sizeof(buff))) > 0) {
		m_sub.Write(buff, len);
	}
	m_sub.SeekToBegin();

	WORD sync				= 0;
	USHORT size				= 0;
	REFERENCE_TIME rtStart	= 0;

	while (m_sub.GetPosition() < (m_sub.GetLength() - 10)) {
		sync = (WORD)ReadByte(&m_sub, 2);
		if (sync == 'PG') {
			rtStart = UINT64(ReadByte(&m_sub, 4) * 1000 / 9);
			m_sub.Seek(4 + 1, CFile::current);	// rtStop + Segment type
			size = ReadByte(&m_sub, 2) + 3;		// Segment size
			m_sub.Seek(-3, CFile::current);
			m_sub.Read(buff, size);
			m_pSub->ParseSample(buff, size, rtStart, 0);
		} else {
			break;
		}
	}

	m_sub.Close();

	return 0;
}
Exemple #17
0
inline UINT32 ScaledDiv( UINT32 N, UINT32 D )
{
	if (D == 0)
		return 1;
#if defined(__WXMSW__)
	UINT32 temp ;
	__asm {
		mov		eax,N
		xor		edx,edx
		shld	edx,eax,28
		shl		eax,28
		div		D
		mov		temp,eax
	}
	return temp ;
#else
	return UINT32((UINT64(N)<<28)/D);
#endif
}
Exemple #18
0
unsigned int  calc(double sample,uint64* state)
{
      int v;
      uint64  sample_int=sample*((double)(UINT64(1)<<53));
      uint32  x1=sample_int>>27;
      uint32  x2=sample_int & ((1<<27)-1);
      uint32  out;
      if ((sample>=1.0) || (sample<0.0))
      {
            // Error - bad input
            return 1;
      }
      for (v=0;v<(1<<22);v++)
      {
            *state=adv((((uint64)x1)<<22)|v);
            out=((*state)>>(48-27))&((1<<27)-1);
            if (out==x2)
            {
                   return 0;
            }
      }
      // Could not find PRNG internal state
      return 2;
}
Exemple #19
0
static bool read_avi(void *file, int frame, bitmap_yuy16 &bitmap, INT16 *lsound, INT16 *rsound, int &samples)
{
	avi_file *avifile = reinterpret_cast<avi_file *>(file);

	// read the frame
	avi_error avierr = avi_read_video_frame(avifile, frame, bitmap);
	if (avierr != AVIERR_NONE)
		return FALSE;

	// read the samples
	const avi_movie_info *aviinfo = avi_get_movie_info(avifile);
	UINT32 firstsample = (UINT64(aviinfo->audio_samplerate) * UINT64(frame) * UINT64(aviinfo->video_sampletime) + aviinfo->video_timescale - 1) / UINT64(aviinfo->video_timescale);
	UINT32 lastsample = (UINT64(aviinfo->audio_samplerate) * UINT64(frame + 1) * UINT64(aviinfo->video_sampletime) + aviinfo->video_timescale - 1) / UINT64(aviinfo->video_timescale);
	avierr = avi_read_sound_samples(avifile, 0, firstsample, lastsample - firstsample, lsound);
	avierr = avi_read_sound_samples(avifile, 1, firstsample, lastsample - firstsample, rsound);
	if (avierr != AVIERR_NONE)
		return false;
	samples = lastsample - firstsample;
	return true;
}
Exemple #20
0
/**
 * \brief This function initialize values of command Tag_Set
 */
struct Generic_Cmd *v_tag_set_create(const uint32 node_id,
		const uint16 taggroup_id,
		const uint16 tag_id,
		const uint8 data_type,
		const uint8 count,
		const void *value)
{
	int i, cmd_id;
	struct Generic_Cmd *tag_set;

	assert(count<=4);

	/* Tricky part :-) */
	cmd_id = CMD_TAG_SET_UINT8 + 4*(data_type-1) + (count-1);

	tag_set = (struct Generic_Cmd *)malloc(UINT8_SIZE +
			cmd_struct[cmd_id].size);

	if(tag_set == NULL) {
		return NULL;
	}

	tag_set->id = cmd_id;
	UINT32(tag_set->data[0]) = node_id;
	UINT16(tag_set->data[UINT32_SIZE]) = taggroup_id;
	UINT16(tag_set->data[UINT32_SIZE + UINT16_SIZE]) = tag_id;

	switch(data_type) {
	case VRS_VALUE_TYPE_UINT8:
		for(i=0; i<count; i++) {
			UINT8(tag_set->data[UINT32_SIZE + UINT16_SIZE + UINT16_SIZE + i*INT8_SIZE]) = ((uint8*)value)[i];
		}
		break;
	case VRS_VALUE_TYPE_UINT16:
		for(i=0; i<count; i++) {
			UINT16(tag_set->data[UINT32_SIZE + UINT16_SIZE + UINT16_SIZE + i*INT16_SIZE]) = ((uint16*)value)[i];
		}
		break;
	case VRS_VALUE_TYPE_UINT32:
		for(i=0; i<count; i++) {
			UINT32(tag_set->data[UINT32_SIZE + UINT16_SIZE + UINT16_SIZE  + i*INT32_SIZE]) = ((uint32*)value)[i];
		}
		break;
	case VRS_VALUE_TYPE_UINT64:
		for(i=0; i<count; i++) {
			UINT64(tag_set->data[UINT32_SIZE + UINT16_SIZE + UINT16_SIZE + i*INT64_SIZE]) = ((uint64*)value)[i];
		}
		break;
	case VRS_VALUE_TYPE_REAL16:
		for(i=0; i<count; i++) {
			REAL16(tag_set->data[UINT32_SIZE + UINT16_SIZE + UINT16_SIZE + i*REAL16_SIZE]) = ((real16*)value)[i];
		}
		break;
	case VRS_VALUE_TYPE_REAL32:
		for(i=0; i<count; i++) {
			REAL32(tag_set->data[UINT32_SIZE + UINT16_SIZE + UINT16_SIZE + i*REAL32_SIZE]) = ((real32*)value)[i];
		}
		break;
	case VRS_VALUE_TYPE_REAL64:
		for(i=0; i<count; i++) {
			REAL64(tag_set->data[UINT32_SIZE + UINT16_SIZE + UINT16_SIZE + i*REAL64_SIZE]) = ((real64*)value)[i];
		}
		break;
	case VRS_VALUE_TYPE_STRING8:
		assert((char*)value != NULL);
		{
			char *name = (char*)value;
			size_t string8_len = strlen(name);

			/* The length of the name can't be longer then 255 bytes. Crop it, when it
			 * is necessary */
			if(string8_len > VRS_STRING8_MAX_SIZE) {
				v_print_log(VRS_PRINT_WARNING, "Cropping string8 %s(length:%d) to length: %d\n",
						name, string8_len, VRS_STRING8_MAX_SIZE);
				string8_len = VRS_STRING8_MAX_SIZE;
			}
			PTR(tag_set->data[UINT32_SIZE + UINT16_SIZE + UINT16_SIZE]) = strndup(name, string8_len);
		}
		break;
	}

	return tag_set;
}
Exemple #21
0
inline UINT32 field_to_sample_number(const movie_info &info, UINT32 field)
{
	return (UINT64(info.samplerate) * UINT64(field) * UINT64(1000000) + info.iframerate - 1) / UINT64(info.iframerate);
}
Exemple #22
0
DWORD addFileToListView (HWND hDlg, WIN32_FIND_DATA* findData, UINT itemId, LVITEM* lvI)
{
	SYSTEMTIME stUTC; 
	SYSTEMTIME stLocal;
	TCHAR str1 [MAX_PATH];
	TCHAR* tmpStr1;
	
	if (lstrcmp(findData->cFileName, L".") == 0)
	{
		return FM_AFTLV_NO;
	}

	// Занести данные из findData
	lvI->lParam = (LPARAM) fmLocalAlloc (sizeof(WIN32_FIND_DATA));
	CopyMemory ((VOID*)lvI->lParam, (const VOID*) findData, sizeof (WIN32_FIND_DATA));
	
	// Создать новую строку
	lvI->iSubItem = 0;
	lvI->pszText[0] = L'\0';
	lvI->mask = LVIF_PARAM;
	SendDlgItemMessage (hDlg, itemId, LVM_INSERTITEM, (WPARAM)0, (LPARAM)lvI);
	
	
	lvI->mask = LVIF_TEXT;
	// Файл или папка
	if (findData->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
	{	
		// если папка
		lvI->iSubItem = FM_COLUMN_NAME;
		lstrcpy (lvI->pszText, findData->cFileName);
		SendDlgItemMessage(hDlg, itemId, LVM_SETITEM, (WPARAM)0, (LPARAM)lvI);
		
		lvI->iSubItem = FM_COLUMN_TYPE;
		lstrcpy (lvI->pszText, FM_DIRTYPE_STUB);
		SendDlgItemMessage(hDlg, itemId, LVM_SETITEM, (WPARAM)0, (LPARAM)lvI);
	}
	else 
	{	
		// Если файл, то тип файла
		lvI->iSubItem = FM_COLUMN_TYPE;
		tmpStr1 = lstrrchr (findData->cFileName, L'.');
		if (tmpStr1 != NULL)
		{
			++ tmpStr1;
			lstrcpy (lvI->pszText, tmpStr1);
			SendDlgItemMessage (hDlg, itemId, LVM_SETITEM, (WPARAM)0, (LPARAM)lvI);
		}
		
		// имя файла
		lvI->iSubItem = FM_COLUMN_NAME;
		lstrcpy (lvI->pszText, findData->cFileName);
		lcutrchr (lvI->pszText, L'.');
		SendDlgItemMessage(hDlg, itemId, LVM_SETITEM, (WPARAM)0, (LPARAM)lvI);

		// размер файла
		UINT64 fs = findData->nFileSizeLow | (UINT64(findData->nFileSizeHigh) << 32);
		StrFormatByteSize (LONGLONG(fs), str1, sizeof (str1) / sizeof (str1[0]));
		lvI->iSubItem = FM_COLUMN_SIZE;
		lstrcpy (lvI->pszText, str1);
		SendDlgItemMessage (hDlg, itemId, LVM_SETITEM, (WPARAM)lvI->iItem, (LPARAM)lvI);
	}

	// Дата файла или папки
	lvI->iSubItem = FM_COLUMN_DATE;
	FileTimeToSystemTime(&findData->ftLastWriteTime, &stUTC);
	SystemTimeToTzSpecificLocalTime(NULL, &stUTC, &stLocal);
	wsprintf(str1, L"%02u-%02u-%02u %02u:%02u", stLocal.wYear, stLocal.wMonth,
		stLocal.wDay, stLocal.wHour, stLocal.wMinute);
	lstrcpy (lvI->pszText, str1);
	SendDlgItemMessage (hDlg, itemId, LVM_SETITEM, (WPARAM)0, (LPARAM)lvI);
	
	return FM_AFTLV_OK;
}
Exemple #23
0
inline UINT64 ConvertToAudioTime(DWORD timestamp, UINT64 minVal)
{
    UINT val = UINT64(timestamp)*App->GetSampleRateHz()/1000;
    return MAX(val, minVal);
}
Exemple #24
0
bool MMDeviceAudioSource::GetNextBuffer(void **buffer, UINT *numFrames, QWORD *timestamp)
{
    UINT captureSize = 0;
    bool bFirstRun = true;
    HRESULT hRes;
    UINT64 devPosition, qpcTimestamp;
    LPBYTE captureBuffer;
    UINT32 numFramesRead;
    DWORD dwFlags = 0;

    while (true) {
        if (inputBufferSize >= sampleWindowSize*GetChannelCount()) {
            if (bFirstRun) {
                lastQPCTimestamp += 10;
            } else if (bIsMic && !bUseQPC) {
                captureSize = 0;
                mmCapture->GetNextPacketSize(&captureSize);

                //throws away worthless mic data that's sampling faster than the desktop buffer.
                //disgusting fix for stupid worthless mic issues.
                if (captureSize > 0) {
                    ++numTimesInARowNewDataSeen;

                    if (numTimesInARowNewDataSeen > angerThreshold) {
                        if (SUCCEEDED(mmCapture->GetBuffer(&captureBuffer, &numFramesRead, &dwFlags, &devPosition, &qpcTimestamp))) {
                            mmCapture->ReleaseBuffer(numFramesRead);
                            numTimesInARowNewDataSeen = 0;
                        }
                    }
                } else {
                    numTimesInARowNewDataSeen = 0;
                }
            }
            firstTimestamp = GetTimestamp(lastQPCTimestamp);
            break;
        }

        //---------------------------------------------------------

        hRes = mmCapture->GetNextPacketSize(&captureSize);

        if (FAILED(hRes)) {
            RUNONCE AppWarning(TEXT("MMDeviceAudioSource::GetBuffer: GetNextPacketSize failed, result = %08lX"), hRes);
            return false;
        }

        if (!captureSize)
            return false;

        //---------------------------------------------------------

        hRes = mmCapture->GetBuffer(&captureBuffer, &numFramesRead, &dwFlags, &devPosition, &qpcTimestamp);

        if (FAILED(hRes)) {
            RUNONCE AppWarning(TEXT("MMDeviceAudioSource::GetBuffer: GetBuffer failed, result = %08lX"), hRes);
            return false;
        }

        UINT totalFloatsRead = numFramesRead*GetChannelCount();

        if (bConvert) {
            if (convertBuffer.Num() < totalFloatsRead)
                convertBuffer.SetSize(totalFloatsRead);

            short *shortBuffer = (short*)captureBuffer;
            for (UINT i = 0; i < totalFloatsRead; i++)
                convertBuffer[i] = float(shortBuffer[i])*(1.0f/32767.0f);

            captureBuffer = (LPBYTE)convertBuffer.Array();
        }

        if (inputBufferSize) {
            double timeAdjust = double(inputBufferSize/GetChannelCount());
            timeAdjust /= (double(GetSamplesPerSec())*0.0000001);

            qpcTimestamp -= UINT64(timeAdjust);
        }

        qpcTimestamp /= 10000;
        lastQPCTimestamp = qpcTimestamp;

        //---------------------------------------------------------

        UINT newInputBufferSize = inputBufferSize + totalFloatsRead;
        if (newInputBufferSize > inputBuffer.Num())
            inputBuffer.SetSize(newInputBufferSize);

        mcpy(inputBuffer.Array()+inputBufferSize, captureBuffer, totalFloatsRead*sizeof(float));
        inputBufferSize = newInputBufferSize;

        mmCapture->ReleaseBuffer(numFramesRead);

        bFirstRun = false;
    }

    *numFrames = sampleWindowSize;
    *buffer = (void*)inputBuffer.Array();
    *timestamp = firstTimestamp;

    /*if (bIsMic) {
        static QWORD lastTimestamp = 0;
        if (firstTimestamp != lastTimestamp+10)
            Log(TEXT("A: %llu, difference: %llu"), firstTimestamp, firstTimestamp-lastTimestamp);

        lastTimestamp = firstTimestamp;
    }*/

    return true;
}
Exemple #25
0
int huffman_context_base::build_tree(UINT32 totaldata, UINT32 totalweight)
{
	// make a list of all non-zero nodes
	std::vector<node_t *> list(m_numcodes * 2);
	int listitems = 0;
	memset(m_huffnode, 0, m_numcodes * sizeof(m_huffnode[0]));
	for (int curcode = 0; curcode < m_numcodes; curcode++)
		if (m_datahisto[curcode] != 0)
		{
			list[listitems++] = &m_huffnode[curcode];
			m_huffnode[curcode].m_count = m_datahisto[curcode];
			m_huffnode[curcode].m_bits = curcode;

			// scale the weight by the current effective length, ensuring we don't go to 0
			m_huffnode[curcode].m_weight = UINT64(m_datahisto[curcode]) * UINT64(totalweight) / UINT64(totaldata);
			if (m_huffnode[curcode].m_weight == 0)
				m_huffnode[curcode].m_weight = 1;
		}
/*
        fprintf(stderr, "Pre-sort:\n");
        for (int i = 0; i < listitems; i++) {
            fprintf(stderr, "weight: %d code: %d\n", list[i]->m_weight, list[i]->m_bits);
        }
*/
	// sort the list by weight, largest weight first
	qsort(&list[0], listitems, sizeof(list[0]), tree_node_compare);
/*
        fprintf(stderr, "Post-sort:\n");
        for (int i = 0; i < listitems; i++) {
            fprintf(stderr, "weight: %d code: %d\n", list[i]->m_weight, list[i]->m_bits);
        }
        fprintf(stderr, "===================\n");
*/
	// now build the tree
	int nextalloc = m_numcodes;
	while (listitems > 1)
	{
		// remove lowest two items
		node_t &node1 = *list[--listitems];
		node_t &node0 = *list[--listitems];

		// create new node
		node_t &newnode = m_huffnode[nextalloc++];
		newnode.m_parent = nullptr;
		node0.m_parent = node1.m_parent = &newnode;
		newnode.m_weight = node0.m_weight + node1.m_weight;

		// insert into list at appropriate location
		int curitem;
		for (curitem = 0; curitem < listitems; curitem++)
			if (newnode.m_weight > list[curitem]->m_weight)
			{
				memmove(&list[curitem+1], &list[curitem], (listitems - curitem) * sizeof(list[0]));
				break;
			}
		list[curitem] = &newnode;
		listitems++;
	}

	// compute the number of bits in each code, and fill in another histogram
	int maxbits = 0;
	for (int curcode = 0; curcode < m_numcodes; curcode++)
	{
		node_t &node = m_huffnode[curcode];
		node.m_numbits = 0;
		node.m_bits = 0;

		// if we have a non-zero weight, compute the number of bits
		if (node.m_weight > 0)
		{
			// determine the number of bits for this node
			for (node_t *curnode = &node; curnode->m_parent != nullptr; curnode = curnode->m_parent)
				node.m_numbits++;
			if (node.m_numbits == 0)
				node.m_numbits = 1;

			// keep track of the max
			maxbits = MAX(maxbits, node.m_numbits);
		}
	}
	return maxbits;
}
void vmsTrafficUsageModeMgr::ProcessManageForSpeedItems_updateSpeeds(bool bForDownload)
{
	LOGFN ("vmsTrafficUsageModeMgr::ProcessManageForSpeedItems_updateSpeeds");

	UINT64 uTotalInternetSpeed = 0;
	bool bAtLeast1UsesInternet = false;

	for (size_t i = 0; i < m_vpManageForSpeed.size (); i++)
	{
		ManageForSpeedItemsList *pList = m_vpManageForSpeed [i];

		UINT64 uListTotalInternetSpeed = 0;

		for (size_t j = 0; j < pList->vItems.size (); j++)
		{
			ManageForSpeedItem *pItem = &pList->vItems [j];
			if (pItem->pDldr->isRequiresTraffic (bForDownload))
			{
				UINT64 uSpeed = pItem->pDldr->getSpeed (bForDownload);
				pItem->getData (bForDownload).vSpeed.AddValue (uSpeed);

				if (pItem->pDldr->isInternetTraffic (bForDownload))
				{
					bAtLeast1UsesInternet = true;
					uListTotalInternetSpeed += uSpeed;
				}				
			}
			else
			{
				if (!pItem->getData (bForDownload).vSpeed.empty ())
					pItem->getData (bForDownload).vSpeed.clear ();				
			}
		}

		pList->vTotalSpeed.AddValue (uListTotalInternetSpeed);
		uTotalInternetSpeed += uListTotalInternetSpeed;
	}

	NetworkStat& ns = refgetNetworkStat (bForDownload);

	if (m_enCurrentTUM != TUM_HEAVY)
	{
		ns.tcTrafficGoesInHeavyModeFrom = 0;
	}
	else
	{
		if (!uTotalInternetSpeed)
		{
			ns.tcTrafficGoesInHeavyModeFrom = 0;
		}
		else
		{
			UINT64 tcNow = vmsTickCount::GetTickCount64 ();
			if (!ns.tcTrafficGoesInHeavyModeFrom)
				ns.tcTrafficGoesInHeavyModeFrom = tcNow;
			if (tcNow - ns.tcTrafficGoesInHeavyModeFrom > 3*60*1000)
				ns.tcHeavyModeWorkedEnoughUntil = tcNow;
		}
	}

	vmsAUTOLOCKSECTION (m_csMisc);
	if (bAtLeast1UsesInternet)
		ns.vTotalSpeed.AddValue (uTotalInternetSpeed);

	UINT64 uTotalMaxSpeed = ns.vTotalSpeed.getMaximumValue ();

	if (uTotalMaxSpeed != UINT64_MAX)
	{
		if (ns.uConnectionBandwidth == UINT64_MAX)
		{
			if (uTotalMaxSpeed > ns.bandwidthMeasureStart.uMaxValue)
			{
				if (uTotalMaxSpeed > UINT64 (ns.bandwidthMeasureStart.uMaxValue*1.1))
					ns.bandwidthMeasureStart.cNonZeroTotalSpeeds = 0; 
				ns.bandwidthMeasureStart.uMaxValue = uTotalMaxSpeed;
			}
			if (uTotalMaxSpeed)
				ns.bandwidthMeasureStart.cNonZeroTotalSpeeds++;
			if (ns.bandwidthMeasureStart.cNonZeroTotalSpeeds >= 10)
				ns.uConnectionBandwidth = ns.bandwidthMeasureStart.uMaxValue;
		}
		else if (ns.uConnectionBandwidth < uTotalMaxSpeed)
		{
			ns.uConnectionBandwidth = uTotalMaxSpeed;
		}
	}
}
Exemple #27
0
uint64 adv(uint64 x)
{
      return (a*x+b) & ((UINT64(1)<<48)-1);
}
Exemple #28
0
UINT64 h8_sci_device::internal_update(UINT64 current_time)
{
	UINT64 event = 0;
	switch(clock_mode) {
	case CLKM_INTERNAL_SYNC_OUT:
		if(clock_state || !clock_value) {
			UINT64 fp = divider*2;
			if(current_time >= clock_base) {
				UINT64 delta = current_time - clock_base;
				if(delta >= fp) {
					delta -= fp;
					clock_base += fp;
				}
				assert(delta < fp);

				bool new_clock = delta >= divider;
				if(new_clock != clock_value) {
					cpu->synchronize();
					if((!new_clock) && (clock_state & CLK_TX))
						tx_dropped_edge();

					else if(new_clock && (clock_state & CLK_RX))
						rx_raised_edge();

					clock_value = new_clock;
					if(clock_state || clock_value)
						clk_cb(clock_value);
				}
			}
			event = clock_base + (clock_value ? fp : divider);
		}
		break;

	case CLKM_INTERNAL_ASYNC:
	case CLKM_INTERNAL_ASYNC_OUT:
		if(clock_state || !clock_value) {
			UINT64 fp = divider*16;
			if(current_time >= clock_base) {
				UINT64 delta = current_time - clock_base;
				if(delta >= fp) {
					delta -= fp;
					clock_base += fp;
				}
				assert(delta < fp);
				bool new_clock = delta >= divider*8;
				if(new_clock != clock_value) {
					cpu->synchronize();
					if((!new_clock) && (clock_state & CLK_TX))
						tx_dropped_edge();

					else if(new_clock && (clock_state & CLK_RX))
						rx_raised_edge();

					clock_value = new_clock;
					if(clock_mode == CLKM_INTERNAL_ASYNC_OUT && (clock_state || !clock_value))
						clk_cb(clock_value);
				}
			}

			event = clock_base + (clock_value ? fp : divider*8);
		}
		break;

	case CLKM_EXTERNAL_RATE_SYNC:
		if(clock_state || !clock_value) {
			UINT64 ctime = UINT64(current_time*internal_to_external_ratio*2);
			if(ctime >= clock_base) {
				UINT64 delta = ctime - clock_base;
				clock_base += delta & ~1;
				delta &= 1;
				bool new_clock = delta >= 1;
				if(new_clock != clock_value) {
					cpu->synchronize();
					if((!new_clock) && (clock_state & CLK_TX))
						tx_dropped_edge();

					else if(new_clock && (clock_state & CLK_RX))
						rx_raised_edge();

					clock_value = new_clock;
				}
			}

			event = UINT64((clock_base + (clock_value ? 2 : 1))*external_to_internal_ratio)+1;
		}
		break;

	case CLKM_EXTERNAL_RATE_ASYNC:
		if(clock_state || !clock_value) {
			UINT64 ctime = UINT64(current_time*internal_to_external_ratio);
			if(ctime >= clock_base) {
				UINT64 delta = ctime - clock_base;
				clock_base += delta & ~15;
				delta &= 15;
				bool new_clock = delta >= 8;
				if(new_clock != clock_value) {
					cpu->synchronize();
					if((!new_clock) && (clock_state & CLK_TX))
						tx_dropped_edge();

					else if(new_clock && (clock_state & CLK_RX))
						rx_raised_edge();

					clock_value = new_clock;
				}
			}

			event = UINT64((clock_base + (clock_value ? 16 : 8))*external_to_internal_ratio)+1;
		}
		break;

	case CLKM_EXTERNAL_ASYNC:
	case CLKM_EXTERNAL_SYNC:
		break;;
	}
	if(event) {
		attotime ctime = machine().time();
		attotime sync_time = attotime::from_ticks(event-10, cpu->clock());
		if(cur_sync_time != sync_time && sync_time > ctime) {
			sync_timer->adjust(sync_time - ctime);
			cur_sync_time = sync_time;
		}
	}

	return event;
}
Exemple #29
0
UINT64 RangeCheck::HashCode(unsigned lclNum, unsigned ssaNum)
{
    assert(ssaNum != SsaConfig::RESERVED_SSA_NUM);
    return UINT64(lclNum) << 32 | ssaNum;
}
Exemple #30
0
static imgtoolerr_t rsdos_diskimage_writefile(imgtool_partition *partition, const char *fname, const char *fork, imgtool_stream *sourcef, util::option_resolution *writeoptions)
{
    floperr_t ferr;
    imgtoolerr_t err;
    imgtool_image *img = imgtool_partition_image(partition);
    struct rsdos_dirent ent, ent2;
    size_t i;
    UINT64 sz;
    UINT64 freespace = 0;
    unsigned char g;
    unsigned char *gptr;
    UINT8 granule_count;
    UINT8 granule_map[MAX_GRANULEMAP_SIZE];

    /* can we write to this image? */
    if (floppy_is_read_only(imgtool_floppy(img)))
        return IMGTOOLERR_READONLY;

    err = rsdos_diskimage_freespace(partition, &freespace);
    if (err)
        return err;

    /* is there enough space? */
    sz = stream_size(sourcef);
    if (sz > freespace)
        return IMGTOOLERR_NOSPACE;

    /* setup our directory entry */
    err = prepare_dirent(&ent, fname);
    if (err)
        return err;

    ent.ftype = writeoptions->lookup_int(RSDOS_OPTIONS_FTYPE);
    ent.asciiflag = UINT8(writeoptions->lookup_int(RSDOS_OPTIONS_ASCII)) - 1;
    ent.lastsectorbytes_lsb = sz % 256;
    ent.lastsectorbytes_msb = (((sz % 256) == 0) && (sz > 0)) ? 1 : 0;
    gptr = &ent.first_granule;

    ferr = get_granule_map(img, granule_map, &granule_count);
    if (ferr)
        return imgtool_floppy_error(ferr);

    g = 0x00;

    do
    {
        while (granule_map[g] != 0xff)
        {
            g++;
            if ((g >= granule_count) || (g == 0))
                return IMGTOOLERR_UNEXPECTED;   /* We should have already verified that there is enough space */
        }
        *gptr = g;
        gptr = &granule_map[g];


        i = std::min(sz, UINT64(9*256));
        err = transfer_to_granule(img, g, i, sourcef);
        if (err)
            return err;

        sz -= i;

        /* Go to next granule */
        g++;
    }
    while(sz > 0);

    /* Now that we are done with the file, we need to specify the final entry
     * in the file allocation table
     */
    *gptr = 0xc0 + ((i + 255) / 256);

    /* Now we need to find an empty directory entry */
    i = -1;
    do
    {
        ferr = get_rsdos_dirent(img, ++i, &ent2);
        if (ferr)
            return imgtool_floppy_error(ferr);
    }
    while((ent2.fname[0] != '\0') && strcmp(ent.fname, ent2.fname) && (ent2.fname[0] != -1));

    /* delete file if it already exists */
    if (ent2.fname[0] && (ent2.fname[0] != -1))
    {
        err = delete_entry(img, &ent2, i);
        if (err)
            return err;
    }

    ferr = put_rsdos_dirent(img, i, &ent);
    if (ferr)
        return imgtool_floppy_error(ferr);

    /* write the granule map back out */
    ferr = put_granule_map(img, granule_map, granule_count);
    if (ferr)
        return imgtool_floppy_error(ferr);

    return IMGTOOLERR_SUCCESS;
}