コード例 #1
0
ファイル: USBDevice.cpp プロジェクト: ekiwi/tinyos-1.x
bool CUSBDevice::WriteData(BYTE *data, DWORD datalen, BYTE type){
	BYTE valid;
	BYTE *OutputReport;

	if(!IsConnected())
		return false;

	if(datalen == 0){
		OutputReport = new BYTE[m_Capabilities.OutputReportByteLength];
		OutputReport[0] = 0;
		OutputReport[IMOTE_HID_TYPE] = (type & 0xE3) | _BIT(IMOTE_HID_TYPE_H) | (IMOTE_HID_TYPE_L_BYTE << IMOTE_HID_TYPE_L);
		OutputReport[IMOTE_HID_NI] = 0;
		OutputReport[IMOTE_HID_NI + 1] = 0;
		//Result = SendData(OutputReport, m_Capabilities.OutputReportByteLength);
		QueueData(OutputReport);
		//assert(Result);
	}
	else if(datalen <= IMOTE_HID_TYPE_L_BYTE_SIZE){
		BYTE n = (BYTE)(datalen / IMOTE_HID_BYTE_MAXPACKETDATA);

		for(BYTE i = 0; i <= n && IsConnected(); i++){
			OutputReport = new BYTE[m_Capabilities.OutputReportByteLength];
			OutputReport[0] = 0;
			
			if(i == 0){
				OutputReport[IMOTE_HID_NI] = n;
				OutputReport[IMOTE_HID_TYPE] = (type & 0xE3) | _BIT(IMOTE_HID_TYPE_H) | (IMOTE_HID_TYPE_L_BYTE << IMOTE_HID_TYPE_L);
			}
			else{
				OutputReport[IMOTE_HID_NI] = i;
				OutputReport[IMOTE_HID_TYPE] = (type & 0xE3) | (IMOTE_HID_TYPE_L_BYTE << IMOTE_HID_TYPE_L);
			}
			if(i==n){
				valid = (BYTE)(datalen % IMOTE_HID_BYTE_MAXPACKETDATA);
				OutputReport[IMOTE_HID_NI + 1] = valid;
			}
			else
				valid = (BYTE)IMOTE_HID_BYTE_MAXPACKETDATA;
			memcpy(OutputReport + IMOTE_HID_NI + 1 + (i==n?1:0), data + i * IMOTE_HID_BYTE_MAXPACKETDATA, valid);
			//Result = SendData(OutputReport, m_Capabilities.OutputReportByteLength);
			QueueData(OutputReport);
			//assert(Result);
			if(i == n)
				break;// because of loop around
		}
	}
	else if(datalen <= IMOTE_HID_TYPE_L_SHORT_SIZE){
		USHORT n = (USHORT)(datalen / IMOTE_HID_SHORT_MAXPACKETDATA);
		for(USHORT i = 0; i <= n && IsConnected(); i++){
			OutputReport = new BYTE[m_Capabilities.OutputReportByteLength];
			OutputReport[0] = 0;
			if(i == 0){
				OutputReport[IMOTE_HID_TYPE] = (type & 0xE3) | _BIT(IMOTE_HID_TYPE_H) | (IMOTE_HID_TYPE_L_SHORT << IMOTE_HID_TYPE_L);
				OutputReport[IMOTE_HID_NI] = (BYTE)(n >> 8);
				OutputReport[IMOTE_HID_NI + 1] = (BYTE)n;
			}
			else{
コード例 #2
0
ファイル: PAPlayer.cpp プロジェクト: AchimTuran/xbmc
inline bool PAPlayer::PrepareStream(StreamInfo *si)
{
  /* if we have a stream we are already prepared */
  if (si->m_stream)
    return true;

  /* get a paused stream */
  AEAudioFormat format = si->m_audioFormat;
  si->m_stream = CAEFactory::MakeStream(
    format,
    AESTREAM_PAUSED
  );

  if (!si->m_stream)
  {
    CLog::Log(LOGDEBUG, "PAPlayer::PrepareStream - Failed to get IAEStream");
    return false;
  }

  si->m_stream->SetVolume    (si->m_volume);
  float peak = 1.0;
  float gain = si->m_decoder.GetReplayGain(peak);
  if (peak == 1.0)
    si->m_stream->SetReplayGain(gain);
  else
    si->m_stream->SetAmplification(gain);

  /* if its not the first stream and crossfade is not enabled */
  if (m_currentStream && m_currentStream != si && !m_upcomingCrossfadeMS)
  {
    /* slave the stream for gapless */
    si->m_isSlaved = true;
    m_currentStream->m_stream->RegisterSlave(si->m_stream);
  }

  /* fill the stream's buffer */
  while(si->m_stream->IsBuffering())
  {
    int status = si->m_decoder.GetStatus();
    if (status == STATUS_ENDED   ||
        status == STATUS_NO_FILE ||
        si->m_decoder.ReadSamples(PACKET_SIZE) == RET_ERROR)
    {
      CLog::Log(LOGINFO, "PAPlayer::PrepareStream - Stream Finished");
      break;
    }

    if (!QueueData(si))
      break;

    /* yield our time so that the main PAP thread doesnt stall */
    CThread::Sleep(1);
  }

  CLog::Log(LOGINFO, "PAPlayer::PrepareStream - Ready");

  return true;
}
コード例 #3
0
void CTextReader::QueueBit(unsigned char bit)
{
	if (_res < resBits)
	{
		for (int i=0; i<(bit ? 8 : 4); i++)
		{
			QueueCycleKind(bit ? 'S' : 'L');
		}
	}
	else
	{
		EnsureResolution(resBits);
		QueueData(bit);
	}
}
コード例 #4
0
void CTextReader::QueueCycleKind(char kind)
{
	EnsureResolution(resCycleKinds);
	QueueData(kind);
}
コード例 #5
0
ファイル: PAPlayer.cpp プロジェクト: huigll/xbmc
inline bool PAPlayer::ProcessStream(StreamInfo *si, double &delay, double &buffer)
{
  /* if playback needs to start on this stream, do it */
  if (si == m_currentStream && !si->m_started)
  {
    si->m_started = true;
    si->m_stream->RegisterAudioCallback(m_audioCallback);
    if (!si->m_isSlaved)
      si->m_stream->Resume();
    si->m_stream->FadeVolume(0.0f, 1.0f, m_upcomingCrossfadeMS);
    m_callback.OnPlayBackStarted();
  }

  /* if we have not started yet and the stream has been primed */
  unsigned int space = si->m_stream->GetSpace();
  if (!si->m_started && !space)
    return true;

  /* see if it is time yet to FF/RW or a direct seek */
  if (!si->m_playNextTriggered && ((m_playbackSpeed != 1 && si->m_framesSent >= si->m_seekNextAtFrame) || si->m_seekFrame > -1))
  {
    int64_t time = (int64_t)0;
    /* if its a direct seek */
    if (si->m_seekFrame > -1)
    {
      time = (int64_t)((float)si->m_seekFrame / (float)si->m_sampleRate * 1000.0f);
      si->m_framesSent = (int)(si->m_seekFrame - ((float)si->m_startOffset * (float)si->m_sampleRate) / 1000.0f);
      si->m_seekFrame  = -1;
      m_playerGUIData.m_time = time; //update for GUI
    }
    /* if its FF/RW */
    else
    {
      si->m_framesSent      += si->m_sampleRate * (m_playbackSpeed  - 1);
      si->m_seekNextAtFrame  = si->m_framesSent + si->m_sampleRate / 2;
      time = (int64_t)(((float)si->m_framesSent / (float)si->m_sampleRate * 1000.0f) + (float)si->m_startOffset);
    }

    /* if we are seeking back before the start of the track start normal playback */
    if (time < si->m_startOffset || si->m_framesSent < 0)
    {
      time = si->m_startOffset;
      si->m_framesSent      = (int)(si->m_startOffset * si->m_sampleRate / 1000);
      si->m_seekNextAtFrame = 0;
      ToFFRW(1);
    }

    si->m_decoder.Seek(time);
  }

  int status = si->m_decoder.GetStatus();
  if (status == STATUS_ENDED   ||
      status == STATUS_NO_FILE ||
      si->m_decoder.ReadSamples(PACKET_SIZE) == RET_ERROR ||
      ((si->m_endOffset) && (si->m_framesSent / si->m_sampleRate >= (si->m_endOffset - si->m_startOffset) / 1000)))
  {
    CLog::Log(LOGINFO, "PAPlayer::ProcessStream - Stream Finished");
    return false;
  }

  if (!QueueData(si))
    return false;

  /* update the delay time if we are running */
  if (si->m_started)
  {
    if (si->m_stream->IsBuffering())
      delay = 0.0;
    else
      delay = std::min(delay , si->m_stream->GetDelay());
    buffer = std::min(buffer, si->m_stream->GetCacheTotal());
  }

  return true;
}
コード例 #6
0
ファイル: PAPlayer.cpp プロジェクト: KeTao/kodi-cmake
inline bool PAPlayer::ProcessStream(StreamInfo *si, double &freeBufferTime)
{
  /* if playback needs to start on this stream, do it */
  if (si == m_currentStream && !si->m_started)
  {
    si->m_started = true;
    si->m_stream->RegisterAudioCallback(m_audioCallback);
    if (!si->m_isSlaved)
      si->m_stream->Resume();
    si->m_stream->FadeVolume(0.0f, 1.0f, m_upcomingCrossfadeMS);
    m_callback.OnPlayBackStarted();
  }

  /* if we have not started yet and the stream has been primed */
  unsigned int space = si->m_stream->GetSpace();
  if (!si->m_started && !space)
    return true;

  /* see if it is time yet to FF/RW or a direct seek */
  if (!si->m_playNextTriggered && ((m_playbackSpeed != 1 && si->m_framesSent >= si->m_seekNextAtFrame) || si->m_seekFrame > -1))
  {
    int64_t time = (int64_t)0;
    /* if its a direct seek */
    if (si->m_seekFrame > -1)
    {
      time = (int64_t)((float)si->m_seekFrame / (float)si->m_sampleRate * 1000.0f);
      si->m_framesSent = (int)(si->m_seekFrame - ((float)si->m_startOffset * (float)si->m_sampleRate) / 1000.0f);
      si->m_seekFrame  = -1;
      m_playerGUIData.m_time = time; //update for GUI
      si->m_seekNextAtFrame = 0;
    }
    /* if its FF/RW */
    else
    {
      si->m_framesSent      += si->m_sampleRate * (m_playbackSpeed  - 1);
      si->m_seekNextAtFrame  = si->m_framesSent + si->m_sampleRate / 2;
      time = (int64_t)(((float)si->m_framesSent / (float)si->m_sampleRate * 1000.0f) + (float)si->m_startOffset);
    }

    /* if we are seeking back before the start of the track start normal playback */
    if (time < si->m_startOffset || si->m_framesSent < 0)
    {
      time = si->m_startOffset;
      si->m_framesSent      = 0;
      si->m_seekNextAtFrame = 0;
      ToFFRW(1);
    }

    si->m_decoder.Seek(time);
  }

  int status = si->m_decoder.GetStatus();
  if (status == STATUS_ENDED   ||
      status == STATUS_NO_FILE ||
      si->m_decoder.ReadSamples(PACKET_SIZE) == RET_ERROR ||
      ((si->m_endOffset) && (si->m_framesSent / si->m_sampleRate >= (si->m_endOffset - si->m_startOffset) / 1000)))
  {
    if (si == m_currentStream && m_continueStream)
    {
      // update current stream with info of next track
      si->m_startOffset = m_FileItem->m_lStartOffset * 1000 / 75;
      if (m_FileItem->m_lEndOffset)
        si->m_endOffset = m_FileItem->m_lEndOffset * 1000 / 75;
      else
        si->m_endOffset = 0;
      si->m_framesSent = 0;

      int64_t streamTotalTime = si->m_decoder.TotalTime() - si->m_startOffset;
      if (si->m_endOffset)
        streamTotalTime = si->m_endOffset - si->m_startOffset;

      // calculate time when to prepare next stream
      si->m_prepareNextAtFrame = 0;
      if (streamTotalTime >= TIME_TO_CACHE_NEXT_FILE + m_defaultCrossfadeMS)
        si->m_prepareNextAtFrame = (int)((streamTotalTime - TIME_TO_CACHE_NEXT_FILE - m_defaultCrossfadeMS) * si->m_sampleRate / 1000.0f);

      si->m_prepareTriggered = false;
      si->m_playNextAtFrame = 0;
      si->m_playNextTriggered = false;
      si->m_seekNextAtFrame = 0;

      //update the current stream to start playing the next track at the correct frame.
      UpdateStreamInfoPlayNextAtFrame(m_currentStream, m_upcomingCrossfadeMS);

      UpdateGUIData(si);
      m_callback.OnPlayBackStarted();
      m_continueStream = false;
    }
    else
    {
      CLog::Log(LOGINFO, "PAPlayer::ProcessStream - Stream Finished");
      return false;
    }
  }

  if (!QueueData(si))
    return false;

  /* update free buffer time if we are running */
  if (si->m_started)
  {
    if (si->m_stream->IsBuffering())
      freeBufferTime = 1.0;
    else
    {
      double free_space = (double)(si->m_stream->GetSpace() / si->m_bytesPerSample) / si->m_sampleRate;
      freeBufferTime = std::max(freeBufferTime , free_space);
    }
  }

  return true;
}
コード例 #7
0
ファイル: PAPlayer.cpp プロジェクト: FLyrfors/xbmc
inline bool PAPlayer::PrepareStream(StreamInfo *si)
{
  /* if we have a stream we are already prepared */
  if (si->m_stream)
    return true;

  /* get a paused stream */
  AEAudioFormat format = si->m_audioFormat;
  si->m_stream = CServiceBroker::GetActiveAE().MakeStream(
    format,
    AESTREAM_PAUSED
  );

  if (!si->m_stream)
  {
    CLog::Log(LOGDEBUG, "PAPlayer::PrepareStream - Failed to get IAEStream");
    return false;
  }

  si->m_stream->SetVolume    (si->m_volume);
  float peak = 1.0;
  float gain = si->m_decoder.GetReplayGain(peak);
  if (peak * gain <= 1.0)
    // No clipping protection needed
    si->m_stream->SetReplayGain(gain);
  else if (CServiceBroker::GetSettings().GetBool(CSettings::SETTING_MUSICPLAYER_REPLAYGAINAVOIDCLIPPING))
    // Normalise volume reducing replaygain to avoid needing clipping protection, plays file at lower level
    si->m_stream->SetReplayGain(1.0f / fabs(peak));
  else
    // Clipping protection (when enabled in AE) by audio limiting, applied just where needed
    si->m_stream->SetAmplification(gain);

  /* if its not the first stream and crossfade is not enabled */
  if (m_currentStream && m_currentStream != si && !m_upcomingCrossfadeMS)
  {
    /* slave the stream for gapless */
    si->m_isSlaved = true;
    m_currentStream->m_stream->RegisterSlave(si->m_stream);
  }

  /* fill the stream's buffer */
  while(si->m_stream->IsBuffering())
  {
    int status = si->m_decoder.GetStatus();
    if (status == STATUS_ENDED   ||
        status == STATUS_NO_FILE ||
        si->m_decoder.ReadSamples(PACKET_SIZE) == RET_ERROR)
    {
      CLog::Log(LOGINFO, "PAPlayer::PrepareStream - Stream Finished");
      break;
    }

    if (!QueueData(si))
      break;

    /* yield our time so that the main PAP thread doesnt stall */
    CThread::Sleep(1);
  }

  CLog::Log(LOGINFO, "PAPlayer::PrepareStream - Ready");

  return true;
}
コード例 #8
0
ファイル: am4pmr.c プロジェクト: OS2World/APP-COMM-AM4PM
void ReadModem(PVOID lpVar)
{
   static USHORT i;
   static ULONG n, ulLen, ulStartRecTime;
   static CHAR achHayesBuff[MAXHAYESMSG]; // Buffer for DCE answers
   static USHORT ichHayesBuff=0, usFBuffPos=0;
   static ULONG ulCount;
   static UCHAR buff[RECBUFFLEN], achFileB[RECFBUFFLEN];
   static BOOL bLastCharDLE=FALSE;

   if (fDebug)
      dprintf("Thread for reading started...\n");

   DosSetPriority(PRTYS_THREAD, PRTYC_TIMECRITICAL, 0, 0);

   for (;;)
   {
      if (DosWaitEventSem(semStopRead, SEM_IMMEDIATE_RETURN)==0)
      {
         if (fDebug)
            dprintf("Reading thread halted. usGlobalState=%u\n", usGlobalState);
         DosResetEventSem(semStopRead, &ulCount);
         DosResetEventSem(semGoOnRead, &ulCount);
         DosPostEventSem(semStopedReading);
         DosWaitEventSem(semGoOnRead, SEM_INDEFINITE_WAIT);
         if (fDebug)
            dprintf("Reading thread goes on... usGlobalState=%u\n", usGlobalState);
         bLastCharDLE=FALSE;
         ichHayesBuff=0;
      }

      if (usGlobalState==GS_ENDING) // Check if it's time to die
      {
         if (fDebug)
            dprintf("\nReading thread dying...\n");
         return;
      }
      
      if (DosRead(hCom, buff, RECBUFFLEN, &n) || !n) // L„s in fr†n porten
         continue;

      for (i=0; i<n; i++)
      {
         if (usGlobalState==GS_READY || usGlobalState==GS_INITREC || usGlobalState==GS_DONE || usGlobalState==GS_INITPLAY)
         {
            switch (buff[i])
            {
            case '\r':
               break;

            case '\n':
               if (ichHayesBuff)
               {
                  achHayesBuff[ichHayesBuff]='\0';
                  if (fDebug)
                     dprintf("DCE: '%s'\n", achHayesBuff);
                  if (usGlobalState==GS_INITREC && strcmp((PCHAR)achHayesBuff, "CONNECT")==0)
                  {
                     usGlobalState=GS_RECORDING;
                     bLastCharDLE=FALSE;
                     ulStartRecTime=GetSysMSecs();
                  }
                  else if (usGlobalState==GS_DONE && strcmp((PCHAR)achHayesBuff, "VCON")==0)
                  {
                     if (fDebug)
                        dprintf("<Ready>\n");
                     usGlobalState=GS_READY;
                  }
                  else if (usGlobalState==GS_INITPLAY)
                  {
                     if (fDebug)
                        dprintf("Play started\n");
                     SendIt(pchSendBuff, ulSendBuffLen);
                     usGlobalState=GS_READY;
                  }
                  QueueData(IM_STRFROMDCE, achHayesBuff, ichHayesBuff+1);
                  ichHayesBuff=0;
               }
               break;

#if 0   // XON/XOFF now handled by OS/2 COM driver
            case 17:
               QueueData(IM_XON, NULL, 0l);
               if (fDebug)
                  dprintf("XON\n");
               break;

            case 19:
               QueueData(IM_XOFF, NULL, 0l);
               if (fDebug)
                  dprintf("XOFF\n");
               break;
#endif
            case 16: // DLE
               if (!bLastCharDLE)
               {
                  bLastCharDLE=TRUE;
                  break;
               }
               else
                  bLastCharDLE=FALSE;
               // Fall through

            default:
               if (bLastCharDLE)
               {
 //               ichHayesBuff=0;
                  bLastCharDLE=FALSE;
                  if (buff[i] >= 32 && (szActiveDLECodes[0]=='\0' || strchr((PCHAR)szActiveDLECodes, buff[i]) != NULL))
                  {
                     QueueData(IM_DLEFROMDCE, buff+i, 1);
                     if (fDebug)
                        dprintf("DCE: <DLE> %c\n", buff[i]);
                  }
                  else
                     if (fDebug)
                        dprintf("DCE: <DLE> %c (ignored)\n", buff[i]);
               }
               else if (ichHayesBuff+1 < MAXHAYESMSG)
               {
                  achHayesBuff[ichHayesBuff]=buff[i];
                  ichHayesBuff++;
               }
               break;
            }
         }
         else if (usGlobalState==GS_RECORDING)
         {
            if (bLastCharDLE)
            {
               bLastCharDLE=FALSE;
               if (buff[i]==3) // ETX
               {
//                SetComXONXOFF(FALSE);
                  usGlobalState=GS_DONE;
                  ichHayesBuff=0;
                  ulRecTime+=GetSysMSecs()-ulStartRecTime;
                  usFBuffPos--;  // Remove stored DLE
               }
               else
               {
                  if (buff[i] >= 32)
                  {
                     if (szActiveDLECodes[0]=='\0' || strchr((PCHAR)szActiveDLECodes, buff[i]) != NULL)
                     {
                        QueueData(IM_DLEFROMDCE, buff+i, 1);
                        if (fDebug)
                           dprintf("DCE: <DLE> %c\n", buff[i]);
                     }
                     else
                        if (fDebug)
                           dprintf("DCE: <DLE> %c (ignored)\n", buff[i]);
                     usFBuffPos--;  // Remove stored DLE
                  }
                  else
                  {
                     if (!bDLEConv)
                        achFileB[usFBuffPos++]=buff[i];
                  }
               }
            }
            else
            {
               bLastCharDLE = buff[i] == 16;
               achFileB[usFBuffPos++]=buff[i];
            }

            if (usFBuffPos >= sizeof achFileB || (usGlobalState!=GS_RECORDING && usFBuffPos > 0))
            {
               if (hRec != 0)
                  DosWrite(hRec, achFileB, usFBuffPos, &ulLen);
               usFBuffPos=0;
            }
         }
      }
   }
}