예제 #1
0
void audioDHandle(void * buffer, int32u_t length)
{
	if( NULL!=buffer && length>0 )
	{
		struct adpcm_state state;
		struct PacketHead * pp = (struct PacketHead *)buffer;
		if( pp->mode == 0x00 )		
		{
			printf("mode 00    ()\n");
			indexfile=0;
			mymemcpy(musicdatafile,
					(char*)&buffer[sizeof(struct PacketHead)],
					(char*)length-sizeof(struct PacketHead));
			indexfile += (length-sizeof(struct PacketHead));
		}
		else if( pp->mode == 0x02)
		{
			printf("mode 02    ()\n");
			state.index  =0;
        		state.valprev=0;
			adpcm_decoder( &buffer[sizeof(struct PacketHead)],
							adpbuffer,
							(length-sizeof(struct PacketHead))*2, &state );
			mymemcpy( &musicdatafile[indexfile], adpbuffer, (length-sizeof(struct PacketHead))*4 );
			indexfile += (length-sizeof(struct PacketHead))*4;
		}
		else if( pp->mode == 0x0f)
		{
			printf("mode 0f    ()\n");
			state.index  =0;
        		state.valprev=0;
			adpcm_decoder( &buffer[sizeof(struct PacketHead)], adpbuffer, (length-sizeof(struct PacketHead))*2, &state );
			mymemcpy( &musicdatafile[indexfile], adpbuffer, (length-sizeof(struct PacketHead))*4 );
			indexfile += (length-sizeof(struct PacketHead))*4;
			
			/*int justp=0;
			for(justp=0; justp<indexfile; justp++)
			{
				printf("%x, ", musicdatafile[justp] );
			}*/

			//received a complete file , so play it out.
			playwav16m( musicdatafile, FILELEN*2 );
		}
		else 
		{
			printf("packet mode error!\n");
		}
	}
	else
	{
		printf("buffer null or length <=0 \n");
	}
}
예제 #2
0
int main()
{
    long ct_repeat=0;
    long ct_repeat_max=1;
    int ct_return=0;
    int n;

    if (getenv("CT_REPEAT_MAIN")!=NULL) ct_repeat_max=atol(getenv("CT_REPEAT_MAIN"));

    while(1) {
        struct adpcm_state current_state = state;

	n = read(0, abuf, NSAMPLES/2);
	if ( n < 0 ) {
	    perror("input file");
	    exit(1);
	}
	if ( n == 0 ) break;
  
        /* gfursin */
        for (ct_repeat=0; ct_repeat<ct_repeat_max; ct_repeat++)
        {
	  /* The call to adpcm_decoder modifies the state. We need to make a
	     copy of the state and to restore it before each iteration of the
	     kernel to make sure we do not alter the output of the
	     application. */
          state = current_state;
  	  adpcm_decoder(abuf, sbuf, n*2, &state);  /* modifies state */
	}

	write(1, sbuf, n*4);
    }
    return 0;
}
예제 #3
0
파일: codec_vdvi.c 프로젝트: JensenSung/rat
int
vdvi_decoder(uint16_t idx, u_char *decoder_state, coded_unit *c, sample *data)
{
        int samples, len;
        u_char dvi_buf[80];
        vdvi_state_t *v;

        assert(decoder_state);
        assert(c);
        assert(data);
        assert(idx < VDVI_NUM_FORMATS);

        v = (vdvi_state_t*)decoder_state;

	if (c->state_len > 0) {
		assert(c->state_len == sizeof(struct adpcm_state));
		memcpy(v->as, c->state, sizeof(struct adpcm_state));
		v->as->valprev = ntohs(v->as->valprev);
	}

        bs_attach(v->bs, c->data, c->data_len);
        len = vdvi_decode(v->bs, dvi_buf, 160);

        samples = cs[idx].format.bytes_per_block / sizeof(sample);
	adpcm_decoder(dvi_buf, data, samples, v->as);

        return samples;
}
예제 #4
0
void main_adpcmdecoder() {
    int n;

    while ( (n=fread(dec_sbuf, 1, NSAMPLES/2,filein_adpcmdecoder)) > 0 )
    {
	adpcm_decoder(dec_abuf, dec_sbuf, n*2, &state_decoder);
	fwrite(dec_sbuf, 1, n*4, fileout_adpcmdecoder);
    }

    //fprintf(stderr, "Final valprev=%d, index=%d\n",state.valprev, state.index);
    
    return;
}
예제 #5
0
int main(void) {
    int n;

    while(1) {
	n = read(0, abuf, NSAMPLES/2);
	if ( n < 0 ) {
	    perror("input file");
	    exit(1);
	}
	if ( n == 0 ) break;
	adpcm_decoder(abuf, sbuf, n*2, &state);
	write(1, sbuf, n*4);
    }
    fprintf(stderr, "Final valprev=%d, index=%d\n",
	    state.valprev, state.index);
    exit(0);
}
예제 #6
0
파일: rawdaudio.c 프로젝트: 8l/csolve
main() {
    int n;

    char  abuf[NSAMPLES/2];
    short sbuf[NSAMPLES];

    struct adpcm_state state;

    while(1) {
	n = read(0, abuf, NSAMPLES/2);
	if ( n < 0 ) {
	    perror("input file");
	    exit(1);
	}
	if ( n == 0 ) break;
	adpcm_decoder(abuf, sbuf, n*2, &state);
	write(1, sbuf, n*4);
    }
    fprintf(stdout, "Final valprev=%d, index=%d\n",
	    state.valprev, state.index);
    exit(0);
}
예제 #7
0
int main(int argc, char *argv[])
{
    int fd,mid;
    int arg;
    int status;
    int i;
    // for encode use
    unsigned char inbuf[FRAME_SIZE*4];  // 2 channels , 16bit data , so *4
    short         inenc[FRAME_SIZE];    // 1 channel, 16bit data, but short type, so *1
    unsigned char encbuf[FRAME_SIZE/2];
    // for decode use
    short         decbuf[FRAME_SIZE];   // decode restore inenc
    unsigned char outbuf[FRAME_SIZE*4]; // restore inbuf 
    // adpcm
    struct adpcm_state enc_state, dec_state;
    //----------------------------------------------------------------------
    fd = open("/dev/dsp", O_RDWR);
    arg = SIZE;
    printf("SIZE:=%d\n",arg);
    if (fd < 0)
    {
        perror("Open /dev/dsp fail");
        exit(1);
    }

    arg = SIZE;
    status = ioctl(fd, SNDCTL_DSP_SETFMT, &arg);
    if (status == -1)
    {
        perror("SNDCTL_DSP_SETFMT ioctl failed");
        exit(1);
    }

    arg    = CHANNELS;
    status = ioctl(fd, SNDCTL_DSP_CHANNELS, &arg);
    if (status == -1)
    {
        perror("SNDCTL_DSP_CHANNELS ioctl failed");
        exit(1);
    }

    ioctl(fd, SOUND_PCM_READ_CHANNELS, &arg);
    if (arg != CHANNELS)
    {
        perror("unable to set channels");
        exit(1);
    }

    arg = RATE;
    status = ioctl(fd, SNDCTL_DSP_SPEED, &arg);
    if (status == -1)
    {
        perror("SNDCTL_DSP_SPEED ioctl failed");
        exit(1);
    }

    if (arg != RATE)
    {
        perror("unable to set rate");
        exit(1);
    }

    mid = open("/dev/mixer",O_RDWR);
    arg = SOUND_MASK_MIC;
    ioctl(mid,SOUND_MIXER_READ_VOLUME,(char *)&arg);
    printf("volume is:%d\n",arg);
    arg = 55000;
    ioctl(mid,SOUND_MIXER_WRITE_VOLUME,(char *)&arg);
    //----------------------------------------------------------------------
    // encode
    enc_state.valprev = 0;
    enc_state.index = 0;
    //----------------------------------------------------------------------
    // decode
    dec_state.valprev = 0;
    dec_state.index = 0;
    //----------------------------------------------------------------------
    while(1)
    {
        // encode
        printf("encode\n");
        read(fd, inbuf, sizeof(inbuf));
        for(i=0;i<FRAME_SIZE*4;i+=4) inenc[i/4] = inbuf[i] + inbuf[i+1]*256;  
        adpcm_coder(inenc, encbuf, FRAME_SIZE, &enc_state);

        // decode
        printf("decode\n");
        adpcm_decoder(encbuf, decbuf, FRAME_SIZE/2, &dec_state); 
        for(i=0;i<FRAME_SIZE;i++)
        {
            outbuf[i*4] = decbuf[i] & 0xff;
            outbuf[i*4+1] = decbuf[i] >> 8;
            outbuf[i*4+2] = decbuf[i] & 0xff;
            outbuf[i*4+3] = decbuf[i] >> 8;
        }
        write(fd, outbuf, sizeof(outbuf)); 
    }
    //----------------------------------------------------------------------

    printf("finished\n");
    return 0;
}  
예제 #8
0
파일: adpcm2pcm.c 프로젝트: plessl/zippy
int main(int argc, char* argv[])
{

  char *sInputFileName;
  char *sOutputFileName;
  FILE *fpInputFile, *fpOutputFile;
  struct adpcm_state state;
  int iInputLen, iOutputLen;
  int iOutputSamples;
  
  char *cInputBuffer;
  char *cOutputBuffer;
  int iBytesRead, iBytesWritten;
  
  if (argc < 3){
    usage(argv[0]);
    exit(-1);
  }

  sInputFileName = argv[1];
  sOutputFileName = argv[2];
  
  
  printf("Converting ADPCM file %s to PCM file %s\n",
         sInputFileName, sOutputFileName);

  fpInputFile = fopen(sInputFileName, "r");
  if (!fpInputFile){
    perror("input file");
    exit(-2);
  }
  
  fpOutputFile = fopen(sOutputFileName, "w");
  if (!fpOutputFile) {
    perror("output file");
    exit(-3);
  }

  fseek(fpInputFile,0,SEEK_END);
  iInputLen = ftell(fpInputFile);
  printf("Input file has %d bytes\n",iInputLen);
  fseek(fpInputFile,0,SEEK_SET);

  /* each input sample (nibble) will be decoded to two output words (short) */
  iOutputSamples = iInputLen*2;   /* in samples (16bit words) */
  iOutputLen = iInputLen*4;       /* in bytes */
  
  printf("File will be decoded to %d output samples\n",iOutputSamples);
           
  cInputBuffer = (char *)malloc(iInputLen);
  if (!cInputBuffer){
    perror("input buffer:");
    exit(-3);
  }
  
  cOutputBuffer = (char *)malloc(iOutputLen);
  if (!cOutputBuffer){
    perror("output buffer:");
    exit(-4);
  }

  iBytesRead = 0;
  while (iBytesRead < iInputLen) {
    iBytesRead += fread(cInputBuffer+iBytesRead, sizeof(char),
                        iInputLen-iBytesRead,fpInputFile);
  }
  
  adpcm_decoder(cInputBuffer, (short *)cOutputBuffer, iOutputSamples, &state);

  iBytesWritten = 0;
  while (iBytesWritten < iOutputLen) {
    iBytesWritten += fwrite(cOutputBuffer+iBytesWritten, sizeof(char),
                            iOutputLen-iBytesWritten,fpOutputFile);
  }
      
  fclose(fpInputFile);
  fclose(fpOutputFile);

  return 0;
  
}