duration=(tend-tstart)*saveFilter->getInfo()->frequency;
duration=(tend-tstart); duration*=saveFilter->getInfo()->frequency;
A_saveAudioDecodedTest (char *name){// debug audio seek  uint32_t len, gauge = 0;  uint32_t written = 0;  FILE *out;  AVDMGenericAudioStream *saveFilter;    uint64_t sampleTarget,sampleCurrent;  #undef BITT#define BITT 4*1152#define OUTCHUNK 1024*1024  uint8_t *outbuffer;  if (!currentaudiostream)    return;  if (currentaudiostream->isCompressed ())    if (!currentaudiostream->isDecompressable ())      {	GUI_Alert ("Cannot decompress audio frame!");	return;      }  if (!(out = fopen (name, "wb")))    {      GUI_Alert ("Cannot write file");      return;    }  outbuffer = (uint8_t *) malloc (2 * OUTCHUNK);	// 1Meg cache;  if (!outbuffer)    {      GUI_Alert ("Memory Error!");      return;    }// re-ignite first filter...  currentaudiostream->beginDecompress ();  // Write Wav header  /* Sat Nov 09 06:11:52 CET 2002 Fixes from Maik Broemme <mbroemme@plusserver.de> */  /* If you set negative delay and save the audio stream, the saved stream was shorter than the video stream. */  /* Example: video stream is 10 minutes long, audio stream perhaps 20 minutes, you need the audio stream from */  /*          minute 1 until 11, so you setup an audio delay from -60 seconds, but this 60 seconds were removed */  /*          from begin and end of the audio stream. That was not good :) Now it runs correctly also if you use */  /*          audio stream with same length then video, therefore is premature ending :) */ 	saveFilter =	buildAudioFilter (currentaudiostream,			  video_body->getTime (frameStart), 0xffffffff);       	DIA_working *work=new DIA_working("Saving audio");////  Create First filter that is null filter//  saveFilter->writeHeader (out);  uint32_t tstart,tend,samples;  double duration;  tstart=video_body->getTime(frameStart);  tend=video_body->getTime(frameEnd+1);  duration=(tend-tstart)*saveFilter->getInfo()->frequency;  duration/=1000.;    sampleTarget=(uint64_t)floor(duration);  sampleCurrent=0;  gauge=0;    while ((sampleCurrent<sampleTarget))    {      if(!saveFilter->getPacket(outbuffer + gauge,&len,&samples))      {        printf("Audio save:Read error\n");      	break;      }      //      printf("Got : %lu\n",len2);      gauge += len;      sampleCurrent+=samples;      // update GUI                   	if (work->update (sampleCurrent>>10, sampleTarget>>10))	// abort request ?	    break;;      if (gauge > OUTCHUNK)	// either out buffer is full		{	  fwrite (outbuffer, 1, gauge, out);	  	  written += gauge;	  gauge = 0;	}   	    };// Clean up	if(gauge)	{		fwrite (outbuffer,  gauge,1, out);	  		written += gauge;		gauge = 0;		}  saveFilter->endWrite (out, written);  fclose (out);  free (outbuffer);  delete work;  deleteAudioFilter ();  currentaudiostream->endDecompress ();  printf ("AudioSave: actually written %u\n", written);  printf ("Audiosave: target sample:%llu, got :%llu\n",sampleTarget,sampleCurrent);}