Exemple #1
0
int main(int argc, char* argv[])
{
  FILE *output;
  int8_t *buffer;
  int32_t frequency,size,index,written;
  float average;
  int   data,i,j;
  bool  header;

  char  *ifile = NULL;
  char  *ofile = NULL;

  /* parse command line options */
  for (i=1; i<argc; i++) {

    if (argv[i][0]=='-') {

      for(j=1;j && argv[i][j]!='\0';j++)

	switch(argv[i][j]) {

	case 'n': normalize=true; break;
	case 'p': phase=false; break;
	case 'w': window=atof(argv[++i]);    j=-1; break;
	case 't': threshold=atoi(argv[++i]); j=-1; break;
	case 'e': envelope=atoi(argv[++i]);  j=-1; break;

	default:
	  fprintf(stderr,"%s: invalid option\n",argv[0]);
	  exit(1);
	}

      continue;
    }

    if (ifile==NULL) { ifile=argv[i]; continue; }
    if (ofile==NULL) { ofile=argv[i]; continue; }

    fprintf(stderr,"%s: invalid option\n",argv[0]);
    exit(1);
  }

  if (ifile==NULL || ofile==NULL) { showUsage(argv[0]); exit(1); }

  /* read the sample data and store it in buffer */
  frequency=tapeRead(ifile,&buffer,&size);
  if (frequency<0) {

    fprintf(stderr,"%s: failed reading %s\n",argv[0],ifile);
    exit(1);
  }

  /* open/create the output data file */
  if ((output=fopen(ofile,"wb"))==NULL) {

    fprintf(stderr,"%s: failed writing %s\n",argv[0],ofile);
    exit(1);
  }

  /* work on signal first */
  if (normalize) normalizeAmplitude(&buffer,size);
  for(i=0;i<envelope;i++) correctEnvelope(&buffer,size);

  /* let's do it */
  printf("Decoding audio data...\n");

  /* sample probably starts with some silence before the data, skip it */
  written=index=0;
  skipSilence(buffer,&index,size);

  header=false;
  /* loop through all audio data and extract the contents */
  for (;index<size;index++) {

    /* detect silent parts and skip them */
    if (isSilence(buffer,index,size)) {

      printf("[%.1f] skipping silence\n",(double)index/frequency);
      skipSilence(buffer,&index,size);
    }

    /* detect header and proces the data block followed */
    if (isHeader(buffer,index,size)) {

      printf("[%.1f] header detected\n",(double)index/frequency);
      average=skipHeader(buffer,&index,size);

      /* write .cas header if none already written */
      if (!header) {

	/* .cas headers always start at fixed positions */
	for (;written&7;written++) putc(0x00,output);

	/* write a .cas header */
	putc(0x1f,output); putc(0xa6,output);
	putc(0xde,output); putc(0xba,output);
	putc(0xcc,output); putc(0x13,output);
	putc(0x7d,output); putc(0x74,output);
	written+=8;
	header=true;
      }

      printf("[%.1f] data block\n",(double)index/frequency);

      while (!isSilence(buffer,index,size) && index<size) {
	data=readByte(buffer,&index,size,average);
	if (data>=0) { putc(data,output); written++; header=false; }
	else break;
      }

    } else {

      /* data found without a header, skip it */
      printf("[%.1f] skipping headerless data\n",(double)index/frequency);
      while(!isSilence(buffer,index,size) && index<size ) index++;
    }

  }

  fclose(output);
  free(buffer);

  printf("All done...\n");
  return 0;
}
Exemple #2
0
bool CFlowDepth::On_Execute_Position(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode){	

	int iX, iY;	
	int iNextX, iNextY;
	int x,y;
	int iOutletX, iOutletY;
	double fArea;
	double fDepth, fPreviousDepth = 0;

	if(	Mode != MODULE_INTERACTIVE_LDOWN || !Get_Grid_Pos(iOutletX, iOutletY) )
	{
		return( false );
	}

	m_pFlowDepth->Assign((double)0);

	fArea = m_pCatchArea->asFloat(iOutletX, iOutletY);
	
	if (fArea < m_dThreshold * 2.){ //check outlet point
		iNextX = iOutletX;
		iNextY = iOutletY;
		do{
			iOutletX = iNextX;
			iOutletY = iNextY;
			getNextCell(m_pDEM, iOutletX, iOutletY, iNextX, iNextY);
		}while (m_pCatchArea->asFloat(iOutletX, iOutletY) < m_dThreshold * 2. &&
				(iOutletX != iNextX || iOutletY != iNextY));
			
		if (m_pCatchArea->asFloat(iOutletX, iOutletY) < m_dThreshold * 2.){
			Message_Add(_TL("** Error : Wrong outlet point selected **"));
			return false;
		}//if
		Message_Add(_TL("** Warning : Outlet point was modified **"));
    }//if

	CalculateBasinGrid(m_pBasinGrid, m_pDEM, iOutletX, iOutletY);

	m_fMaxFlowAcc = m_pCatchArea->asFloat(iOutletX, iOutletY);		
    
    for(y=0; y<Get_NY() && Set_Progress(y); y++){		
		for(x=0; x<Get_NX(); x++){
			if (m_pCatchArea->asFloat(x,y) > m_dThreshold){
				if (isHeader(x,y)){					
					iNextX = x;
					iNextY = y;
					do {
						iX = iNextX;
						iY = iNextY;
						if (m_pFlowDepth->asFloat(iX,iY) == 0. && m_pBasinGrid->asInt(iX, iY) != 0){
							getNextCell(m_pDEM, iX, iY, iNextX, iNextY);
							fDepth = CalculateFlowDepth(iX,iY);
							if (fDepth == NO_DEPTH){
								m_pFlowDepth->Set_Value(iX,iY, fPreviousDepth);
							}//if
							else{
								fPreviousDepth = fDepth;
							}//else
						}//if
					}while ((iX != iOutletX || iY != iOutletY)
							&& (iX != iNextX || iY != iNextY));
				}//if
			}//if
		}//for
	}// for

	DataObject_Update(m_pFlowDepth);

	return true;

}//method
Exemple #3
0
int convertStreamtoOMA(u8* audioStream, int audioSize, u8** outputStream)
{
	if (!isHeader(audioStream, 0))
	{
		*outputStream = 0;
		return 0;
	}
	u8 headerCode1 = audioStream[2];
	u8 headerCode2 = audioStream[3];

	if (headerCode1 == 0x28)
	{
		bool bsupported = false;
		for (int i = 0; i < atrac3plusradiosize; i++) {
			if (atrac3plusradio[i] == headerCode2)
			{
				bsupported = true;
				break;
			}
		}
		if (bsupported == false)
		{
			*outputStream = 0;
			return 0;
		}
	}
	else
	{
		*outputStream = 0;
		return 0;
	}

	int frameSize = ((headerCode1 & 0x03) << 8) | (headerCode2 & 0xFF) * 8 + 0x10;
	int numCompleteFrames = audioSize / (frameSize + 8);
	int lastFrameSize = audioSize - (numCompleteFrames * (frameSize + 8));

	int omaStreamSize = OMAHeaderSize + numCompleteFrames * frameSize + lastFrameSize;

	// Allocate an OMA stream size large enough (better too large than too short)
	if (audioSize > omaStreamSize) omaStreamSize = audioSize;
	u8* oma = new u8[omaStreamSize];
	int omapos = 0;
	int audiopos = 0;

	omapos += getOmaHeader(OMA_CODECID_ATRAC3P, 0, headerCode1, headerCode2, oma);
	while (audioSize - audiopos > 8) {
		// Skip 8 bytes frame header
		audiopos += 8;
		int nextHeader = getNextHeaderPosition(audioStream, audiopos, audioSize, frameSize);
		u8* frame = audioStream + audiopos;
		int framelimit = audioSize - audiopos;
		if (nextHeader >= 0) {
			framelimit = nextHeader - audiopos;
			audiopos = nextHeader;
		} else
			audiopos = audioSize;
		WriteBuf(oma, omapos, frame, framelimit);
	}

	*outputStream = oma;
	return omapos;
}