Example #1
0
UInt8 tapeReadHeader()
{
    if (ramImageBuffer != NULL) {
        UInt8 buf[32];
        int i;
        for (i = 0; i < tapeHeaderSize; i++) {
            if (!tapeRead(buf + i)) {
                return 0;
            }
        }

        while (memcmp(buf, tapeHeader, tapeHeaderSize)) {
            memmove(buf, buf + 1, tapeHeaderSize - 1);
            if (!tapeRead(buf + tapeHeaderSize - 1)) {
                return 0;
            }
        }
        return 1;
    }

    return 0;
}
Example #2
0
static UInt8 readA(SviPPI* ppi)
{
#if 1
    // dvik: reverted to 2.8 since wav support is not finished yet
    return boardCaptureUInt8(16, sviJoyIoReadTrigger(ppi->joyIO)) | 
        (boardGetCassetteInserted() ? 0:0x40);
#else
    UInt8 value;
    UInt8 casdat = 0;

    value = boardCaptureUInt8(16, sviJoyIoReadTrigger(ppi->joyIO));
    value |= boardGetCassetteInserted() ? 0:0x40; 

    tapeRead(&casdat);
    value |= (casdat) ? 0:0x80;

    dacWrite(ppi->dac, DAC_CH_MONO, (casdat & 0x01) ? 0 : 255);

    return value;
#endif
}
Example #3
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;
}