Exemplo n.º 1
0
//*****************************************************************************
bool CCreditsScreen::OnQuit()
//Called when SDL_QUIT event is received.
//Returns whether Quit action was confirmed.
{
	//Pause action while the "Really quit?" dialog is activated.
	const bool bWasPaused = this->bPaused;
	if (!bWasPaused)
	{
		this->bPaused = true;
		SetRate(0);
	}

	const bool bQuit = CScreen::OnQuit(); //no sell screen

	if (!bWasPaused)
	{
		this->bPaused = false;
		SetRate(this->fScrollRateMultiplier);
	} else {
		//redraw screen parts
		PaintChildren();
		UpdateRect();
	}

	return bQuit;
}
Exemplo n.º 2
0
bool FGUDPInputSocket::Load(Element* el)
{
  if (!FGInputType::Load(el))
    return false;
   
  rate = atoi(el->GetAttributeValue("rate").c_str());
  SetRate(0.5 + 1.0/(FDMExec->GetDeltaT()*rate));
   
  SockPort = atoi(el->GetAttributeValue("port").c_str());
  if (SockPort == 0) {
    cerr << endl << "No port assigned in input element" << endl;
    return false;
  }
  
  Element *property_element = el->FindElement("property");

  while (property_element) {
    string property_str = property_element->GetDataLine();
    FGPropertyNode* node = PropertyManager->GetNode(property_str);
    if (!node) {
      cerr << fgred << highint << endl << "  No property by the name "
           << property_str << " can be found." << reset << endl;
    } else {
      InputProperties.push_back(node);
    }
    property_element = el->FindNextElement("property");
  }

  return true;
}
Exemplo n.º 3
0
STDMETHODIMP CStreamSwitcherPassThru::SetRate(double dRate)
{
    if (0.0 == dRate) {
        return E_INVALIDARG;
    }
    CallPeerSeekingAll(SetRate(dRate));
}
Exemplo n.º 4
0
void RRCSAccelerometer::Init() {
    gpio115_st_ = new mraa::Gpio(MRAA_INTEL_EDISON_GP115);
    if (gpio115_st_ == NULL) {
        std::cout << "count not create GPIO(115 mraa == 11)" << std::endl;
        mraa::printError(mraa::ERROR_UNSPECIFIED);
    }
    mraa::Result response = gpio115_st_->dir(mraa::DIR_OUT);
    if (response != mraa::SUCCESS) {
        mraa::printError(response);
    }
    response = gpio115_st_->mode(mraa::MODE_STRONG);
    if (response != mraa::SUCCESS) {
        mraa::printError(response);
    }
    response = gpio115_st_->write(0);
    if (response != mraa::SUCCESS) {
        mraa::printError(response);
    }

    adc_ = new upm::ADS1015(1, 0x48);
    adc_->setContinuous(false);
    adc_->setSPS(upm::ADS1015::SPS_3300);
    adc_->setGain(upm::ADS1X15::GAIN_ONE);
    acc_ = new upm::ADXL377(adc_);
    acc_->calibrate();

    SetRate(std::chrono::milliseconds(RRCS_ACCELERATION_PERIOD_MS));
}
Exemplo n.º 5
0
// ---------------------------------------------------------------------------
//	初期化
//
bool X68PCM8::Init(uint rate)
{
	mMask = 0;
	mVolume = 256;
	for (int i=0; i<PCM8_NCH; ++i) {
		mPcm8[i].Init();
	}

	OutInpAdpcm[0] = OutInpAdpcm[1] =
	  OutInpAdpcm_prev[0] = OutInpAdpcm_prev[1] =
	  OutInpAdpcm_prev2[0] = OutInpAdpcm_prev2[1] =
	  OutOutAdpcm[0] = OutOutAdpcm[1] =
	  OutOutAdpcm_prev[0] = OutOutAdpcm_prev[1] =
	  OutOutAdpcm_prev2[0] = OutOutAdpcm_prev2[1] =
	  0;
	OutInpOutAdpcm[0] = OutInpOutAdpcm[1] =
	  OutInpOutAdpcm_prev[0] = OutInpOutAdpcm_prev[1] =
	  OutInpOutAdpcm_prev2[0] = OutInpOutAdpcm_prev2[1] =
	  OutOutInpAdpcm[0] = OutOutInpAdpcm[1] =
	  OutOutInpAdpcm_prev[0] = OutOutInpAdpcm_prev[1] =
	  0;

	SetRate(rate);

	return true;
}
Exemplo n.º 6
0
void SelectionBar::SetListener(SelectionBarListener *l)
{
   mListener = l;
   SetRate(mListener->AS_GetRate());
   SetSnapTo(mListener->AS_GetSnapTo());
   SetSelectionFormat(mListener->AS_GetSelectionFormat());
};
Exemplo n.º 7
0
bool FGOutput::Load(int subSystems, std::string protocol, std::string  type, std::string port, std::string name, double outRate, std::vector<FGPropertyManager *> & outputProperties)
{
  SetType(type);
  SetRate(outRate);
  SubSystems = subSystems;
  OutputProperties = outputProperties;

  if (((Type == otCSV) || (Type == otTab)) && (name != "cout") && (name !="COUT"))
    name = FDMExec->GetRootDir() + name;

  if (!port.empty() && (Type == otSocket || Type == otFlightGear)) {
    SetProtocol(protocol);
    socket = new FGfdmSocket(name, atoi(port.c_str()), Protocol);
  } else {
    BaseFilename = Filename = name;
  }

  if (Type == otMAVLink)
  {
    mavlink = new FGMAVLink(0,0,MAV_TYPE_GENERIC,"/dev/ttyUSB0",115200);
  }

  Debug(2);
  return true;
}
Exemplo n.º 8
0
void NES_FDS::SetOption (int id, int val)
{
    if(id<OPT_END) option[id] = val;

    // update cutoff immediately
    if (id == OPT_CUTOFF) SetRate(rate);
}
Exemplo n.º 9
0
//*****************************************************************************************
void CCreditsScreen::OnKeyDown(
//
//Params:
	const UINT dwTagNo, const SDL_KeyboardEvent &Key)
{ 
	HideCursor();

	CScreen::OnKeyDown(dwTagNo,Key); //For alt-F4, F10, etc.
	if (IsDeactivating()) {ShowCursor(); return;}

	 //Ignore control keys below if song is playing.
	 if (!this->pScrollingText->IsVisible()) return;

	//Check for other keys.
	switch (Key.keysym.sym)
	{
		case SDLK_PAUSE:
			//pause animation
			this->bPaused = true;
			SetRate(0);
			break;
		case SDLK_SPACE:
			//toggle pause animation unless song is playing.
			this->bPaused = !this->bPaused;
			SetRate(this->bPaused ? 0 : this->fScrollRateMultiplier);
			break;
		case SDLK_KP2: case SDLK_DOWN:
			//increase scroll rate
			this->bPaused = false;
			if (this->fScrollRateMultiplier < 5.0f) this->fScrollRateMultiplier += 0.10f;
			SetRate(this->fScrollRateMultiplier);
			break;
		case SDLK_KP8: case SDLK_UP:
			//slow scroll rate
			this->bPaused = false;
			if (this->fScrollRateMultiplier > 0.15f) this->fScrollRateMultiplier -= 0.10f;
			SetRate(this->fScrollRateMultiplier);
			break;
		default:
			//unpause
			this->bPaused = false;
			SetRate(this->fScrollRateMultiplier);
			break;
	}
}
Exemplo n.º 10
0
int EncoderMFC::Initialize(int width, int height,int codec,float rate,int bitrate,int in_bufs,int out_bufs, int stream_b_size){

    if(state!=MFC_ST_OPEN)
        return -1;

    if(SetFormat(width,height)<0)
        return -1;

    if(SetCodec(codec,stream_b_size)<0)
        return -1;

    SetRate(rate);

    if(bitrate>0)
        SetBitRate(bitrate);

    if(InitBuffers(DIR_IN,in_bufs)<0)
        return -1;

    if(InitBuffers(DIR_OUT,out_bufs)<0)
        return -1;


    for (int bi=0;bi<out_bufs;bi++){


        struct v4l2_buffer buf;
        struct v4l2_plane planes[MFC_MAX_PLANES];

        buf.type = io_dir_to_type(DIR_OUT);
        buf.memory = V4L2_MEMORY_MMAP;
        buf.m.planes = planes;
        buf.length = NPPBuf[DIR_OUT];

        buf.index=bi;


        for (u_int i = 0; i < NPPBuf[DIR_OUT]; i++){
            planes[i].length=PlanesLen[DIR_OUT][i];
            planes[i].bytesused=0;
            planes[i].m.userptr=(u_long)BufAddr[DIR_OUT][bi][i];
        }

        int ret = ioctl(fd, VIDIOC_QBUF, &buf);
        if (ret != 0) {
            printf("\nEncoderMFC: Init, Queue buffer %d error! %s\n",buf.index,strerror(errno));
        }

    }

    BufInx[DIR_OUT]=0;

    state=MFC_ST_OK;
    return 0;

}
bool RageSoundReader_Resample_Good::SetProperty( const RString &sProperty, float fValue )
{
	if( sProperty == "Rate" )
	{
		SetRate( fValue );
		return true;
	}

	return m_pSource->SetProperty( sProperty, fValue );
}
Exemplo n.º 12
0
Channel::Channel()
{
	resampler = 0;
	SetRate(1);
	SetVolume(SDL_MIX_MAXVOLUME);
	oldvolume = 0;
	SetPan(0.5f);
	done = true;
	stopping = false;
	stream = 0;
}
Exemplo n.º 13
0
//************************************************************************************
CCreditsScreen::CCreditsScreen()
	: CDrodScreen(SCR_Credits)
	, pScrollingText(NULL)
//Constructor.
{
	this->imageFilenames.push_back(string("Credits"));

	this->pScrollingText = new CScrollingTextWidget(0L, X_CREDITS, Y_CREDITS, 
			CX_CREDITS, CY_CREDITS);
	AddWidget(this->pScrollingText);
	SetRate(CCreditsScreen::fScrollRateMultiplier);
}
Exemplo n.º 14
0
/* Our own loadcheck which will use fixed 3.0x clock for player
   and 4.0x for USB. */
void MyLoadCheck(struct CodecServices *cs, s_int16 n) {
  if (cs == NULL) {
    if (n) {
	if (clockX != 8) {
	    clockX = 8; /* USB requires 4.0x! */
	    SetRate(hwSampleRate);
	}
	return;
    }
    if (clockX != 6) {
	clockX = 6; /* Otherwise 3.0x */
	SetRate(hwSampleRate);
    }
    return;
  }
  /* cs is always non-NULL here */
  if (cs->gain != player.volumeOffset) {
    player.volumeOffset = cs->gain; /* vorbis-gain */
    PlayerVolume();
  }
}
Exemplo n.º 15
0
HRESULT WaveStreamContext::Open(DeviceContext *pDeviceContext, LPWAVEOPENDESC lpWOD, DWORD dwFlags)
{
    HRESULT Result;
    Result = StreamContext::Open(pDeviceContext,lpWOD,dwFlags);
    if (FAILED(Result))
    {
        return Result;
    }

    if (m_WaveFormat.wBitsPerSample == 8)
    {
        if (m_WaveFormat.nChannels == 1)
        {
            m_SampleType = PCM_TYPE_M8;
            m_SampleSize = 1;
        }
        else
        {
            m_SampleType = PCM_TYPE_S8;
            m_SampleSize = 2;
        }
    }
    else
    {
        if (m_WaveFormat.nChannels == 1)
        {
            m_SampleType = PCM_TYPE_M16;
            m_SampleSize = 2;
        }
        else
        {
            m_SampleType = PCM_TYPE_S16;
            m_SampleSize = 4;
        }
    }

    SetRate(0x10000);

    int i;
    for (i=0;i<OUTCHANNELS;i++)
    {
        m_PrevSamp[i] = 0;
        m_CurrSamp[i] = 0;
    }
    m_CurrT    = 0x200;   // Initializing to this ensures we get the 1st sample.

    return S_OK;
}
Exemplo n.º 16
0
void NetChannel::Reset()
{
	m_keep_alive = true;
	m_crashed = false;
	m_connected = false;

	m_connect_time = m_System->GetTime();

	SetTimeOut(30);
	SetRate(10000);
	SetUpdateRate(20);

	m_incoming_sequence = 0;
	m_incoming_acknowledged = 0;
	m_incoming_reliable_acknowledged = 0;
	m_incoming_reliable_sequence = 0;
	m_outgoing_sequence = 1;
	m_reliable_sequence = 0;
	m_last_reliable_sequence = 0;
}
Exemplo n.º 17
0
 /*
  * aRate -- the delay, in milliseconds, requested between timer firings
  */
 RefreshDriverTimer(double aRate)
 {
   SetRate(aRate);
 }
Exemplo n.º 18
0
 AudioChannelImpl()
 {
     SetRate(1);
     SetVolume(SDL_MIX_MAXVOLUME);
     SetPan(0.5f);
 }
BOOL clsIM7::InitThread()
{
    //initial setting
	FD_ZERO(&rfd);
	m_timeOut.tv_sec = 0;
	m_timeOut.tv_usec = IMU_TIMEOUT_READ;

    m_nsIM7= ::open("/dev/ser1", O_RDWR /*| O_NONBLOCK*/ );
	if (m_nsIM7 == -1) { printf("[IM7] Open IMU serial port (/dev/ser1) failed!\n"); return FALSE; }

    // Setup the COM port
    termios term;
    tcgetattr(m_nsIM7, &term);

    cfsetispeed(&term, IM7_BAUDRATE);				//input and output baudrate
    cfsetospeed(&term, IM7_BAUDRATE);

    term.c_cflag = CS8 | CLOCAL | CREAD;				//communication flags
//    term.c_iflag &= ~IXOFF;
//    term.c_iflag = /*IGNBRK | IGNCR |*/ IGNPAR;

	tcsetattr(m_nsIM7, TCSANOW, &term);

	tcflush(m_nsIM7, TCIOFLUSH);
//	IM7RAWPACK packraw[MAX_IM7PACK];

#ifdef IM7_MODE_POLL
	SetRate(0);
	usleep(15000);
//	SetType('A');
//	usleep(15000);
//	Poll('N');
	Poll('A');	// previous poll N

	usleep(15000);
//	GetPack(packraw, MAX_IM6PACK);				//filter the first package which is often invalid

//	Poll('A');	// previous poll N
//	usleep(10000);
#else
	Poll('N');
	usleep(15000);
//	SetType('A');
#endif
	SetType('N');
//	SetType('A');
	SetRate(100);

	//initialize variables
	m_tRetrieve = m_tRequest = -1;

	m_nIM7 = 0;
	m_nLost = 0;

	m_tGP7 = -1;
	m_tAH7 = -1;
	m_tSC7 = -1;

	m_nBuffer = 0;

	m_bit = 0;

    printf("[IM7] Start\n");		// after filtering the 1st packet, then start real imu data capture
	return TRUE;
}
Exemplo n.º 20
0
bool UMediaPlayer::Pause()
{
	return SetRate(0.0f);
}
Exemplo n.º 21
0
Channel::Channel()
{
	SetRate(1);
	SetVolume(SDL_MIX_MAXVOLUME);
	SetPan(0.5f);
}
Exemplo n.º 22
0
bool UMediaPlayer::Play()
{
	return SetRate(1.0f);
}
Exemplo n.º 23
0
bool
WUploadThread::InitSession()
{
	PRINT("WUploadThread::InitSession\n");

	ThreadWorkerSessionRef limit(new ThreadWorkerSession());

	// First check if IP is blacklisted or ignored
	//

	if (gWin->IsIgnoredIP(fStrRemoteIP))
	{
		SetBlocked(true);
	}

	if (gWin->IsBlackListedIP(fStrRemoteIP) && (gWin->fSettings->GetBLLimit() != WSettings::LimitNone))
	{
		limit()->SetGateway(AbstractMessageIOGatewayRef(new MessageIOGateway()));
		SetRate(WSettings::ConvertToBytes(gWin->fSettings->GetBLLimit()), limit);
	}
	else if (gWin->fSettings->GetULLimit() != WSettings::LimitNone)
	{
		limit()->SetGateway(AbstractMessageIOGatewayRef(new MessageIOGateway()));
		SetRate(WSettings::ConvertToBytes(gWin->fSettings->GetULLimit()), limit);
	}

	if (fTunneled)
	{
		WUploadEvent *wue = new WUploadEvent(WUploadEvent::ConnectInProgress);
		if (wue)
		{
			SendReply(wue);
		}

		return true;
	}
	else if (fAccept)
	{
		// <*****@*****.**> 20021026
		muscle::ip_address sRemoteIP = ResolveAddress(fStrRemoteIP);
		if (qmtt->AddNewConnectSession(sRemoteIP, (uint16)fPort, limit) != B_OK)
		{
			WUploadEvent *fail = new WUploadEvent(WUploadEvent::ConnectFailed);
			if (fail)
			{
				fail->SetError( QT_TR_NOOP( "Couldn't create new connect session!" ) );
				SendReply(fail);
			}
			return false;
		}
	}
	else
	{
		if (qmtt->AddNewSession(fSocket, limit) != B_OK)
		{
			WUploadEvent *fail = new WUploadEvent(WUploadEvent::ConnectFailed);
			if (fail)
			{
				fail->SetError( QT_TR_NOOP( "Could not init session!" ) );
				SendReply(fail);
			}
			return false;
		}
	}

	//
	// We should have a session created now
	//

	if (qmtt->StartInternalThread() == B_OK)
	{
		WUploadEvent *wue = new WUploadEvent(WUploadEvent::ConnectInProgress);
		if (wue)
		{
			SendReply(wue);
		}
		CTimer->start(60000, true);
		return true;
	}

	WUploadEvent *fail = new WUploadEvent(WUploadEvent::ConnectFailed);
	if (fail)
	{
		fail->SetError( QT_TR_NOOP( "Could not start internal thread!" ) );
		SendReply(fail);
	}
	return false;
}
Exemplo n.º 24
0
LRESULT CALLBACK WndMainProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch(message)
    {
        // Resize the video when the window changes
        case WM_MOVE:
        case WM_SIZE:
            if ((hWnd == ghApp) && (!g_bAudioOnly))
                MoveVideoWindow();
            break;

        // Enforce a minimum size
        case WM_GETMINMAXINFO:
            {
                LPMINMAXINFO lpmm = (LPMINMAXINFO) lParam;
                lpmm->ptMinTrackSize.x = MINIMUM_VIDEO_WIDTH;
                lpmm->ptMinTrackSize.y = MINIMUM_VIDEO_HEIGHT;
            }
            break;

        case WM_KEYDOWN:

            switch(toupper((int) wParam))
            {
                // Frame stepping
                case VK_SPACE:
                case '1':
                    StepOneFrame();
                    break;

                // Frame stepping (multiple frames)
                case '2':
                case '3':
                case '4':
                case '5':
                case '6':
                case '7':
                case '8':
                case '9':
                    StepFrames((int) wParam - '0');
                    break;

                case VK_LEFT:       // Reduce playback speed by 25%
                    ModifyRate(-0.25);
                    break;

                case VK_RIGHT:      // Increase playback speed by 25%
                    ModifyRate(0.25);
                    break;

                case VK_DOWN:       // Set playback speed to normal
                    SetRate(1.0);
                    break;

                case 'P':
                    PauseClip();
                    break;

                case 'S':
                    StopClip();
                    break;

                case 'M':
                    ToggleMute();
                    break;

                case 'F':
                case VK_RETURN:
                    ToggleFullScreen();
                    break;

               case 'H':
                    InitVideoWindow(1,2);
                    CheckSizeMenu(wParam);
                    break;
                case 'N':
                    InitVideoWindow(1,1);
                    CheckSizeMenu(wParam);
                    break;
                case 'D':
                    InitVideoWindow(2,1);
                    CheckSizeMenu(wParam);
                    break;
                case 'T':
                    InitVideoWindow(3,4);
                    CheckSizeMenu(wParam);
                    break;

                case VK_ESCAPE:
                    if (g_bFullscreen)
                        ToggleFullScreen();
                    else
                        CloseClip();
                    break;

                case VK_F12:
                case 'Q':
                case 'X':
                    CloseClip();
                    break;
            }
            break;

        case WM_COMMAND:

            switch(wParam)
            { // Menus

                case ID_FILE_OPENCLIP:
                    // If we have ANY file open, close it and shut down DShow
                    if (g_psCurrent != Init)
                        CloseClip();

                    // Open the new clip
                    OpenClip();
                    break;

                case ID_FILE_EXIT:
                    CloseClip();
                    PostQuitMessage(0);
                    break;

                case ID_FILE_PAUSE:
                    PauseClip();
                    break;

                case ID_FILE_STOP:
                    StopClip();
                    break;

                case ID_FILE_CLOSE:
                    CloseClip();
                    break;

                case ID_FILE_MUTE:
                    ToggleMute();
                    break;

                case ID_FILE_FULLSCREEN:
                    ToggleFullScreen();
                    break;

                case ID_HELP_ABOUT:
                    DialogBox(ghInst, MAKEINTRESOURCE(IDD_ABOUTBOX),
                              ghApp,  (DLGPROC) AboutDlgProc);
                    break;

                case ID_FILE_SIZE_HALF:
                    InitVideoWindow(1,2);
                    CheckSizeMenu(wParam);
                    break;
                case ID_FILE_SIZE_NORMAL:
                    InitVideoWindow(1,1);
                    CheckSizeMenu(wParam);
                    break;
                case ID_FILE_SIZE_DOUBLE:
                    InitVideoWindow(2,1);
                    CheckSizeMenu(wParam);
                    break;
                case ID_FILE_SIZE_THREEQUARTER:
                    InitVideoWindow(3,4);
                    CheckSizeMenu(wParam);
                    break;

                case ID_SINGLE_STEP:
                    StepOneFrame();
                    break;

                case ID_RATE_DECREASE:     // Reduce playback speed by 25%
                    ModifyRate(-0.25);
                    break;
                case ID_RATE_INCREASE:     // Increase playback speed by 25%
                    ModifyRate(0.25);
                    break;
                case ID_RATE_NORMAL:       // Set playback speed to normal
                    SetRate(1.0);
                    break;
                case ID_RATE_HALF:         // Set playback speed to 1/2 normal
                    SetRate(0.5);
                    break;
                case ID_RATE_DOUBLE:       // Set playback speed to 2x normal
                    SetRate(2.0);
                    break;

            } // Menus
            break;


        case WM_GRAPHNOTIFY:
            HandleGraphEvent();
            break;

        case WM_CLOSE:
            SendMessage(ghApp, WM_COMMAND, ID_FILE_EXIT, 0);
            break;

        case WM_DESTROY:
            PostQuitMessage(0);
            break;

        default:
            return DefWindowProc(hWnd, message, wParam, lParam);

    } // Window msgs handling

    // Pass this message to the video window for notification of system changes
    if (pVW)
        pVW->NotifyOwnerMessage((LONG_PTR) hWnd, message, wParam, lParam);

    return DefWindowProc(hWnd, message, wParam, lParam);
}
Exemplo n.º 25
0
unsigned long Measurement::GetNextDataBulk()
{
	FILE_LOG(logDEBUG3) << "Measurement::GetNextDataBulk";

	unsigned long i, j, index;
	short *overflow;
	uint32_t traces_asked_for, length_of_trace_fetched;
	// unsigned long length_of_trace_askedfor, length_of_trace_fetched;
	Timing t;

	// std::cerr << "(GetNextDataBulk: " << GetNextIndex() << ", " << GetMaxTracesToFetch() << ")\n";

	// it makes no sense to read any further: we are already at the end
	if(GetNextIndex() >= GetNTraces()) {
		std::cerr << "Stop fetching data from ociloscope." << std::endl;
		return 0UL;
	}

/*
	try {
		for(i=0; i<GetNumberOfChannels(); i++) {
			if(GetChannel(i)->IsEnabled()) {
				delete [] data[i];
				data[i] = new short[GetMaxTracesToFetch()*GetLength()];
			}
		}
	} catch(...) {
		std::cerr << "Unable to allocate memory in Measurement::AllocateMemoryBlock." << std::endl;
		throw;
	}
/**/

	traces_asked_for = GetMaxTracesToFetch();
	if(GetNextIndex() + traces_asked_for > GetNTraces()) {
		traces_asked_for = GetNTraces() - GetNextIndex();
	}
	// allocate buffers
	for(i=0; i<GetNumberOfChannels(); i++) {
		if(GetChannel(i)->IsEnabled()) {
			FILE_LOG(logDEBUG4) << "Measurement::GetNextDataBulk - memset data[i]" << GetLength()*traces_asked_for*sizeof(short);
			memset(data[i], 0, GetLength()*traces_asked_for*sizeof(short));
			FILE_LOG(logDEBUG4) << "done";
		}
		for(j=0; j<traces_asked_for; j++) {
			index = j+GetNextIndex();
			if(GetChannel(i)->IsEnabled()) {
				if(data_allocated[i] == false) {
					throw "Unable to get data. Memory is not allocated.";
				}
				if(GetSeries() == PICO_4000) {
					// GetPicoscope()->SetStatus(ps4000SetDataBufferBulk(
					// 	GetHandle(),                  // handle
					// 	(PS4000_CHANNEL)i,            // channel
					// 	data[i],                      // *buffer
					// 	GetMaxTraceLengthToFetch())); // bufferLength
					GetPicoscope()->SetStatus(ps4000SetDataBufferBulk(
						GetHandle(),                // handle
						(PS4000_CHANNEL)i,          // channel
						&data[i][j*GetLength()],    // *buffer
						GetLength(),                // bufferLength
						index));                    // waveform
				} else {
					// unsigned long dj = (j+GetNextIndex()/GetMaxTracesToFetch())%traces_asked_for;
					// std::cerr << "-- (set data buffer bulk: [" << i << "][" << dj
					// 	<< "], len:" << GetLength() << ", index:" << index
					// 	<< ", from:" << GetNextIndex()
					// 	<< ", to:" << GetNextIndex()+traces_asked_for-1 << "\n";
					GetPicoscope()->SetStatus(ps6000SetDataBufferBulk(
						GetHandle(),                // handle
						(PS6000_CHANNEL)i,          // channel
						&data[i][j*GetLength()],    // *buffer
						GetLength(),                // bufferLength
						index,                      // waveform
						PS6000_RATIO_MODE_NONE));   // downSampleRatioMode
				}
				if(GetPicoscope()->GetStatus() != PICO_OK) {
					std::cerr << "Unable to set memory for channel." << std::endl;
					throw Picoscope::PicoscopeException(GetPicoscope()->GetStatus());
				}
			}
		}
	}
	// fetch data
	// length_of_trace_fetched = length_of_trace_askedfor;
	std::cerr << "Get data for traces " << GetNextIndex() << "-" << GetNextIndex()+traces_asked_for << " (" << 100.0*(GetNextIndex()+traces_asked_for)/GetNTraces() << "%) ... ";
	overflow = new short[traces_asked_for];
	memset(overflow, 0, traces_asked_for*sizeof(short));
	// std::cerr << "-- x1\n";
	t.Start();
	// std::cerr << "length of buffer: " << data_length[0] << ", length of requested trace: " << length_of_trace_askedfor << " ... ";
	if(GetSeries() == PICO_4000) {
		length_of_trace_fetched = GetLength();
		GetPicoscope()->SetStatus(ps4000GetValuesBulk(
			GetHandle(),                // handle
			&length_of_trace_fetched,   // *noOfSamples
			// TODO: start index
			GetNextIndex(),             // fromSegmentIndex
			GetNextIndex()+traces_asked_for-1, // toSegmentIndex
			// this could also be min(GetMaxTraceLengthToFetch(),wholeLength-startindex)
			overflow));                // *overflow
	} else {
		// TODO: not sure about this ...
		length_of_trace_fetched = GetLength();
		GetPicoscope()->SetStatus(ps6000GetValuesBulk(
			GetHandle(),                // handle
			&length_of_trace_fetched,   // *noOfSamples
			// TODO: start index
			GetNextIndex(),             // fromSegmentIndex
			GetNextIndex()+traces_asked_for-1, // toSegmentIndex
			// this could also be min(GetMaxTraceLengthToFetch(),wholeLength-startindex)
			1,                          // downSampleRatio
			PS6000_RATIO_MODE_NONE,     // downSampleRatioMode
			overflow));                // *overflow
	}
	t.Stop();
	// std::cerr << "-- x2\n";
	if(GetPicoscope()->GetStatus() != PICO_OK) {
		std::cerr << "Unable to set memory for channel." << std::endl;
		throw Picoscope::PicoscopeException(GetPicoscope()->GetStatus());
	}
	for(i=0; i<traces_asked_for; i++) {
		for(j=0; i<GetNumberOfChannels(); i++) {
			if(overflow[i] & (1<<j)) {
				FILE_LOG(logWARNING) << "Warning: Overflow on channel " << (char)('A'+j) << " of trace " << i+GetNextIndex() << ".\n";
			}
		}
	}
	delete [] overflow;
	// if(length_of_trace_fetched != length_of_trace_askedfor) {
	// 	std::cerr << "Warning: The number of read samples was smaller than requested.\n";
	// }

	// getting timestamps
	int64_t *timestamps;
	PS6000_TIME_UNITS *timeunits;

	timestamps = new int64_t[traces_asked_for];
	timeunits  = new PS6000_TIME_UNITS[traces_asked_for];

	if(GetSeries() == PICO_4000) {
		// NOT YET IMPLEMENTED
	} else {
		FILE_LOG(logDEBUG2) << "ps6000GetValuesTriggerTimeOffsetBulk64(handle=" << GetHandle() << ", *timestamps, *timeunits, fromSegmentIndex=" << GetNextIndex() << ", toSegmentIndex=" << GetNextIndex()+traces_asked_for-1 << ")";
		GetPicoscope()->SetStatus(ps6000GetValuesTriggerTimeOffsetBulk64(
			GetHandle(),                // handle
			timestamps,                 // *times
			timeunits,                  // *timeUnits
			GetNextIndex(),                      // fromSegmentIndex
			GetNextIndex()+traces_asked_for-1)); // toSegmentIndex
	}
	if(GetPicoscope()->GetStatus() != PICO_OK) {
		std::cerr << "Unable to get timestamps." << std::endl;
		throw Picoscope::PicoscopeException(GetPicoscope()->GetStatus());
	}

	// for(i=0; i<traces_asked_for; i++) {
	// 	std::cerr << "time " << i << ": " << timestamps[i] << "\n";
	// }
	SetRate(traces_asked_for, timestamps[0], timeunits[0], timestamps[traces_asked_for-1], timeunits[traces_asked_for-1]);
	// if(timeunits[0] != timeunits[traces_asked_for-1]) {
	// 	FILE_LOG(logWARNING) << "time unit of the first and last sample differ; rate is not reliable; TIMING seems to be broken anyway";
	// }

	delete [] timestamps;
	delete [] timeunits;


	std::cerr << "OK ("<< t.GetSecondsDouble() <<"s)\n";

	// std::cerr << "length of trace fetched: " << length_of_trace_fetched << "\n";
	// std::cerr << "total length: " << traces_asked_for*length_of_trace_fetched << "\n";

	SetLengthFetched(traces_asked_for*length_of_trace_fetched);
	// std::cerr << "-- next index is now " << GetNextIndex() << ", will be set to " << GetNextIndex() + traces_asked_for << "\n";
	SetNextIndex(GetNextIndex()+traces_asked_for);
	// std::cerr << "-- next index is now " << GetNextIndex() << "\n";
	// std::cerr << "-- return value " << traces_asked_for << "\n";

	return traces_asked_for;
}