if (work->update (written, max)) goto abortSaveAudio; if ((len2 == 0) || (gauge > OUTCHUNK))
if (work->update (sampleCurrent>>10, sampleTarget>>10)) break;; if (gauge > OUTCHUNK)
A_saveAudioDecodedTest (char *name){// debug audio seek  uint32_t len2, gauge = 0;  uint32_t written = 0, max;  FILE *out;  AVDMGenericAudioStream *saveFilter;#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;    }// compute max bytes to read (with little margin)  max = getAudioByteCount( frameStart, frameEnd);  printf ("\n input : %u bytes\n", max);// 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 :) */  uint32_t delay = 0;  if (audioDelay > 0)    {      saveFilter =	buildAudioFilter (currentaudiostream,			  video_body->getTime (frameStart), max);    }  else    {      delay = currentaudiostream->convTime2Offset (-audioDelay);      saveFilter =	buildAudioFilter (currentaudiostream,			  video_body->getTime (frameStart), max + delay);    }    DIA_working *work=new DIA_working("Saving audio");////  Create First filter that is null filter//  saveFilter->writeHeader (out);  printf (".. Starting ..\n");  if (audioDelay > 0)    {      max = saveFilter->getLength ();    }  else    {      max = saveFilter->getLength () - delay;    }  printf ("\n Computed length : %u\n", max);  while (1)    {      len2 = saveFilter->readDecompress (BITT, outbuffer + gauge);      //      printf("Got : %lu\n",len2);      gauge += len2;      // update GUI                   	if (work->update (written, max))	// abort request ?	    goto abortSaveAudio;      if ((len2 == 0) || (gauge > OUTCHUNK))	// either out buffer is full	// or we read nothing -> end of file	{	  fwrite (outbuffer, 1, gauge, out);	  //      fflush(out);    	  written += gauge;	  gauge = 0;	  if (len2 == 0)	    break;		// premature ending	 	  //printf("\n written %lu/%lu max\n",written,max);	}      //      if(written>max) break; // we wrote everything !    };abortSaveAudio:  saveFilter->endWrite (out, written);  fclose (out);  free (outbuffer);  delete work;  deleteAudioFilter ();  currentaudiostream->endDecompress ();  printf (" actually written %u\n", written);}