Example #1
0
///////////////////////////////////////////////////////////////////////////////
// Open device
bool CWaveOut::Start(int DevID, int SmplRate, int Channels, int nBlock, int MaxBlockSamples)
{int i;

 // if we are already started, stop 
 if (m_Dev != NULL) Stop();
 
 // update audio format
 m_Fmt.nSamplesPerSec = SmplRate;
 m_Fmt.nChannels = Channels;
 m_Fmt.nBlockAlign = m_Fmt.nChannels * m_Fmt.wBitsPerSample / 8;
 m_Fmt.nAvgBytesPerSec = m_Fmt.nSamplesPerSec * m_Fmt.nBlockAlign;

 // save max length of block in samples and comute max block length in bytes
 m_MaxBlockSamples = MaxBlockSamples;
 m_MaxBlockBytes = m_Fmt.nBlockAlign * MaxBlockSamples;

 // try to open waveout device
 m_DevID = DevID;
 if (waveOutOpen(&m_Dev, m_DevID, &m_Fmt, (DWORD_PTR)CWaveOut_CB, (DWORD_PTR)this, CALLBACK_FUNCTION) != MMSYSERR_NOERROR) 
 {m_Dev = NULL; return(false);}
 
 // allocate memory for array of output blocks 
 m_nBlock = nBlock;
 if (m_nBlock < 2) m_nBlock = 2;
 m_B = (WAVEHDR *)ippsMalloc_8u(m_nBlock * sizeof(WAVEHDR));
 if (m_B == NULL) goto err;
 
 // allocate memory for output blocks
 for (i = 0; i < m_nBlock; i++)
 {// for safety ...
  memset(m_B+i, 0, sizeof(m_B[i])); 
 
  // allocate memory
  m_B[i].lpData = (LPSTR)ippsMalloc_8u(m_MaxBlockBytes);
  if (m_B[i].lpData == NULL) goto err;
  m_B[i].dwBufferLength = m_MaxBlockBytes;
  
  // clear it
  memset(m_B[i].lpData, 0, m_B[i].dwBufferLength);
  
  // prepare it
  if (waveOutPrepareHeader(m_Dev, m_B+i, sizeof(m_B[i])) != MMSYSERR_NOERROR) goto err;
  
  // send it into the device queue
  if (waveOutWrite(m_Dev, m_B+i, sizeof(m_B[i])) != MMSYSERR_NOERROR) goto err;
 }
 
 // we start from the first block
 m_Idx = 0;
 
 // success
 return(true);
 
 // error 
 err:
 Stop();
 return(false);
}
Example #2
0
static int g729tolin_new(struct ast_trans_pvt *pvt) {
	int i;
	struct g729_coder_pvt *tmp = pvt->pvt;
	//tmp = malloc(sizeof(struct g729_coder_pvt));
	if(tmp) {
		USC_CODEC_Fxns->std.GetInfo((USC_Handle)NULL, &(tmp->pInfo));	
		((USC_Option*)tmp->pInfo.params)->modes.bitrate = 0;
  		((USC_Option*)tmp->pInfo.params)->modes.truncate = 1;
  		((USC_Option*)tmp->pInfo.params)->direction = 1;

		/* tmp->bitstream_buf = ippsMalloc_8s(size); */
		
		USC_CODEC_Fxns->std.NumAlloc(tmp->pInfo.params, &tmp->nbanks);
		if(!(tmp->pBanks = (USC_MemBank*)ippsMalloc_8u(sizeof(USC_MemBank)*(tmp->nbanks)))) {
			ast_log(LOG_WARNING, "ippsMalloc_8u failed allocating %d bytes", sizeof(USC_MemBank)*(tmp->nbanks));
			return 1;
		}
		USC_CODEC_Fxns->std.MemAlloc(tmp->pInfo.params, tmp->pBanks);
		for(i=0; i<tmp->nbanks;i++) {
			if(!(tmp->pBanks[i].pMem = ippsMalloc_8u(tmp->pBanks->nbytes))) {
				ast_log(LOG_WARNING, "ippsMalloc_8u failed allocating %d bytes", sizeof(USC_MemBank)*(tmp->nbanks));
				/* printf("\nLow memory: %d bytes not allocated\n", tmp->pBanks->nbytes); */
				return 1;
			}
		}

		tmp->outFrameSize = getOutFrameSize();

		/* pcm_buf ippsMalloc_8s(getOutFrameSize()); */

		tmp->maxbitsize = tmp->pInfo.maxbitsize;
		USC_CODEC_Fxns->std.Init(tmp->pInfo.params, tmp->pBanks, &(tmp->codec));

#ifndef IPPCORE_NO_SSE
		ippCoreSetFlushToZero( 1, NULL );
#endif

		tmp->bitStream.nbytes  = tmp->maxbitsize;
	  	tmp->bitStream.bitrate = 0;
	        tmp->bitStream.frametype = 3;
	        tmp->pcmStream.pBuffer = tmp->pcm_buf;
		tmp->pcmStream.pcmType.bitPerSample = 0;
	        tmp->pcmStream.pcmType.sample_frequency = 0;

	        USC_CODEC_Fxns->std.Reinit(&((USC_Option*)tmp->pInfo.params)->modes, tmp->codec);

		tmp->tail = 0;
		localusecnt++;
		ast_update_use_count();
	}
	return 0;
}
Example #3
0
void g729_init_coder(PVT *hEncoder, int dummy){
    struct g72x_coder_pvt *state = hEncoder;

#ifndef IPPCORE_NO_SSE
    ippSetFlushToZero(1, NULL); /* is FZM flag per-thread or not? does it matter at all? */
#endif
    state->coder = ippsMalloc_8u(encoder_size);
    state->scratch_mem = ippsMalloc_8u(coder_size_scratch);

    apiG729Encoder_InitBuff(state->coder, state->scratch_mem);
    apiG729Encoder_Init(state->coder, G729A_CODEC, G729Encode_VAD_Disabled);

    return 0;
}
Example #4
0
void g729_init_decoder(PVT *hDecoder){
    struct g72x_coder_pvt *state = hDecoder;

#ifndef IPPCORE_NO_SSE
    ippSetFlushToZero(1, NULL);
#endif
    state->coder = ippsMalloc_8u(decoder_size);
    state->scratch_mem = ippsMalloc_8u(coder_size_scratch);

    apiG729Decoder_InitBuff(state->coder, state->scratch_mem);
    apiG729Decoder_Init(state->coder, G729A_CODEC);

    return 0;
}
Example #5
0
int auxResize_8u_C1R(void * pSrc, int sstep, int sh, int sw,
                      int sr1, int sr2, int sc1, int sc2,
                      void * pDst, int dstep,
                      int dr1, int dr2, int dc1, int dc2,
                      int interp)
{
    IppiSize srcSize = {sw,sh};
    IppiRect srcRoi = {sc1,sr1,sc2-sc1+1,sr2-sr1+1};
    IppiSize dstRoi = {dc2-dc1+1,dr2-dr1+1};
    double xf = (double)(dc2-dc1+1)/(sc2-sc1+1);
    double yf = (double)(dr2-dr1+1)/(sr2-sr1+1);

#ifdef IPP71

    if (interp != ippLinear) printf("sorry, using linear resize\n");

    int specSize, initSize, bufSize, numLobes=2, nChannel=1;
    IppiSize srcSizeR = {sc2-sc1+1,sr2-sr1+1};
    IppiPoint dstOffset = {0,0};
    // get working buffer sizes
    ippiResizeGetSize_8u(srcSizeR,dstRoi,ippLinear, 0, &specSize, &initSize);

    // allocate working buffers
    //Ipp8u *pInitBuf=ippsMalloc_8u(initSize);
    IppiResizeSpec_32f* pSpec=(IppiResizeSpec_32f*)ippsMalloc_8u(specSize);

    ippiResizeLinearInit_8u(srcSizeR, dstRoi, pSpec);

    ippiResizeGetBufferSize_8u(pSpec,dstRoi,nChannel,&bufSize);
    Ipp8u* pBuffer=ippsMalloc_8u(bufSize);

    int r = ippiResizeLinear_8u_C1R(pSrc, sstep,
                                    pDst, dstep,
                                    dstOffset, dstRoi,
                                    ippBorderRepl, 0,
                                    pSpec, pBuffer);

    //ippsFree(pInitBuf);
    ippsFree(pSpec);
    ippsFree(pBuffer);

    return r;

#else

    return ippiResize_8u_C1R(pSrc,srcSize,sstep,srcRoi,pDst,dstep,dstRoi,xf,yf,interp);

#endif

}
Example #6
0
Ipp32s  PrepareInput(FILE* pFile, Ipp8s* comment, Ipp8u** pBuff, FILE *fptrLog)
{
   Ipp8s pString[MAX_LEN_STRING];
   Ipp32s lenFile;
   Ipp8u *buff = NULL;
   fseek(pFile,0,SEEK_END);
   lenFile = ftell(pFile); /* size of file*/
   buff=ippsMalloc_8u(lenFile);
   if(!buff){
      sprintf(pString, "\nNo memory to load %d bytes from %s file",lenFile,comment);
      OutputInfoString(1, fptrLog, (const Ipp8s*)pString);
      return MEMORY_FAIL;
   }
//   rewind(pFile);
   fseek(pFile,0,SEEK_SET);

   lenFile = (Ipp32s)fread(buff,1,lenFile,pFile);
   if (PreProcessBitstream((Ipp8s *)buff, lenFile)) {
       OutputInfoString(1, fptrLog,"\nUnknown format bitstream.\n");
       return UNKNOWN_FORMAT;
   }

   *pBuff = buff;
   return lenFile;
}
/**
* \brief Default constructor
*/
Worker::Worker(RoboCompKinect::KinectPrx kinectprx, QObject *parent) : Ui_evaluacionForm()
{
	kinect = kinectprx;
	mutex = new QMutex();
	ippSetNumThreads(1);
	setupUi(this);
	imgAlto=480;imgAncho=640;
	maxDepth=10.0;minDepth=0.5;
	ippSizeImage.height=imgAlto;
	ippSizeImage.width=imgAncho;
	
	qImgRGB = new QImage(imgAncho,imgAlto,QImage::Format_RGB888 );
	qImgRGBZ = new QImage(imgAncho,imgAlto,QImage::Format_RGB888 );
	qImgZ = new QImage(imgAncho,imgAlto,QImage::Format_Indexed8 );
	imgZ =ippsMalloc_8u(imgAlto*imgAncho);
	

	rcdRGB =  new RCDraw (imgAncho,imgAlto,qImgRGB,this->frameRGB);
	rcdRGBZ =  new RCDraw (imgAncho,imgAlto,qImgRGBZ,this->frameRGBZ);
	rcdZ =  new RCDraw (imgAncho,imgAlto,qImgZ,this->frameZ);
	roiGrab.setCoords(0,0,640,480);
	grab=false;capture=false;
	
	show();
	connect(&timer, SIGNAL(timeout()), this, SLOT(compute()));
	connect(rcdZ,SIGNAL(newCoor(QPointF)),this,SLOT(mousePress(QPointF)));
	connect(rcdZ,SIGNAL(endCoor(QPointF)),this,SLOT(mouseRelase(QPointF)));
	Period = BASIC_PERIOD;
	timer.start(Period);
}
roiDetector::roiDetector(const CameraPrx& camera , RoboCompVision::TCamParams params_, int nCam_, QObject *parent):
    QObject(parent), _camera(camera), nCam(nCam_), params(params_)
{
    qDebug() << "roiDetector::roiDetector() -> Initiating roiDetector number " << nCam;
    Umbral_Harris=UMBRAL_HARRIS;
    Umbral_Harris_Min=UMBRAL_HARRIS_MIN;
    Umbral_Hess=UMBRAL_HESS;
    Umbral_Laplacian=(uchar)UMBRAL_LAPLACIAN;

    sizePir=(IppiSize *) malloc(params.pyrLevels*sizeof(IppiSize));
    infoPrisma=(PrismaROI *) malloc(params.pyrLevels*sizeof(PrismaROI));

    imagen = ippsMalloc_8u(params.size);
    imagenV.resize(params.size);

    iniPiramide();

    IppiSize sizeImage;
    sizeImage.width=PAN_RANK;
    sizeImage.height=TILT_RANK;

    Mapa_Umbral_Harris1=(Ipp32f *) ippsMalloc_32f(PAN_RANK*TILT_RANK*sizeof(Ipp32f));
    Mapa_Umbral_Harris2=(Ipp32f *) ippsMalloc_32f(PAN_RANK*TILT_RANK*sizeof(Ipp32f));
    ippiSet_32f_C1R(-1.,Mapa_Umbral_Harris1,PAN_RANK*sizeof(Ipp32f),sizeImage);
    ippiSet_32f_C1R(-1.,Mapa_Umbral_Harris2,PAN_RANK*sizeof(Ipp32f),sizeImage);
    Mapa_Umbral_Harris_Act=Mapa_Umbral_Harris1;
    Mapa_Umbral_Harris_Ant=Mapa_Umbral_Harris2;

    //LogPolar
    //	lp = new LPolar(64,200,height,height);
}
Example #9
0
IQSSBDemodulator::IQSSBDemodulator()
{
	_sideband = USB;

	ippsFFTInitAlloc_C_32f(&_fft_specs, ORDER, IPP_FFT_DIV_BY_SQRTN, ippAlgHintNone);
	int fft_bufsize;
	ippsFFTGetBufSize_C_32f(_fft_specs, &fft_bufsize);
	_fft_buf = ippsMalloc_8u(fft_bufsize);
	// allocate buffers
	_in_re = ippsMalloc_32f(NFFT);
	_in_im = ippsMalloc_32f(NFFT);
	_in_p = ippsMalloc_32f(NFFT);
	_in_m = ippsMalloc_32f(NFFT);
	_residual_re = ippsMalloc_32f(NFFT);
	_residual_im = ippsMalloc_32f(NFFT);

	// prepare for ippsDeinterleave
	_iq[0] = _in_re;
	_iq[1] = _in_im;
	
	// design initial filter
	_taps_len = BLKSIZE;
	_fir_taps_re = ippsMalloc_32f(NFFT);
	_fir_taps_im= ippsMalloc_32f(NFFT);
	_fir_taps_m  = ippsMalloc_32f(NFFT);  // magnitude
	_fir_taps_p  = ippsMalloc_32f(NFFT);  // phase
	_lowFreq = 200.0/48000.0;
	_highFreq = 3000.0/48000.0;
	this->setFilter(_lowFreq, _highFreq);

	_residual_length = NFFT - _taps_len -1;
}
Example #10
0
static bool ipp_sqrDistance(const Mat& src, const Mat& tpl, Mat& dst)
{
    IppStatus status;

    IppiSize srcRoiSize = {src.cols,src.rows};
    IppiSize tplRoiSize = {tpl.cols,tpl.rows};

    Ipp8u *pBuffer;
    int bufSize=0;

    int depth = src.depth();

    ippimatchTemplate ippFunc =
            depth==CV_8U ? (ippimatchTemplate)ippiSqrDistanceNorm_8u32f_C1R:
            depth==CV_32F? (ippimatchTemplate)ippiSqrDistanceNorm_32f_C1R: 0;

    if (ippFunc==0)
        return false;

    IppEnum funCfg = (IppEnum)(ippAlgAuto | ippiNormNone | ippiROIValid);

    status = ippiSqrDistanceNormGetBufferSize(srcRoiSize, tplRoiSize, funCfg, &bufSize);
    if ( status < 0 )
        return false;

    pBuffer = ippsMalloc_8u( bufSize );

    status = ippFunc(src.ptr(), (int)src.step, srcRoiSize, tpl.ptr(), (int)tpl.step, tplRoiSize, dst.ptr<Ipp32f>(), (int)dst.step, funCfg, pBuffer);

    ippsFree( pBuffer );
    return status >= 0;
}
Example #11
0
int Decompress1StateInitAlloc( bwtState **ppState, int blocksize ) {

    IppStatus st;
    int totalSize   = 0;    /* total size of all buffers */
    int bwtSize     = 0;    /* size of additional buffer for BWT transform */
    int mtfSize     = 0;    /* size of state structure for MTF transform */
    int hufSize     = 0;    /* size of state structure for Huffman encoding */


    /* gets size of additional buffer for BWT */
    if( ippStsNoErr != ( st = ippsBWTInvGetSize_8u( (blocksize<<1), &bwtSize ) ) )
        return st;

    totalSize += bwtSize;

    /* gets size of state structure for MTF */
    if( ippStsNoErr != ( st = ippsMTFGetSize_8u( &mtfSize ) ) )
        return st;

    totalSize += mtfSize;

    /* gets size of state structure for Huffman Encoding */
    if( ippStsNoErr != ( st = ippsHuffGetSize_8u( &hufSize ) ) )
        return st;

    totalSize += hufSize;

    /* allocates memory for the structure itself */
    (*ppState) = (bwtState *)ippsMalloc_8u(sizeof(bwtState));

    /* allocates memory for the additional buffers and state structures
       as a one big piece of memory and then just inits a pointers as a
       shift inside this memory piece */
    (*ppState)->mtfStateSize    = mtfSize;
    (*ppState)->huffStateSize   = hufSize;
    (*ppState)->bwtBufferSize   = bwtSize;
    (*ppState)->blocksize       = blocksize;
    (*ppState)->mainstream      = (Ipp8u *)ippsMalloc_8u( sizeof(Ipp8u) * totalSize + 1);
    (*ppState)->pBwtAddBuffer   = (*ppState)->mainstream;
    (*ppState)->pMTFState       = ((*ppState)->pBwtAddBuffer + bwtSize);
    (*ppState)->pHuffState      = ((*ppState)->pMTFState + mtfSize);

    if( ippStsNoErr != ( st = ippsMTFInit_8u( (IppMTFState_8u *)((*ppState)->pMTFState) ) ) )
        return st;

    return ippStsNoErr;
} /* Decompress1StateInitAlloc() */
Biquad::Biquad()
{
#if OS(DARWIN)
    // Allocate two samples more for filter history
    m_inputBuffer.allocate(kBufferSize + 2);
    m_outputBuffer.allocate(kBufferSize + 2);
#endif

#if USE(WEBAUDIO_IPP)
    int bufferSize;
    ippsIIRGetStateSize64f_BiQuad_32f(1, &bufferSize);
    m_ippInternalBuffer = ippsMalloc_8u(bufferSize);
#endif // USE(WEBAUDIO_IPP)

    // Initialize as pass-thru (straight-wire, no filter effect)
    setNormalizedCoefficients(1, 0, 0, 1, 0, 0);

    reset(); // clear filter memory
}
Example #13
0
static int g723tolin_new(struct ast_trans_pvt *pvt) {
	int i;
	struct g723_coder_pvt *tmp = pvt->pvt;
	int dSize;

	//tmp = malloc(sizeof(struct g723_coder_pvt));
	if(tmp) {

		apiG723Decoder_Alloc(&dSize);
		tmp->encoder = NULL;
		tmp->decoder = (G723Decoder_Obj *)ippsMalloc_8u(dSize);

		apiG723Decoder_Init(tmp->decoder, 0);

		tmp->tail = 0;
		localusecnt++;
		ast_update_use_count();
	}
	return 0;
}
Example #14
0
static int lintog723_new(struct ast_trans_pvt *pvt) {
	int i;
	struct g723_coder_pvt *tmp = pvt->pvt;
	int eSize;

	//tmp = malloc(sizeof(struct g723_coder_pvt));
	if(tmp) {

		apiG723Encoder_Alloc(&eSize);
		tmp->encoder = (G723Encoder_Obj*)ippsMalloc_8u(eSize);		
		tmp->decoder = NULL;
		tmp->sendRate = defaultSendRate;

		// Init, no VAD or silence compression
		apiG723Encoder_Init(tmp->encoder, 0);

		tmp->tail = 0;
		localusecnt++;
		ast_update_use_count();
	}
	return 0;
}
Example #15
0
OsStatus MpeIPPG729::initEncode(void)
{
   int lCallResult;

   ippStaticInit();
   strcpy((char*)codec->codecName, "IPP_G729A");
   codec->lIsVad = 1;

   // Load codec by name from command line
   lCallResult = LoadUSCCodecByName(codec, NULL);
   if (lCallResult < 0)
   {
      return OS_FAILED;
   }

   // Get USC codec params
   lCallResult = USCCodecAllocInfo(&codec->uscParams, NULL);
   if (lCallResult < 0)
   {
      return OS_FAILED;
   }

   lCallResult = USCCodecGetInfo(&codec->uscParams, NULL);
   if (lCallResult < 0)
   {
      return OS_FAILED;
   }

   // Get its supported format details
   lCallResult = GetUSCCodecParamsByFormat(codec, BY_NAME, NULL);
   if (lCallResult < 0)
   {
      return OS_FAILED;
   }

   // Set params for encode
   USC_PCMType streamType;
   streamType.bitPerSample = getInfo()->getNumBitsPerSample();
   streamType.nChannels = getInfo()->getNumChannels();
   streamType.sample_frequency = getInfo()->getSamplingRate();

   lCallResult = SetUSCEncoderPCMType(&codec->uscParams, LINEAR_PCM, &streamType, NULL);
   if (lCallResult < 0)
   {
      return OS_FAILED;
   }

   // instead of SetUSCEncoderParams(...)
   codec->uscParams.pInfo->params.direction = USC_ENCODE;
   codec->uscParams.pInfo->params.law = 0;
   codec->uscParams.pInfo->params.modes.vad = ms_bEnableVAD ? 1 : 0;

   // Alloc memory for the codec
   lCallResult = USCCodecAlloc(&codec->uscParams, NULL);
   if (lCallResult < 0)
   {
      return OS_FAILED;
   }

   // Init decoder
   lCallResult = USCEncoderInit(&codec->uscParams, NULL, NULL);
   if (lCallResult < 0)
   {
      return OS_FAILED;  
   }

   // Allocate memory for the output buffer. Size of output buffer is equal
   // to the size of 1 frame
   inputBuffer = 
      (Ipp8s *)ippsMalloc_8s(codec->uscParams.pInfo->params.framesize);
   outputBuffer = 
      (Ipp8u *)ippsMalloc_8u(codec->uscParams.pInfo->maxbitsize + 10);

   return OS_SUCCESS;
}
bool ieee1394capture::init(RoboCompCamera::TCamParams &params_, RoboCompJointMotor::JointMotorPrx head_ , RoboCompDifferentialRobot::DifferentialRobotPrx base_ )
{
	params = params_;
	head = head_;
	base = base_;

	int32_t i;

	fps = (dc1394framerate_t)params.FPS;//15;
	res = (dc1394video_mode_t)0;

	switch (fps) {
	case 1: fps =  DC1394_FRAMERATE_1_875; break;
	case 3: fps =  DC1394_FRAMERATE_3_75; break;
	case 15: fps = DC1394_FRAMERATE_15; break;
	case 30: fps = DC1394_FRAMERATE_30; break;
	case 60: fps = DC1394_FRAMERATE_60; break;
	default: fps = DC1394_FRAMERATE_7_5; break;
	}

	switch (res) {
	case 1:
		res = DC1394_VIDEO_MODE_640x480_YUV411;
		device_width = 640;
		device_height = 480;
		break;
	case 2:
		res = DC1394_VIDEO_MODE_640x480_RGB8;
		device_width = 640;
		device_height = 480;
		break;
	default:
		res = DC1394_VIDEO_MODE_320x240_YUV422;
		device_width = 320;
		device_height = 240;
		break;
	}


	/// Get handle
	qDebug() << "ieee1394capture::init() -> Initializating first Firewire Card in the system...";
	if (!(d = dc1394_new()))
	{
		qDebug() << "ieee1394capture::init() -> Fatal error: Unable to aquire a handle to the Ieee1394 device";
		qDebug() << "Please check if the kernel modules `ieee1394',`raw1394' and `ohci1394' are loaded or if you have read/write access to /dev/raw1394 and to /dev/video1394-0 " ;
		return false;
	}
	CREATED_BUS = true;

	/// Create camera interfaces
	numCameras = 0;
	err = dc1394_camera_enumerate(d, &list);
	DC1394_ERR_RTN(err, "Failed to enumerate cameras");
	if (list->num == 0)
	{
		dc1394_log_error("No cameras found");
		return 1;
	}
	numCameras = 0;
	for (uint32_t  di = 0; di < list->num; di++)
	{
		if (numCameras >= MAX_CAMERAS)
			break;
		cameras[numCameras] = dc1394_camera_new(d, list->ids[di].guid);
		if (!cameras[numCameras])
		{
			dc1394_log_warning("Failed to initialize camera with guid %llx", list->ids[di].guid);
			continue;
		}
		printf("Camera #%d\n", numCameras);
		numCameras++;
	}
	dc1394_camera_free_list(list);
	if ( numCameras < 1 )
	{
		qDebug() << "ieee1394capture::init() -> Fatal error: No cameras found in the bus! Called from ";
		cleanup();
		return false;
	}
	/// Check if one camera has become the root node
/*	for ( int n=0; n < numCameras; n++ )
	{
		if ( cameraNodeList[n] == numNodes )
		{
			qDebug() << "ieee1394capture::init() -> Fatal error: Sorry, your camera is the highest numbered node of the bus, and has therefore become the root node." ;
			cleanup();
			return false;
		}
	}*/
	CREATED_CAMS = true;

	/// Setup cameras for capture
	qDebug() << "ieee1394capture::init() -> Searching cameras with requested parameters:";
	printf("%s\n",params.mode.c_str());
	if (params.mode == "MODE_320x240_YUV422")
	{
		res = DC1394_VIDEO_MODE_320x240_YUV422;
		params.width = 320;
		params.height = 240;
	}
	else if (params.mode == "MODE_640x480_YUV422" )
	{
		res = DC1394_VIDEO_MODE_640x480_YUV422;
		params.width = 640;
		params.height = 480;
	}
	else if (params.mode == "MODE_640x480_RGB" )
	{
		res = DC1394_VIDEO_MODE_640x480_RGB8;
		params.width = 640;
		params.height = 480;
	}
	else if (params.mode == "MODE_640x480_YUV411")
	{
		res = DC1394_VIDEO_MODE_640x480_YUV411;
		params.width = 640;
		params.height = 480;
	}
	else if (params.mode == "MODE_640x480_MONO")
	{
		res = DC1394_VIDEO_MODE_640x480_MONO8;
		params.width = 640;
		params.height = 480;
	}
	else if (params.mode == "MODE_640x480_MONO16")
	{
		res = DC1394_VIDEO_MODE_640x480_MONO16;
		params.width = 640;
		params.height = 480;
	}
	else if (params.mode == "MODE_516x338_YUV422")
	{
		res = DC1394_VIDEO_MODE_FORMAT7_1;
		params.width = 516;
		params.height = 338;
	}
	else qFatal("ieee1394capture::init() -> Image Mode %s not available. Aborting...", params.mode.c_str());
	params.size = params.width*params.height;
	if (params.FPS!=15 and params.FPS!=30)
	{
		qWarning("ieee1394capture::init() -> Framerate %d not available. Aborting...", params.FPS );
		cleanup();
		return false;
	}

	dc1394format7modeset_t info;

	for (i = 0; i < numCameras; i++)
	{

	    if (params.mode == "MODE_516x338_YUV422")
	    {
		err = dc1394_format7_get_modeset(cameras[i], &info);

		for( int j=0;j<DC1394_VIDEO_MODE_FORMAT7_NUM;j++)
		{
		  qDebug() << info.mode[j].present;
		  qDebug() << info.mode[j].size_x;
		  qDebug() << info.mode[j].size_y;
		  qDebug() << info.mode[j].max_size_x;
		  qDebug() << info.mode[j].max_size_y;

		  qDebug() << info.mode[j].pos_x;
		  qDebug() << info.mode[j].pos_y;

		  qDebug() << info.mode[j].unit_size_x;
		  qDebug() << info.mode[j].unit_size_y;
		  qDebug() << info.mode[j].unit_pos_x;
		  qDebug() << info.mode[j].unit_pos_y;

		  qDebug() << info.mode[j].pixnum;

		  qDebug() << info.mode[j].packet_size; /* in bytes */
		  qDebug() << info.mode[j].unit_packet_size;
		  qDebug() << info.mode[j].max_packet_size;
		}
	    }


   	    release_iso_and_bw(i);

	    err = dc1394_video_set_mode(cameras[i], res);
	    DC1394_ERR_CLN_RTN(err, cleanup(), "Could not set video mode");

	    err = dc1394_video_set_iso_speed(cameras[i], DC1394_ISO_SPEED_400);
	    DC1394_ERR_CLN_RTN(err, cleanup(), "Could not set ISO speed");


	    //For format 7 modes only
	    if (params.mode == "MODE_516x338_YUV422")
	    {
	   //  uint32_t packet_size;

	    //  err=dc1394_format7_set_image_size(cameras[i], res, 514, 384);
	    //  DC1394_ERR_RTN(err,"Could not set image size");
	    //  err=dc1394_format7_get_recommended_packet_size(cameras[i], res, &packet_size);
	    //  DC1394_ERR_RTN(err,"Could not get format 7 recommended packet size");
	    //  err=dc1394_format7_set_roi(cameras[i], res, DC1394_COLOR_CODING_YUV422, packet_size, 0,0, 514, 384);
	    //  DC1394_ERR_RTN(err,"Could not set ROI");
	      qDebug() << "ya";
	    }

	    err = dc1394_video_set_framerate(cameras[i], fps);
	    DC1394_ERR_CLN_RTN(err, cleanup(), "Could not set framerate");

	    err = dc1394_capture_setup(cameras[i], NUM_BUFFERS, DC1394_CAPTURE_FLAGS_DEFAULT);
	    DC1394_ERR_CLN_RTN(err, cleanup(), "Could not setup camera-\nmake sure that the video mode and framerate are\nsupported by your camera");

	    err = dc1394_video_set_transmission(cameras[i], DC1394_ON);
	    DC1394_ERR_CLN_RTN(err, cleanup(), "Could not start camera iso transmission");


	}
	fflush(stdout);
	qDebug() << "	ieee1394capture::init() -> Iso transmission started.";


	///Buffers de imagen
	qDebug() << "BUFFERS DE IMAGEN ------------------------------------------";
	for ( int i=0; i < numCameras; i++ )
	{
		AimgBuffer[i] = ( Ipp8u * ) ippsMalloc_8u ( params.size * 9 );
		BimgBuffer[i] = ( Ipp8u * ) ippsMalloc_8u ( params.size * 9 );
		img8u_lum[i] = AimgBuffer[i];
		img8u_YUV[i] = AimgBuffer[i]+params.size;
		localYRGBImgBufferPtr[i] = BimgBuffer[i];
		qDebug() << "Reservando" << params.size * 9 <<" para localYRGBImgBufferPtr["<<i<<"]";
		printf("(de %p a %p)\n", localYRGBImgBufferPtr[i], localYRGBImgBufferPtr[i]+(params.size*9-1));
	}


	planos[0]=BimgBuffer[0]+params.size*3;
	planos[1]=BimgBuffer[0]+ ( params.size*4 );
	planos[2]=BimgBuffer[0]+ ( params.size*5 );
	//img8u_aux = BimgBuffer[0]+(params.size*6);

	imgSize_ipp.width=params.width;
	imgSize_ipp.height=params.height;

	return true;

}
Example #17
0
static void
HoughLinesProbabilistic( Mat& image,
                         float rho, float theta, int threshold,
                         int lineLength, int lineGap,
                         std::vector<Vec4i>& lines, int linesMax )
{
    Point pt;
    float irho = 1 / rho;
    RNG rng((uint64)-1);

    CV_Assert( image.type() == CV_8UC1 );

    int width = image.cols;
    int height = image.rows;

    int numangle = cvRound(CV_PI / theta);
    int numrho = cvRound(((width + height) * 2 + 1) / rho);

#if defined HAVE_IPP && !defined(HAVE_IPP_ICV_ONLY) && IPP_VERSION_X100 >= 810 && IPP_DISABLE_BLOCK
    CV_IPP_CHECK()
    {
        IppiSize srcSize = { width, height };
        IppPointPolar delta = { rho, theta };
        IppiHoughProbSpec* pSpec;
        int bufferSize, specSize;
        int ipp_linesMax = std::min(linesMax, numangle*numrho);
        int linesCount = 0;
        lines.resize(ipp_linesMax);
        IppStatus ok = ippiHoughProbLineGetSize_8u_C1R(srcSize, delta, &specSize, &bufferSize);
        Ipp8u* buffer = ippsMalloc_8u(bufferSize);
        pSpec = (IppiHoughProbSpec*) malloc(specSize);
        if (ok >= 0) ok = ippiHoughProbLineInit_8u32f_C1R(srcSize, delta, ippAlgHintNone, pSpec);
        if (ok >= 0) ok = ippiHoughProbLine_8u32f_C1R(image.data, image.step, srcSize, threshold, lineLength, lineGap, (IppiPoint*) &lines[0], ipp_linesMax, &linesCount, buffer, pSpec);

        free(pSpec);
        ippsFree(buffer);
        if (ok >= 0)
        {
            lines.resize(linesCount);
            CV_IMPL_ADD(CV_IMPL_IPP);
            return;
        }
        lines.clear();
        setIppErrorStatus();
    }
#endif

    Mat accum = Mat::zeros( numangle, numrho, CV_32SC1 );
    Mat mask( height, width, CV_8UC1 );
    std::vector<float> trigtab(numangle*2);

    for( int n = 0; n < numangle; n++ )
    {
        trigtab[n*2] = (float)(cos((double)n*theta) * irho);
        trigtab[n*2+1] = (float)(sin((double)n*theta) * irho);
    }
    const float* ttab = &trigtab[0];
    uchar* mdata0 = mask.ptr();
    std::vector<Point> nzloc;

    // stage 1. collect non-zero image points
    for( pt.y = 0; pt.y < height; pt.y++ )
    {
        const uchar* data = image.ptr(pt.y);
        uchar* mdata = mask.ptr(pt.y);
        for( pt.x = 0; pt.x < width; pt.x++ )
        {
            if( data[pt.x] )
            {
                mdata[pt.x] = (uchar)1;
                nzloc.push_back(pt);
            }
            else
                mdata[pt.x] = 0;
        }
    }

    int count = (int)nzloc.size();

    // stage 2. process all the points in random order
    for( ; count > 0; count-- )
    {
        // choose random point out of the remaining ones
        int idx = rng.uniform(0, count);
        int max_val = threshold-1, max_n = 0;
        Point point = nzloc[idx];
        Point line_end[2];
        float a, b;
        int* adata = accum.ptr<int>();
        int i = point.y, j = point.x, k, x0, y0, dx0, dy0, xflag;
        int good_line;
        const int shift = 16;

        // "remove" it by overriding it with the last element
        nzloc[idx] = nzloc[count-1];

        // check if it has been excluded already (i.e. belongs to some other line)
        if( !mdata0[i*width + j] )
            continue;

        // update accumulator, find the most probable line
        for( int n = 0; n < numangle; n++, adata += numrho )
        {
            int r = cvRound( j * ttab[n*2] + i * ttab[n*2+1] );
            r += (numrho - 1) / 2;
            int val = ++adata[r];
            if( max_val < val )
            {
                max_val = val;
                max_n = n;
            }
        }

        // if it is too "weak" candidate, continue with another point
        if( max_val < threshold )
            continue;

        // from the current point walk in each direction
        // along the found line and extract the line segment
        a = -ttab[max_n*2+1];
        b = ttab[max_n*2];
        x0 = j;
        y0 = i;
        if( fabs(a) > fabs(b) )
        {
            xflag = 1;
            dx0 = a > 0 ? 1 : -1;
            dy0 = cvRound( b*(1 << shift)/fabs(a) );
            y0 = (y0 << shift) + (1 << (shift-1));
        }
        else
        {
            xflag = 0;
            dy0 = b > 0 ? 1 : -1;
            dx0 = cvRound( a*(1 << shift)/fabs(b) );
            x0 = (x0 << shift) + (1 << (shift-1));
        }

        for( k = 0; k < 2; k++ )
        {
            int gap = 0, x = x0, y = y0, dx = dx0, dy = dy0;

            if( k > 0 )
                dx = -dx, dy = -dy;

            // walk along the line using fixed-point arithmetics,
            // stop at the image border or in case of too big gap
            for( ;; x += dx, y += dy )
            {
                uchar* mdata;
                int i1, j1;

                if( xflag )
                {
                    j1 = x;
                    i1 = y >> shift;
                }
                else
                {
                    j1 = x >> shift;
                    i1 = y;
                }

                if( j1 < 0 || j1 >= width || i1 < 0 || i1 >= height )
                    break;

                mdata = mdata0 + i1*width + j1;

                // for each non-zero point:
                //    update line end,
                //    clear the mask element
                //    reset the gap
                if( *mdata )
                {
                    gap = 0;
                    line_end[k].y = i1;
                    line_end[k].x = j1;
                }
                else if( ++gap > lineGap )
                    break;
            }
        }

        good_line = std::abs(line_end[1].x - line_end[0].x) >= lineLength ||
                    std::abs(line_end[1].y - line_end[0].y) >= lineLength;

        for( k = 0; k < 2; k++ )
        {
            int x = x0, y = y0, dx = dx0, dy = dy0;

            if( k > 0 )
                dx = -dx, dy = -dy;

            // walk along the line using fixed-point arithmetics,
            // stop at the image border or in case of too big gap
            for( ;; x += dx, y += dy )
            {
                uchar* mdata;
                int i1, j1;

                if( xflag )
                {
                    j1 = x;
                    i1 = y >> shift;
                }
                else
                {
                    j1 = x >> shift;
                    i1 = y;
                }

                mdata = mdata0 + i1*width + j1;

                // for each non-zero point:
                //    update line end,
                //    clear the mask element
                //    reset the gap
                if( *mdata )
                {
                    if( good_line )
                    {
                        adata = accum.ptr<int>();
                        for( int n = 0; n < numangle; n++, adata += numrho )
                        {
                            int r = cvRound( j1 * ttab[n*2] + i1 * ttab[n*2+1] );
                            r += (numrho - 1) / 2;
                            adata[r]--;
                        }
                    }
                    *mdata = 0;
                }

                if( i1 == line_end[k].y && j1 == line_end[k].x )
                    break;
            }
        }
Example #18
0
//                ippsFFTInv_CCSToR_32s16s_Sfs
//
*/

#include "../../include/psffti.h"

/* Initialization context functions */

IPPFUN(IppStatus, ippsFFTInitAlloc_C_32sc, (IppsFFTSpec_C_32sc **pFFTSpec, int order, int flag, IppHintAlgorithm hint))
{
    IppStatus result;

    IPP_BAD_PTR1_RET(pFFTSpec);
    IPP_BAD_FFT_ORDER_RET(order);

    *pFFTSpec = (IppsFFTSpec_C_32sc*)ippsMalloc_8u(sizeof(IppsFFTSpec_C_32sc));
    if (pFFTSpec == NULL) return ippStsMemAllocErr;
    (*pFFTSpec)->id = idCtxFFT_C_32sc;
    (*pFFTSpec)->order = order;
    (*pFFTSpec)->length = (1 << (order + 1));
    (*pFFTSpec)->pSrc = ippsMalloc_32f((*pFFTSpec)->length);
    (*pFFTSpec)->pDst = ippsMalloc_32f((*pFFTSpec)->length);
    result = ippsFFTInitAlloc_C_32fc(&((*pFFTSpec)->pSpec), order, flag, hint);

    return result;
}

IPPFUN(IppStatus, ippsFFTInitAlloc_R_32s, (IppsFFTSpec_R_32s **pFFTSpec, int order, int flag, IppHintAlgorithm hint))
{
    IppStatus result;
Ipp32f (*ParticleStatistics(Image2D &image_localmax, Image2D &image_in,
					   const int mask_radius, const int feature_radius, int &counter))[8]
{

	IppStatus status;

	//setup kernels
	Convolution_Kernel ConvolutionKernels(mask_radius, image_localmax.get_width(), image_localmax.get_length());

	//Convert 32-bit FP image data in image_localmax to 8-bit integer data
	Ipp8u *localmaxdata = ippsMalloc_8u((int) image_localmax.get_numberofpixels());
	int stepsize = image_localmax.get_width();
	IppiSize fullROI = image_localmax.get_ROIfull();
	status = ippiConvert_32f8u_C1R(image_localmax.get_image2D(), image_localmax.get_stepsize(),
		localmaxdata, stepsize, fullROI, ippRndNear);
	//Determine the number of particles (raw; not yet excluded from border region)
	Ipp64f numberofmaxima = 0;
	status = ippiSum_8u_C1R(localmaxdata, stepsize, image_localmax.get_ROIfull(), &numberofmaxima);

	//Set up structures for counting particle data
	int numberofpixels = image_localmax.get_numberofpixels();
	Ipp32f (*particledata)[8] = new Ipp32f[(int) numberofmaxima + 1][8];

	//border region (local maxima here are excluded from future operations)
	int border = feature_radius;	//minimum distance from the border, in pixels
	int minx = border, miny = border;
	int maxx = image_localmax.get_width() - minx;
	int maxy = image_localmax.get_height() - miny;
	int xval = 0;
	int yval = 0;

	counter = 0;									//index that keeps track of which particle
	int imagewidth = image_in.get_width();
	//determine integer x and y values (in pixels) for each local maximum outside
	//of border exclusion area
	for(int j = 0; j < numberofpixels; j++) {
		if(localmaxdata[j] == 1) {
			xval = image_in.getx(j);
			yval = image_in.gety(j);

			if (xval > minx && xval < maxx && yval > miny && yval < maxy) {
				particledata[counter][0] = j;
				particledata[counter][1] = xval;
				particledata[counter][2] = yval;
				counter++;
			}
		}
	}

	//extract local region around each maximum
	int extract_radius = mask_radius;
	int extract_diameter = 2 * extract_radius + 1;
	int extract_size = extract_diameter * extract_diameter;
	int extract_step = 4 * extract_diameter;
	IppiSize extract_ROI = {extract_diameter, extract_diameter};
	int extract_offset = extract_radius * (1 + image_in.get_width());	//calculate _relative_ offset (in pixels) of the array index
	Ipp32f *extracted_square = ippsMalloc_32f(extract_size);
	Ipp32f *multiply_result = ippsMalloc_32f(extract_size);
	Ipp32f *inputimage = ippsMalloc_32f(image_in.get_numberofpixels());
	status = ippiCopy_32f_C1R(image_in.get_image2D(), image_in.get_stepsize(),
			inputimage, image_in.get_stepsize(), image_in.get_ROIfull());
	for(int i = 0; i < counter; i++) {

		int extract_index = particledata[i][0];
		int copy_offset = extract_index - extract_offset;							//this is the starting point for ROI (in pixels!!)
		status = ippiCopy_32f_C1R(inputimage + copy_offset, image_in.get_stepsize(),
			extracted_square, extract_step, extract_ROI);
		//Calculate mass
		Ipp64f total_mass = 0;
		status = ippiMul_32f_C1R(extracted_square, extract_step, ConvolutionKernels.get_circle_kernel(), ConvolutionKernels.get_kernel_step(),
			multiply_result, extract_step, extract_ROI);
		status = ippiSum_32f_C1R(multiply_result, extract_step, extract_ROI, &total_mass, ippAlgHintNone);

		//Calculate x-offset (to be added to integral position)
		Ipp64f x_sum = 0;
		status = ippiMul_32f_C1R(extracted_square, extract_step, ConvolutionKernels.get_ramp_x_kernel(), ConvolutionKernels.get_kernel_step(),
			multiply_result, extract_step, extract_ROI);
		status = ippiSum_32f_C1R(multiply_result, extract_step, extract_ROI, &x_sum, ippAlgHintNone);
		Ipp32f x_offset = (x_sum / total_mass) - extract_radius - 1;

		//Calculate y-offset (to be added to integral position)
		Ipp64f y_sum = 0;
		status = ippiMul_32f_C1R(extracted_square, extract_step, ConvolutionKernels.get_ramp_y_kernel(), ConvolutionKernels.get_kernel_step(),
			multiply_result, extract_step, extract_ROI);
		status = ippiSum_32f_C1R(multiply_result, extract_step, extract_ROI, &y_sum, ippAlgHintNone);
		Ipp32f y_offset = (y_sum / total_mass) - extract_radius - 1;

		//Calculate r^2
		Ipp64f r2_sum = 0;
		status = ippiMul_32f_C1R(extracted_square, extract_step, ConvolutionKernels.get_r2_kernel(), ConvolutionKernels.get_kernel_step(),
			multiply_result, extract_step, extract_ROI);
		status = ippiSum_32f_C1R(multiply_result, extract_step, extract_ROI, &r2_sum, ippAlgHintNone);
		Ipp32f r2_val = r2_sum / total_mass;

		//Calculate "multiplicity": how many particles are within the area calculated by the masks
		Ipp64f multiplicity = 0;
		status = ippiSum_32f_C1R(image_localmax.get_image2D()+copy_offset, image_localmax.get_stepsize(),
			extract_ROI, &multiplicity, ippAlgHintNone);
		Ipp32f multiplicity_val = multiplicity;

		//assign values to particle data array
		if (total_mass > 0) {
		particledata[i][1] += x_offset;
		particledata[i][2] += y_offset;
		particledata[i][3] = x_offset;
		particledata[i][4] = y_offset;
		particledata[i][5] = total_mass;
		particledata[i][6] = r2_val;
		particledata[i][7] = multiplicity_val;
		}
	}

	//Cleanup memory (this part is critical---program otherwise crashes!!)
	ippsFree(extracted_square);
	extracted_square = NULL;

	ippsFree(multiply_result);
	multiply_result = NULL;

	ippsFree(inputimage);
	inputimage = NULL;

	ippsFree(localmaxdata);
	localmaxdata = NULL;

	return particledata;
}
Example #20
0
Ipp32s WINAPI WinMain( HINSTANCE hinst, HINSTANCE xxx, LPWSTR lpCmdLine, Ipp32s yyy )
{
   Ipp8s line[WINCE_CMDLINE_SIZE];                     /* to copy command line */
   Ipp8s* argvv[WINCE_NCMD_PARAMS];
   Ipp8s** argv=argvv;

   wchar_t wexename[WINCE_EXENAME_SIZE];
   Ipp8s exename[WINCE_EXENAME_SIZE];
   Ipp8s cmdline[WINCE_CMDLINE_SIZE];

   /* simulate argc and argv parameters */
   Ipp32s argc;
#else /*Other OS*/
Ipp32s main(Ipp32s argc, Ipp8s *argv[])
{
#endif /*_WIN32_WCE*/
   CommandLineParams clParams;
   USC_EC_Params ecParams;
   USC_Status USCStatus;
   MeasureIt measure;
   FILE *fp_rin = NULL;
   FILE *fp_sin = NULL;
   FILE *fp_sout = NULL;
   FILE *f_log = NULL;
   vm_file *f_csv = NULL;        /* csv File    */
   Ipp8u *in1_buff_cur, *in2_buff_cur, *out_buff_cur;
   Ipp8u *in1_buff=NULL, *in2_buff=NULL, *out_buff=NULL;

   Ipp32s flen, in_len, lCallResult;
   Ipp32s i, frameNum, tailNum;
   Ipp32s usage=0, n_repeat=1;
   double speech_sec;
   Ipp32s delay=0;
   Ipp8s* appName=argv[0];
   Ipp8s pString[MAX_LEN_STRING];
   const  IppLibraryVersion *ver = NULL;
#if defined( _WIN32_WCE )

   GetModuleFileName( hinst, wexename, WINCE_EXENAME_SIZE );
   sprintf( exename, "%ls", wexename );
   sprintf( cmdline, "%ls", lpCmdLine );
   argc = parseCmndLine( exename, cmdline, line, WINCE_CMDLINE_SIZE, argv, WINCE_NCMD_PARAMS );

#endif

   ippStaticInit();

   SetCommandLineByDefault(&clParams);
   strcpy(clParams.csvFileName, "ec_speed.csv");

   usage = ReadCommandLine(&clParams, argc, argv);
   if(clParams.puttolog == 1) {
     if((f_log = fopen(clParams.logFileName, "a")) == NULL) return FOPEN_FAIL;
   } else f_log = NULL;
   if(usage) {
      if(clParams.enumerate == 1) {
         EnumerateStaticLinkedEC(f_log);
         if(f_log) fclose(f_log);
         return 0;
      } else {
        PrintUsage((const Ipp8s *)appName, f_log);
        return USAGE;
      }
   }

   lCallResult = LoadECByName((const Ipp8s *)clParams.ECName, &ecParams, f_log);
   if(lCallResult < 0) {
      sprintf(pString, "Cannot find %s echo canceller.\n", clParams.ECName);
      OutputInfoString(1, f_log, (const Ipp8s*)pString);
      if(f_log) fclose(f_log);
      return LOAD_EC_FAIL;
   }
   ecParams.pUSC_EC_Fxns->std.GetInfo((USC_Handle)NULL, &ecParams.pInfo);
   ecParams.objEC = NULL;
   ecParams.pBanks = NULL;
   ecParams.nBanks = 0;

   if((fp_rin = fopen(clParams.rinFileName,"rb")) == NULL)  {
      sprintf(pString, "echo canceller: File %s [r-in] could not be open.\n", clParams.rinFileName);
      OutputInfoString(1, f_log, (const Ipp8s*)pString);
      if(f_log) fclose(f_log);
      return FOPEN_FAIL;
   }
   if((fp_sin = fopen(clParams.sinFileName,"rb")) == NULL) {
      sprintf(pString, "echo canceller: File %s [s-in] could not be open.\n", clParams.sinFileName);
      OutputInfoString(1, f_log, (const Ipp8s*)pString);
      if(f_log) fclose(f_log);
      return FOPEN_FAIL;
   }
   if((fp_sout = fopen(clParams.soutFileName,"wb")) == NULL) {
      sprintf(pString, "echo canceller: File %s [s-out] could not be open.\n", clParams.soutFileName);
      OutputInfoString(1, f_log, (const Ipp8s*)pString);
      if(f_log) fclose(f_log);
      return FOPEN_FAIL;
   }
   if(clParams.puttocsv) { /* open the csv file */
      if((f_csv = vm_file_open(clParams.csvFileName, "a")) == NULL) {
         sprintf(pString, "\nFile %s could not be open.\n", clParams.csvFileName);
         OutputInfoString(1, f_log, (const Ipp8s*)pString);
         if(f_log) fclose(f_log);
         return FOPEN_FAIL;
      }
   }
    if(clParams.printSysInfo){
        OutputInfoString(0, f_log,"The Intel(R) echo canceller conformant to ITU G167 and G168,\n");
        ver = ippscGetLibVersion();
        sprintf(pString, "The Intel(R) IPPSC library used:  %d.%d.%d Build %d, name %s\n",
            ver->major,ver->minor,ver->majorBuild,ver->build,ver->Name);
        OutputInfoString(0, f_log, (const Ipp8s*)pString);
        ver = ippsGetLibVersion();
        sprintf(pString, "The Intel(R) IPPSP library used:  %d.%d.%d Build %d, name %s\n",
            ver->major,ver->minor,ver->majorBuild,ver->build,ver->Name);
        OutputInfoString(0, f_log, (const Ipp8s*)pString);
    }
    sprintf(pString, "Input  rin file: %s\n", clParams.rinFileName);
    OutputInfoString(1, f_log, (const Ipp8s*)pString);
    sprintf(pString, "Input  sin file: %s\n", clParams.sinFileName);
    OutputInfoString(1, f_log, (const Ipp8s*)pString);
    sprintf(pString, "Output sout file: %s\n", clParams.soutFileName);
    OutputInfoString(1, f_log, (const Ipp8s*)pString);
    switch(clParams.nlp) {
     case 0:
         sprintf(pString, "NLP disabled\n");
         break;
     case 1:
         sprintf(pString, "NLP type 1 enabled\n");
         break;
     default:
         sprintf(pString, "NLP  type 2 enabled\n");
    }

    switch(clParams.alg) {
     case EC_FULLBAND:
            ecParams.pInfo.params.algType = EC_FULLBAND;
            sprintf(pString, "mode : fullband \n");
            break;
     case EC_SUBBAND:
            ecParams.pInfo.params.algType = EC_SUBBAND;
            sprintf(pString, "mode : subband \n");
            break;
     case EC_AFFINESUBBAND:
         ecParams.pInfo.params.algType = EC_AFFINESUBBAND;
         sprintf(pString, "mode : subband affine projection \n");
         break;
     case EC_FASTSUBBAND:
            ecParams.pInfo.params.algType = EC_FASTSUBBAND;
            sprintf(pString, "mode : fast subband \n");
            break;
     default: return UNKNOWN_FORMAT;
   }
    OutputInfoString(1, f_log, (const Ipp8s*)pString);
    switch(clParams.adapt) {
        case 0:
            sprintf(pString, "adaptation : disable \n");
            ecParams.pInfo.params.modes.adapt = AD_OFF;
            break;
        case 2:
            sprintf(pString, "adaptation : lite \n");
            ecParams.pInfo.params.modes.adapt = AD_LITEADAPT;
            break;
        default:
            ecParams.pInfo.params.modes.adapt = AD_FULLADAPT;
            sprintf(pString, "adaptation : full \n");
    }
   OutputInfoString(1, f_log, (const Ipp8s*)pString);
   sprintf(pString, "echo tail length : %d\n", clParams.tail);
   OutputInfoString(1, f_log, (const Ipp8s*)pString);
   if(clParams.puttocsv) {
    if(clParams.printSysInfo){
        sysInfoToCSV(f_csv);
    }
   }
   ecParams.pInfo.params.pcmType.sample_frequency = clParams.freq;
   ecParams.pInfo.params.pcmType.bitPerSample = 16;
   ecParams.pInfo.params.echotail = clParams.tail;
   ecParams.pInfo.params.modes.zeroCoeff = 1;///???
   ecParams.pInfo.params.modes.nlp = clParams.nlp;
   ecParams.pInfo.params.modes.cng = clParams.cng;
   ecParams.pInfo.params.modes.td = 1;
   ecParams.pInfo.params.modes.ah = clParams.ah_mode;

   ecParams.pUSC_EC_Fxns->std.NumAlloc((const USC_EC_Option *)&ecParams.pInfo.params, &ecParams.nBanks);
   ecParams.pBanks = (USC_MemBank*)ippsMalloc_8u(sizeof(USC_MemBank)*ecParams.nBanks);
   if(!ecParams.pBanks) {
      sprintf(pString, "\nLow memory: %d bytes not allocated\n", (int)(sizeof(USC_MemBank)*ecParams.nBanks));
      OutputInfoString(1, f_log, (const Ipp8s*)pString);
      if(fp_rin) fclose(fp_rin);
      if(fp_sin) fclose(fp_sin);
      if(fp_sout) fclose(fp_sout);
      if(clParams.puttocsv) { if(f_csv) vm_file_fclose(f_csv); }
      if(f_log) fclose(f_log);
      return MEMORY_FAIL;
   }
   ecParams.pUSC_EC_Fxns->std.MemAlloc((const USC_EC_Option *)&ecParams.pInfo.params, ecParams.pBanks);
   for(i=0;i<ecParams.nBanks;i++) {
     ecParams.pBanks[i].pMem = (Ipp8s *)ippsMalloc_8u(ecParams.pBanks[i].nbytes);//375d60,377420
     if(!ecParams.pBanks[i].pMem) {
       sprintf(pString, "\nLow memory: %d bytes not allocated\n", ecParams.pBanks[i].nbytes);
       OutputInfoString(1, f_log, (const Ipp8s*)pString);
       if(ecParams.pBanks) ippsFree(ecParams.pBanks);
       if(fp_rin) fclose(fp_rin);
       if(fp_sin) fclose(fp_sin);
       if(fp_sout) fclose(fp_sout);
       if(clParams.puttocsv) { if(f_csv) vm_file_fclose(f_csv); }
       if(f_log) fclose(f_log);
       return MEMORY_FAIL;
     }
   }

   flen = PrepareInput(fp_rin, " receive-in input ", &in1_buff, f_log);
   in_len = PrepareInput(fp_sin, " send-in input ", &in2_buff, f_log);

   if(ecParams.pInfo.params.pcmType.sample_frequency == 8000){ /* 8 KHz */
      delay = (Ipp32s) (clParams.fdelay * 8000 * 2/1000);
   }else{ /* 16 KHz */
      delay = (Ipp32s) (clParams.fdelay * 16000 * 2/1000);
   }
   flen -= delay;
   if(flen < 0)  flen = 0;
   if (flen < in_len)
       in_len = flen;

   out_buff=(Ipp8u*)ippsMalloc_8u(in_len);/* allocate output buffer */
   if(!out_buff){ /* allocate output buffer */
      sprintf(pString, "\nNo memory for buffering of %d output bytes", in_len);
      OutputInfoString(1, f_log, (const Ipp8s*)pString);
      if(f_log) fclose(f_log);
      return MEMORY_FAIL;
   }

   /* time stamp prior to threads creation, creation and running time may overlap. */
   measure_start(&measure);

   n_repeat = clParams.nRepeat;
   while(n_repeat--) {
      USCStatus = ecParams.pUSC_EC_Fxns->std.Init((const USC_EC_Option *)&ecParams.pInfo.params, ecParams.pBanks, &ecParams.objEC);
      if(USCStatus!=USC_NoError) {
        OutputInfoString(1, f_log,"\nCan not initialize the EC object!");
        if(ecParams.pBanks) ippsFree(ecParams.pBanks);
        if(fp_rin) fclose(fp_rin);
        if(fp_sin) fclose(fp_sin);
        if(fp_sout) fclose(fp_sout);
        if(clParams.puttocsv) { if(f_csv) vm_file_fclose(f_csv); }
        if(f_log) fclose(f_log);
        return ERROR_INIT;
      }
      ecParams.pUSC_EC_Fxns->std.GetInfo(ecParams.objEC, (USC_EC_Info *)&ecParams.pInfo);
      frameNum = in_len/ecParams.pInfo.params.framesize;
      tailNum = (in_len/sizeof(Ipp16s)) - (ecParams.pInfo.params.framesize/sizeof(Ipp16s))*frameNum;

      out_buff_cur = out_buff;
      in1_buff_cur = in1_buff;
      in2_buff_cur = in2_buff+ delay; /* shift forward the sin at delay */

      for (i = 0; i < frameNum; i++) {
          ecParams.pUSC_EC_Fxns->CancelEcho(ecParams.objEC, (Ipp16s *)in2_buff_cur,
              (Ipp16s *)in1_buff_cur, (Ipp16s *)out_buff_cur);//4,6,9,11,14,19,21,26,29,31,34,36,39,41,44,46,49,51
          in1_buff_cur += ecParams.pInfo.params.framesize;
          in2_buff_cur += ecParams.pInfo.params.framesize;
          out_buff_cur += ecParams.pInfo.params.framesize;
      }
      for (i = 0; i < tailNum; i++) {
          ippsZero_16s((Ipp16s *)out_buff_cur, tailNum);
      }
   }

   measure_end(&measure);

   if (PostProcessPCMstream((Ipp8s *)out_buff, in_len)) {
       sprintf(pString, "No memory for load of %d bytes convert from linear PCM to special pack value.",in_len);
       OutputInfoString(1, f_log, (const Ipp8s*)pString);
       if(f_log) fclose(f_log);
       return MEMORY_FAIL;
   }
   /* Write output PCM to the output file */
   fwrite(out_buff, 1, in_len, fp_sout);

   for(i=0; i<ecParams.nBanks;i++){
     if(ecParams.pBanks[i].pMem) ippsFree(ecParams.pBanks[i].pMem);
     ecParams.pBanks[i].pMem = NULL;
   }
   if(ecParams.pBanks) { ippsFree(ecParams.pBanks); ecParams.pBanks = NULL; }
   ippsFree(out_buff);

   speech_sec = (in_len / 2 * clParams.nRepeat)/(double)ecParams.pInfo.params.pcmType.sample_frequency;
   measure_output(f_log, &measure, speech_sec);
   sprintf(pString, "Done %d samples of %d Hz PCM wave file (%g sec)\n",
       (in_len>>1) * clParams.nRepeat, ecParams.pInfo.params.pcmType.sample_frequency, speech_sec);
   OutputInfoString(1, f_log, (const Ipp8s*)pString);

   if(clParams.puttocsv) {
       Ipp8s* rinFile;
       Ipp8s* sinFile;
       if ((rinFile = strrchr(clParams.rinFileName, '/')) != NULL) {
           rinFile += 1;
       } else if ((rinFile = strrchr(clParams.rinFileName, '\\')) != NULL) {
           rinFile += 1;
       } else
           rinFile = clParams.rinFileName;
       if ((sinFile = strrchr(clParams.sinFileName, '/')) != NULL) {
           sinFile += 1;
       } else if ((sinFile = strrchr(clParams.sinFileName, '\\')) != NULL) {
           sinFile += 1;
       } else
           sinFile = clParams.sinFileName;
       i=sprintf(pString, clParams.ECName);
       i += sprintf(pString + i,",");
       switch(clParams.alg) {
            case EC_FULLBAND:
                i += sprintf(pString + i,"fullband,");
                break;
            case EC_SUBBAND:
                i += sprintf(pString + i,"subband,");
                break;
            case EC_FASTSUBBAND:
                i += sprintf(pString + i,"fast subband,");
                break;
            default:
                i += sprintf(pString + i,"subband,");
       }
       switch(clParams.adapt) {
            case 2:
                i += sprintf(pString + i,"lite,");
                break;
            default:
                i += sprintf(pString + i,"full,");
       }
       i += sprintf(pString + i,"%d,",clParams.tail);
       i += sprintf(pString + i,"%d,%s,%s,%4.2f,%4.2f",
            ecParams.pInfo.params.pcmType.sample_frequency, rinFile, sinFile, speech_sec,
            measure.speed_in_mhz);
       vm_string_fprintf(f_csv,VM_STRING("%s\n"),pString);
       vm_file_fclose(f_csv);
   }

   ippsFree(in1_buff);
   ippsFree(in2_buff);

   fclose(fp_rin);
   fclose(fp_sin);
   fclose(fp_sout);

   OutputInfoString(1, f_log,"Completed !\n");
   if(f_log) fclose(f_log);
   return 0;
}
void roiDetector::iniPiramide()
{
    int i;
    int tamBuftmpHarris;

    ippiPyrDownGetBufSize_Gauss5x5(params.width,ipp8u,1,&tamBuftmpPirG);
    buftmpPirG = (Ipp8u *) ippsMalloc_8u(tamBuftmpPirG);
    sizePir[0].width=params.width;
    sizePir[0].height=params.height;

    sizeWholePir=params.size;
    ApiramideG=(TipoPiramide *) malloc(sizeof(TipoPiramide));
    BpiramideG=(TipoPiramide *) malloc(sizeof(TipoPiramide));
    LecpiramideG=ApiramideG;
    EscpiramideG=BpiramideG;
    (* ApiramideG)[0] = (Ipp8u *) ippsMalloc_8u(sizePir[0].width*sizePir[0].height);
    (* BpiramideG)[0] = (Ipp8u *) ippsMalloc_8u(sizePir[0].width*sizePir[0].height);
    respHarris[0] = (Ipp32f *) ippsMalloc_32f(sizePir[0].width*sizePir[0].height*sizeof(Ipp32f));
    mapaHarris[0] = (Ipp8u *) ippsMalloc_8u(sizePir[0].width*sizePir[0].height);

    for (i=1; i<params.pyrLevels; i++) {
        sizePir[i].width=(sizePir[i-1].width)/2;
        sizePir[i].height=(sizePir[i-1].height)/2;
        sizeWholePir+=sizePir[i].width*sizePir[i].height;
        (* ApiramideG)[i] = (Ipp8u *) ippsMalloc_8u(sizePir[i].width*sizePir[i].height);
        (* BpiramideG)[i] = (Ipp8u *) ippsMalloc_8u(sizePir[i].width*sizePir[i].height);
        respHarris[i] = (Ipp32f *) ippsMalloc_32f(sizePir[i].width*sizePir[i].height*sizeof(Ipp32f));
        mapaHarris[i] = (Ipp8u *) ippsMalloc_8u(sizePir[i].width*sizePir[i].height);
    }

    ippiPyrUpGetBufSize_Gauss5x5(sizePir[0].width,ipp8u,1,&tamBuftmpPirL);
    buftmpPirL = (Ipp8u *) ippsMalloc_8u(tamBuftmpPirL);

    for (i=0; i<params.pyrLevels; i++)
        piramideL[i] = (Ipp8u *) ippsMalloc_8u(sizePir[i].width*sizePir[i].height);

    //Inicializaci� datos para esquinas

    AROIList=new TipoROIList;
    BROIList=new TipoROIList;
    LecROIList=AROIList;
    EscROIList=BROIList;
    A=true;
    for (i=0; i<params.pyrLevels; i++) {
        AROIList->tambufROIs[i]=10*sizeof(int)*NFEAT;
        AROIList->numROIs[i]=0;
        AROIList->ROIList[i]=(int *) calloc(AROIList->tambufROIs[i],1);

        BROIList->tambufROIs[i]=10*sizeof(int)*NFEAT;
        BROIList->numROIs[i]=0;
        BROIList->ROIList[i]=(int *) calloc(BROIList->tambufROIs[i],1);

        tambufesqHarris[i]=10*sizeof(int)*2;
        numesqHarris[i]=0;
        esqHarris[i]=(int *) malloc(tambufesqHarris[i]);

        ippiMinEigenValGetBufferSize_32f_C1R(sizePir[i], WHARRIS, WHARRIS, &tamBuftmpHarris);
        buftmpHarris[i] = (Ipp8u *) ippsMalloc_8u(tamBuftmpHarris);
    }

    //Inicializaci� informaci� para el prisma (el ltimo nivel no se utiliza)

    for (i=params.pyrLevels-1; i>=0; i--) {
        infoPrisma[i].sizeImg.width=sizePir[i].width;
        infoPrisma[i].sizeImg.height=sizePir[i].height;
        if (i>=params.pyrLevels-2) {
            infoPrisma[i].sizeROI.width=sizePir[i].width;  //tama� del prisma=tama� del penltimo nivel
            infoPrisma[i].sizeROI.height=sizePir[i].height;
        } else {
            infoPrisma[i].sizeROI.width=sizePir[params.pyrLevels-3].width;  //tama� del prisma=tama� del penltimo nivel
            infoPrisma[i].sizeROI.height=sizePir[params.pyrLevels-3].height;
        }
        infoPrisma[i].xIni=(infoPrisma[i].sizeImg.width-infoPrisma[i].sizeROI.width)/2;
        infoPrisma[i].yIni=(infoPrisma[i].sizeImg.height-infoPrisma[i].sizeROI.height)/2;
        infoPrisma[i].despIni=infoPrisma[i].yIni*infoPrisma[i].sizeImg.width+infoPrisma[i].xIni;
    }
}
Example #22
0
int main(int argc, char *argv[]) {

  char *buf_in;
  char *bitstream_buf;
  char *p;
  char *f;
  long file_size;
  int i;

  if(argc != 3) {
    fprintf(stderr, "Usage: my_enc audio.raw audio.g729\n");
    exit(-1);
  }
  
  fprintf(stderr, "Converting %s to %s\n", argv[1], argv[2]);

  USC_Fxns *USC_CODEC_Fxns;
  USC_CodecInfo pInfo;
  USC_Handle encoder;

  USC_PCMStream in;
  USC_Bitstream out;
  USC_MemBank* pBanks;

  int nbanks = 0;
  int maxbitsize;
  int inFrameSize;
  int outFrameSize = 0;

  USC_CODEC_Fxns = USC_GetCodecByName_xx2 ();
  USC_CODEC_Fxns->std.GetInfo((USC_Handle)NULL, &pInfo); /* codec info */
  ((USC_Option*)pInfo.params)->modes.truncate = 1;
  ((USC_Option*)pInfo.params)->direction = 0;
  ((USC_Option*)pInfo.params)->modes.vad = 0;

  FILE *f_in = fopen(argv[1], "r");
  FILE *f_out = fopen(argv[2], "w");

  fseek(f_in, 0, SEEK_END);
  file_size = ftell(f_in);
  fseek(f_in, 0, SEEK_SET);

  buf_in = ippsMalloc_8s(file_size);
  fread(buf_in, file_size, 1, f_in);
  p = buf_in;
  f = buf_in + file_size;

  USC_CODEC_Fxns->std.NumAlloc(pInfo.params, &nbanks);
  pBanks = (USC_MemBank*)ippsMalloc_8u(sizeof(USC_MemBank)*nbanks);
  USC_CODEC_Fxns->std.MemAlloc(pInfo.params, pBanks);
  for(i=0; i<nbanks;i++) {
    if(!(pBanks[i].pMem = ippsMalloc_8u(pBanks->nbytes))) {
      printf("\nLow memory: %d bytes not allocated\n",pBanks->nbytes);
      return -1;
    }
  }

  inFrameSize = getInFrameSize();
  outFrameSize = getOutFrameSize_xx3();

  bitstream_buf = ippsMalloc_8s(pInfo.maxbitsize);

  in.bitrate = pInfo.params->modes.bitrate;
  maxbitsize = pInfo.maxbitsize;
  USC_CODEC_Fxns->std.Init(pInfo.params, pBanks, &encoder);

  ippCoreSetFlushToZero( 1, NULL );
  in.pcmType.bitPerSample = pInfo.pcmType->bitPerSample;
  in.pcmType.sample_frequency = pInfo.pcmType->sample_frequency;
  out.nbytes  = maxbitsize;
  out.pBuffer = bitstream_buf;

  USC_CODEC_Fxns->std.Reinit(&((USC_Option*)pInfo.params)->modes, encoder);

  while(p < f) {
    in.pBuffer = p;
    USC_CODEC_Fxns->std.Encode (encoder, &in, &out);
    fwrite(out.pBuffer, 10, 1, f_out);
    p += inFrameSize; 
  }

  fclose(f_out);
  fclose(f_in);

  return 0;
}