// figure processing latency by doing 'dry runs' of filterBuffer()
bigtime_t StepMotionBlurFilter::calcProcessingLatency() {
	PRINT(("StepMotionBlurFilter::calcProcessingLatency()\n"));
	
	if(m_output.destination == media_destination::null) {
		PRINT(("\tNot connected.\n"));
		return 0LL;
	}
	
	// allocate a temporary buffer group
	BBufferGroup* pTestGroup = new BBufferGroup(m_output.format.u.raw_video.display.line_width * m_output.format.u.raw_video.display.line_count *4, 1);
	
	// fetch a buffer
	BBuffer* pBuffer = pTestGroup->RequestBuffer(m_output.format.u.raw_video.display.line_width * m_output.format.u.raw_video.display.line_count * 4);
	ASSERT(pBuffer);
	
	pBuffer->Header()->type = B_MEDIA_RAW_VIDEO;
	pBuffer->Header()->size_used = m_output.format.u.raw_video.display.line_width * m_output.format.u.raw_video.display.line_count * 4;
	
	// run the test
	bigtime_t preTest = system_time();
	filterBuffer(pBuffer);
	bigtime_t elapsed = system_time()-preTest;
	
	// clean up
	pBuffer->Recycle();
	delete pTestGroup;

	// reset filter state
	initFilter();

	return elapsed;
}
Example #2
0
/* ******************************************************************** */
int FdFilter::filterStream(FILE *inStream, FILE *outStream)
{
  int i, j;
  int  toread, towrite, nread, rVal = 1, testc;

  toread = maxInput;
  state = 1; // indicate start of new signal
  /* process data from a stream */
  while((nread = fread(inBuffer, sizeof(short), toread, inStream))) {
    testc = getc(inStream);
    if(feof(inStream))
      state |= 2;
    else
      ungetc(testc,inStream);
    if(insert > 1) {
      short *p, *q;
      for(p=inBuffer+nread-1, q= inBuffer+(nread*insert)-1, i=nread; i--; ) {
	for(j=insert-1; j--;) *q-- = 0;
	*q-- = *p--;
      }
    }
    filterBuffer(nread*insert, &towrite);
    if((i = fwrite(outBuffer,sizeof(short),towrite,outStream)) < towrite) {
      fprintf(stderr,"Problems writing output\n");
      rVal = 0;
    }
    state = 0;
  }
  return(rVal);
}
Example #3
0
void FlangerNode::BufferReceived(
	BBuffer* pBuffer) {
	ASSERT(pBuffer);

	// check buffer destination
	if(pBuffer->Header()->destination !=
		m_input.destination.id) {
		PRINT(("FlangerNode::BufferReceived():\n"
			"\tBad destination.\n"));
		pBuffer->Recycle();
		return;
	}

	if(pBuffer->Header()->time_source != TimeSource()->ID()) {
		PRINT(("* timesource mismatch\n"));
	}

	// check output
	if(m_output.destination == media_destination::null ||
		!m_outputEnabled) {
		pBuffer->Recycle();
		return;
	}

	// process and retransmit buffer
	filterBuffer(pBuffer);

	status_t err = SendBuffer(pBuffer, m_output.source, m_output.destination);
	if (err < B_OK) {
		PRINT(("FlangerNode::BufferReceived():\n"
			"\tSendBuffer() failed: %s\n", strerror(err)));
		pBuffer->Recycle();
	}
	// sent!
}
Example #4
0
// figure processing latency by doing 'dry runs' of filterBuffer()
bigtime_t FlangerNode::calcProcessingLatency() {
	PRINT(("FlangerNode::calcProcessingLatency()\n"));

	if(m_output.destination == media_destination::null) {
		PRINT(("\tNot connected.\n"));
		return 0LL;
	}

	// allocate a temporary buffer group
	BBufferGroup* pTestGroup = new BBufferGroup(
		m_output.format.u.raw_audio.buffer_size, 1);

	// fetch a buffer
	BBuffer* pBuffer = pTestGroup->RequestBuffer(
		m_output.format.u.raw_audio.buffer_size);
	ASSERT(pBuffer);

	pBuffer->Header()->type = B_MEDIA_RAW_AUDIO;
	pBuffer->Header()->size_used = m_output.format.u.raw_audio.buffer_size;

	// run the test
	bigtime_t preTest = system_time();
	filterBuffer(pBuffer);
	bigtime_t elapsed = system_time()-preTest;

	// clean up
	pBuffer->Recycle();
	delete pTestGroup;

	// reset filter state
	initFilter();

	return elapsed;
}
void StepMotionBlurFilter::BufferReceived(BBuffer* pBuffer)
{
	ASSERT(pBuffer);

	// check buffer destination
	if(pBuffer->Header()->destination != m_input.destination.id) 
	{
		PRINT(("StepMotionBlurFilter::BufferReceived():\n"
			"\tBad destination.\n"));
		pBuffer->Recycle();
		return;
	}
	
	if((RunMode() != B_OFFLINE) && (pBuffer->Header()->time_source != TimeSource()->ID())) 
	{
		PRINT(("* timesource mismatch\n"));
	}

	// check output
	if(m_output.destination == media_destination::null || !m_outputEnabled) 
	{
		pBuffer->Recycle();
		return;
	}
		
	// process and retransmit buffer
	filterBuffer(pBuffer);		

	status_t err = SendBuffer(pBuffer, m_output.source, m_output.destination);
	if (err < B_OK)
	{
		PRINT(("StepMotionBlurFilter::BufferReceived():\n"
			"\tSendBuffer() failed: %s\n", strerror(err)));
		pBuffer->Recycle();
	}
	if (RunMode() == B_OFFLINE)
		SetOfflineTime(pBuffer->Header()->start_time);
	// sent!
}
Example #6
0
bool IsHit(float *sample) {
  

  //Precalcuated Filter
  const static float COEF_LOWPASS_FILTER_FS400_FC40[101] = {-7.46743430298208e-05f,0.00248354664696717f,0.00112233989588931f,0.000826711931638179f,0.000220573657162887f,-0.000608580698353681f,-0.00142362923704699f,-0.00193774629305945f,-0.00190779145478616f,-0.00122833673267619f,2.42038943507627e-06f,0.00147768089448461f,0.00274754750201222f,0.00334708032125518f,0.00295224327906748f,0.00151424369613786f,-0.000675392159140040f,-0.00302409269580415f,-0.00478596570411362f,-0.00528393145988946f,-0.00414492280150041f,-0.00147314448490976f,0.00211013271842175f,0.00558635587549593f,0.00781088756279274f,0.00786402930626426f,0.00538476051055825f,0.000769312457516857f,-0.00482890710808253f,-0.00977060467662383f,-0.0123560386272336f,-0.0113712281545797f,-0.00654299033953943f,0.00122950409704551f,0.00996487932906945f,0.0170356688095536f,0.0198720879212355f,0.0167565749717718f,0.00749089935821721f,-0.00627112584227792f,-0.0211593051091526f,-0.0327111848494703f,-0.0363731364604173f,-0.0286490449499551f,-0.00811165965449541f,0.0239952523706242f,0.0637512209042429f,0.105192151754557f,0.141456823496643f,0.166209945155485f,0.174995192947581f,0.166209945155485f,0.141456823496643f,0.105192151754557f,0.0637512209042429f,0.0239952523706242f,-0.00811165965449541f,-0.0286490449499551f,-0.0363731364604173f,-0.0327111848494703f,-0.0211593051091526f,-0.00627112584227792f,0.00749089935821721f,0.0167565749717718f,0.0198720879212355f,0.0170356688095536f,0.00996487932906945f,0.00122950409704551f,-0.00654299033953943f,-0.0113712281545797f,-0.0123560386272336f,-0.00977060467662383f,-0.00482890710808253f,0.000769312457516857f,0.00538476051055825f,0.00786402930626426f,0.00781088756279274f,0.00558635587549593f,0.00211013271842175f,-0.00147314448490976f,-0.00414492280150041f,-0.00528393145988946f,-0.00478596570411362f,-0.00302409269580415f,-0.000675392159140040f,0.00151424369613786f,0.00295224327906748f,0.00334708032125518f,0.00274754750201222f,0.00147768089448461f,2.42038943507627e-06f,-0.00122833673267619f,-0.00190779145478616f,-0.00193774629305945f,-0.00142362923704699f,-0.000608580698353681f,0.000220573657162887f,0.000826711931638179f,0.00112233989588931f,0.00248354664696717f,-7.46743430298208e-05f};

  //Paramters
  float THRESHOLD = 5000;
  float RATIO = 0.9;
  float A_ABS_THRESHOLD = 12.0;
  const float *mFilter = COEF_LOWPASS_FILTER_FS400_FC40;
  int mFilter_length = FILTERSIZE;
  int mMidLocation = (mFilter_length - 1) / 2;
  static float mPsSample = 0;
  static float mPsLowpass = 0;
  float ratio = 1;
  float prevRatio = 1;
  float psHighpass = 0;
  static int buffer_size = 0;
  static bool flag;
  
  

  
  //Buffers
  //static StreamBufferFloat mSampleBufferX; 
  static StreamBuffer mSampleBufferY;
  //static StreamBufferFloat mSampleBufferZ;
  //static StreamBufferFloat mPsLowpassBufferX;
  static StreamBuffer mPsLowpassBufferY;
  //static StreamBufferFloat mPsLowpassBufferZ;
  //static StreamBufferFloat mPsSampleBufferX;
  static StreamBuffer mPsSampleBufferY;
  //static StreamBufferFloat mPsSampleBufferZ;
  

  // yh addition start  
  //static StreamBufferFloat AcclBuffer;
  // yh addition start
  
  float sampleX = sample[0];
  float sampleY = sample[1];
  float sampleZ = sample[2];
  float sampleXYZ = (float) sqrt(sampleX * sampleX + sampleY * sampleY + sampleZ * sampleZ);
  float lpSample;
  float rawSample;
  float ratioY;
  float psHighpassY;



  //Initialize buffers
  if (buffer_size == 0) {
    //InitBuffer(&mSampleBufferX, mFilter_length, 0);
    InitBuffer(&mSampleBufferY);
    //InitBuffer(&mSampleBufferZ, mFilter_length, 0);
    //InitBuffer(&mPsLowpassBufferX, mFilter_length, 0);
    InitBuffer(&mPsLowpassBufferY);
    //InitBuffer(&mPsLowpassBufferZ, mFilter_length, 0);
    //InitBuffer(&mPsSampleBufferX, mFilter_length, 0);
    InitBuffer(&mPsSampleBufferY);
    //InitBuffer(&mPsSampleBufferZ, mFilter_length, 0);    
    //InitBuffer(&AcclBuffer, 1200, 0);
  }




  // deal with X 

  /*

  Push(&mSampleBufferX, sampleX);
  lpSample = filterBuffer(&mSampleBufferX, mFilter);  
  rawSample = Get(&mSampleBufferX, mMidLocation);
  Push(&mPsLowpassBufferX, lpSample * lpSample);
  Push(&mPsSampleBufferX, rawSample * rawSample);
  mPsSample = Sum(&mPsSampleBufferX);
  mPsLowpass = Sum(&mPsLowpassBufferX);
  float ratioX = mPsLowpass / mPsSample;
  float psHighpassX = mPsSample - mPsLowpass;

  */



  // deal with Y

  //start = clock();

  

  if (mSampleBufferY.length == FILTERSIZE) {
    RemoveNode(&mSampleBufferY);    
  }     
  AddNode(&mSampleBufferY, sampleY);
  
  lpSample = filterBuffer(&mSampleBufferY, mFilter);
  rawSample = GetElement(&mSampleBufferY, mMidLocation);



  mPsSample = NewSum(&mPsSampleBufferY, mPsSample, rawSample * rawSample);
  mPsLowpass = NewSum(&mPsLowpassBufferY, mPsLowpass, lpSample * lpSample);

  /*
  if (buffer_size < 52 && buffer_size > 48) {
    OutputAll(&mPsSampleBufferY);  
    printf("values : %f, %f, %f,%f, %d\n", mPsSample, Sum(&mPsSampleBufferY), mPsSampleBufferY.array[mPsSampleBufferY.head], lpSample * lpSample, mPsSampleBufferY.head);
  }
  */



  if (mPsLowpassBufferY.length == FILTERSIZE) {
    RemoveNode(&mPsLowpassBufferY);    
  }     
  AddNode(&mPsLowpassBufferY, lpSample * lpSample);

  if (mPsSampleBufferY.length == FILTERSIZE) {
    RemoveNode(&mPsSampleBufferY);    
  }     
  AddNode(&mPsSampleBufferY, rawSample * rawSample);


  ratioY = mPsLowpass / mPsSample;
  psHighpassY = mPsSample - mPsLowpass;






  /*
  end = clock();
  cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
  printf("part time : %f\n", cpu_time_used);  
  */

  //deal with Z

  /*

  Push(&mSampleBufferZ, sampleZ);
  lpSample = filterBuffer(&mSampleBufferZ, mFilter);
  rawSample = Get(&mSampleBufferZ, mMidLocation);
  Push(&mPsLowpassBufferZ, lpSample * lpSample);
  Push(&mPsSampleBufferZ, rawSample * rawSample);
  mPsSample = Sum(&mPsSampleBufferZ);
  mPsLowpass = Sum(&mPsLowpassBufferZ);
  float ratioZ = mPsLowpass / mPsSample;
  float psHighpassZ = mPsSample - mPsLowpass;

  */




  // Test whether the filter is full or not
  buffer_size++;
  if (buffer_size <FILTERSIZE) {
    printf("The filter is not full yet\n");
    return false;
  }


  //printf("%f, %f, %f\n", ratioY, psHighpassY, sampleXYZ);
  
  

  if ((ratioY < RATIO) && (psHighpassY > THRESHOLD) && sampleXYZ > A_ABS_THRESHOLD) {
    return true;
  } else {
    return false;
  }
}
Example #7
0
// Process samples from 'input' array to 'output' array.  'nIn'
// contains the number of samples available in 'input'.  'maxOut' is
// the maximum number of samples that the caller allows to be
// transferred to 'output' (usually the size of 'output').  Set
// 'first' TRUE if the first sample of a new signal is in 'input'.
// Set 'last' TRUE of the last sample of the signal is in 'input' (to
// cause flushing of processing pipeline).  The simplest setup for use
// of this method requires that the caller use an input buffer no
// larger than the size returned by getMaxInputSize(), and an output
// array twice the size returned by getMaxInputSize().  Then, each
// subsequent call to filterArray will use all 'input' samples, and
// will transfer aoll available samples to 'output'.  Examples of this
// and the other case, of arbitrarily small caller buffers can be seen
// in the test harness at the end of this file.
// This method returns the number of output samples transferred to 'output'.
int FdFilter::filterArray(short *input, int nIn, int first, int last, short *output, int maxOut)
{
  int i, j, nLeft = nIn, nOut = 0, nToGo = maxOut;
  int  toRead, toWrite, available;
  short *p = input, *q, *r = output;

  if(first) {
    state = 1; // indicate start of new signal
    arrayLeftover = 0;
    arrayIndex = 0;
  }

  if(arrayLeftover) { // First, move any output remaining from the previous call.
    int toCopy = arrayLeftover;
    if(toCopy > nToGo)
      toCopy = nToGo;
    for(i=arrayIndex, j = 0; j < toCopy; i++, j++)
      *r++ = outBuffer[i];
    nToGo -= toCopy;
    nOut += toCopy;
    arrayLeftover -= toCopy;
    arrayIndex = i;
  }
  if(nToGo <= 0) {
    arraySamplesUsed = 0; // Can't process any input this time; no room in output array.
    return(maxOut);
  }

  /* Process data from array to array. */
  while(nLeft > 0) {
    toRead = nLeft;
    if(toRead > maxInput)
      toRead = maxInput;
    if(insert > 1) {
      for(q=inBuffer, i=0; i < toRead; i++) {
	*q++ = *p++;
	for(j=1; j < insert; j++)
	  *q++ = 0;
      }
    } else {
      for(q=inBuffer, i=0; i < toRead; i++)
	*q++ = *p++;
    }
    nLeft -= toRead;
    if((nLeft <= 0) && last)
      state |= 2;  // Indicate that end of signal is (also) in this bufferful.
    filterBuffer(toRead*insert, &available);

    state = 0; // Clear the initialization bit, if any for the next iteration.

    toWrite = available;
    if(toWrite > nToGo)
      toWrite = nToGo;

    for(i=0; i < toWrite; i++)
      *r++ = outBuffer[i];
    nOut += toWrite;
    available -= toWrite;
    if(available > 0) { // Ran out of output space; suspend processing
      arrayLeftover = available;  // Save the remaining output samples for the next call.
      arrayIndex = i;
      arraySamplesUsed = nIn - nLeft; // Record the number of input samples actually used.
      return(nOut);
    }
  }
  arraySamplesUsed = nIn;
  return(nOut);
}