add: cd->cd_SoundOK       = cd->cd_DelayedSoundOK;
context: MixGeneric ( REG(a0, struct Hook *Hook),              REG(a1, void *dst),              REG(a2, struct AHIPrivAudioCtrl *audioctrl) )#elsevoidMixGeneric ( struct Hook *Hook,              void *dst,              struct AHIPrivAudioCtrl *audioctrl )#endif{  struct AHIChannelData	*cd;  void                  *dstptr;  LONG                   samplesleft;//kprintf(".");  /* Clear the buffer */  memset( dst, 0, audioctrl->ahiac_BuffSizeNow );  /* Mix the samples */  audioctrl->ahiac_WetOrDry = AHIEDM_WET;  cd = audioctrl->ahiac_WetList;  while(TRUE)  {    while(cd != NULL) // .nextchannel    {      samplesleft = audioctrl->ac.ahiac_BuffSamples;      dstptr      = dst;      while(TRUE) // .contchannel      {        LONG samples;        LONG processed;        /* Call Sound Hook */        if(cd->cd_EOS)        {          cd->cd_EOS = FALSE;          if(audioctrl->ac.ahiac_SoundFunc != NULL)          {            CallSoundHook( audioctrl, &cd->cd_ChannelNo );          }        }        processed = 0;        if( cd->cd_AntiClickCount > 0 && cd->cd_FreqOK && cd->cd_SoundOK )        {          // Sound is ok and we're looking for a zero-crossing.          LONG try_samples;          samples     = min( samplesleft, cd->cd_Samples );          try_samples = min( samples, cd->cd_AntiClickCount );//kprintf("<search %ld = min( %ld, %ld )> ",try_samples, samples, cd->cd_AntiClickCount );          processed = ((ADDFUNC *) cd->cd_AddRoutine)( try_samples,                                                       cd->cd_ScaleLeft,                                                       cd->cd_ScaleRight,                                                      &cd->cd_Offset,                                                        cd->cd_Add,                                                       audioctrl,                                                       cd->cd_DataStart,                                                      &dstptr,                                                       cd,                                                       TRUE );          cd->cd_Samples -= processed;          samplesleft    -= processed;//kprintf("<searched %ld> ", processed);          if( try_samples == cd->cd_AntiClickCount ||              processed != samples )          {            // We either found a zero-crossing or looked as far as            // we were allowed to.            // Note that the sample end was NOT reached! If it was,            // cd_Samples will be zero and the second cd_AddRoutine            // call below will have no effect, and the cd_Next#?            // variables will be copied instead.            // Now start the delayed sound.            if( cd->cd_VolDelayed )            {              cd->cd_VolDelayed = FALSE;//kprintf("<vol> ");              cd->cd_VolumeLeft  = cd->cd_DelayedVolumeLeft;              cd->cd_VolumeRight = cd->cd_DelayedVolumeRight;              cd->cd_ScaleLeft   = cd->cd_DelayedScaleLeft;              cd->cd_ScaleRight  = cd->cd_DelayedScaleRight;              cd->cd_AddRoutine  = cd->cd_DelayedAddRoutine;            }            if( cd->cd_FreqDelayed )            {              cd->cd_FreqDelayed = FALSE;//kprintf("<freq> ");              cd->cd_FreqOK      = cd->cd_DelayedFreqOK;              cd->cd_Add         = cd->cd_DelayedAdd;                            // Since we have advanced, cd_Samples must be recalculated!              cd->cd_Samples     = CalcSamples( cd->cd_Add,                                                cd->cd_Type,                                                cd->cd_LastOffset,                                                cd->cd_Offset );            }            if( cd->cd_SoundDelayed )            {              cd->cd_SoundDelayed = FALSE;//kprintf("<sound> ");              cd->cd_Offset        = cd->cd_DelayedOffset;              cd->cd_FirstOffsetI  = cd->cd_DelayedFirstOffsetI;              cd->cd_LastOffset    = cd->cd_DelayedLastOffset;              cd->cd_DataStart     = cd->cd_DelayedDataStart;              cd->cd_Type          = cd->cd_DelayedType;              cd->cd_SoundOK       = cd->cd_DelayedSoundOK;              cd->cd_AddRoutine    = cd->cd_DelayedAddRoutine;              cd->cd_Samples       = cd->cd_DelayedSamples;              cd->cd_ScaleLeft     = cd->cd_DelayedScaleLeft;              cd->cd_ScaleRight    = cd->cd_DelayedScaleRight;              cd->cd_AddRoutine    = cd->cd_DelayedAddRoutine;            }//            cd->cd_AntiClickCount = 0;//kprintf("<new %ld %ld> ", cd->cd_Samples, cd->cd_AntiClickCount );          }          if( cd->cd_VolDelayed || cd->cd_FreqDelayed || cd->cd_SoundDelayed )          {            cd->cd_AntiClickCount -= processed;          }          else          {            cd->cd_AntiClickCount = 0;          }//kprintf("acc: %ld\n",cd->cd_AntiClickCount);        }        if( cd->cd_FreqOK && cd->cd_SoundOK )        {          // Sound is still ok, let's rock'n roll.          samples = min( samplesleft, cd->cd_Samples );//kprintf("<mixing %ld: %08lx> ", samples, cd->cd_AddRoutine);//kprintf("<%ld, %lx, %lx, %08lx, %08lx> ", samples, cd->cd_ScaleLeft, cd->cd_ScaleRight, cd->cd_DataStart,dstptr );          processed = ((ADDFUNC *) cd->cd_AddRoutine)( samples,                                                       cd->cd_ScaleLeft,                                                       cd->cd_ScaleRight,                                                      &cd->cd_Offset,                                                        cd->cd_Add,                                                       audioctrl,                                                       cd->cd_DataStart,                                                      &dstptr,                                                       cd,                                                       FALSE );//kprintf("<mixed %ld> ", processed );          cd->cd_Samples -= processed;          samplesleft    -= processed;          if( cd->cd_Samples == 0 )          {            /* Linear interpol. stuff */            cd->cd_StartPointL = cd->cd_TempStartPointL;            cd->cd_StartPointR = cd->cd_TempStartPointR;//kprintf("1 ");            /*            ** Offset always points OUTSIDE the sample after this            ** call.  Ie, if we read a sample at offset (Offset.I)            ** now, it does not belong to the sample just played.            ** This is true for both backward and forward mixing.            */            /* What we do now is to calculate how much futher we have               advanced. */              cd->cd_Offset -= cd->cd_LastOffset;            /*            ** Offset should now be added to the NEXT Offset. Offset            ** is positive of the sample was mixed forwards, and            ** negative if the sample was mixed backwards.  There is            ** one catch, however.  If the direction is about to            ** change now, Offset should instead be SUBTRACTED.            ** Let's check:            */            if( (cd->cd_Type ^ cd->cd_NextType) & AHIST_BW )            {              cd->cd_Offset = -cd->cd_Offset;            }            cd->cd_Offset += cd->cd_NextOffset;            cd->cd_FirstOffsetI = cd->cd_Offset >> 32;            /*            ** But what if the next sample is so short that we just            ** passed it!?  Here is the nice part.  CalcSamples            ** checks this, and sets cd_Samples to 0 in that case.            ** And the add routines doesn't do anything when asked to            ** mix 0 samples.  Assume we have passed a sample with 4            ** samples, and the next one is only 3.  CalcSamples            ** returns 0.  The (ADDFUNC) call above does not do            ** anything at all, OffsetI is still 4.  Now we subtract            ** LastOffsetI, which is 3.  Result:  We have passed the            ** sample with 1.  And guess what?  That's in range.            */            /* Now, let's copy the rest of the cd_Next#? stuff... */            cd->cd_FreqOK        = cd->cd_NextFreqOK;            cd->cd_SoundOK       = cd->cd_NextSoundOK;            cd->cd_Add           = cd->cd_NextAdd;            cd->cd_DataStart     = cd->cd_NextDataStart;            cd->cd_LastOffset    = cd->cd_NextLastOffset;            cd->cd_ScaleLeft     = cd->cd_NextScaleLeft;            cd->cd_ScaleRight    = cd->cd_NextScaleRight;            cd->cd_AddRoutine    = cd->cd_NextAddRoutine;            cd->cd_VolumeLeft    = cd->cd_NextVolumeLeft;            cd->cd_VolumeRight   = cd->cd_NextVolumeRight;            cd->cd_Type          = cd->cd_NextType;            cd->cd_Samples = CalcSamples( cd->cd_Add,                                          cd->cd_Type,                                          cd->cd_LastOffset,                                          cd->cd_Offset );            /* Also update all cd_Delayed#? stuff */            cd->cd_DelayedFreqOK        = cd->cd_NextFreqOK;            cd->cd_DelayedSoundOK       = cd->cd_NextSoundOK;            cd->cd_DelayedDataStart     = cd->cd_NextDataStart;            cd->cd_DelayedOffset        = cd->cd_NextOffset;            cd->cd_DelayedAdd           = cd->cd_NextAdd;            cd->cd_DelayedLastOffset    = cd->cd_NextLastOffset;            cd->cd_DelayedScaleLeft     = cd->cd_NextScaleLeft;            cd->cd_DelayedScaleRight    = cd->cd_NextScaleRight;            cd->cd_DelayedVolumeLeft    = cd->cd_NextVolumeLeft;            cd->cd_DelayedVolumeRight   = cd->cd_NextVolumeRight;            cd->cd_DelayedAddRoutine    = cd->cd_NextAddRoutine;            cd->cd_DelayedType          = cd->cd_NextType;            cd->cd_DelayedSamples       = cd->cd_Samples;            cd->cd_DelayedFirstOffsetI  = cd->cd_FirstOffsetI;            cd->cd_EOS = TRUE;      // signal End-Of-Sample            continue;               // .contchannel (same channel, new sound)          }        } // FreqOK && SoundOK        break; // .contchannel      } // while(TRUE)      cd = cd->cd_Succ;    } // while(cd)    if(audioctrl->ahiac_WetOrDry == AHIEDM_WET)    {      audioctrl->ahiac_WetOrDry = AHIEDM_DRY;      /*** AHIET_DSPECHO ***/      if(audioctrl->ahiac_EffDSPEchoStruct != NULL)      {        audioctrl->ahiac_EffDSPEchoStruct->ahiecho_Code(            audioctrl->ahiac_EffDSPEchoStruct, dst, audioctrl);      }      cd = audioctrl->ahiac_DryList;      if(audioctrl->ac.ahiac_Flags & AHIACF_POSTPROC)      {        /*** AHIET_MASTERVOLUME ***/        DoMasterVolume(dst, audioctrl);        /*        ** When AHIACB_POSTPROC is set, the dry data shall be placed        ** immediate after the wet data. This is done by modifying the        ** dst pointer        */        dst = (char *) dst + audioctrl->ac.ahiac_BuffSamples *                              SampleFrameSize(audioctrl->ac.ahiac_BuffType);      }      continue; /* while(TRUE) */    }    else    {      break; /* while(TRUE) */    }  } // while(TRUE)  /*** AHIET_MASTERVOLUME ***/  DoMasterVolume(dst, audioctrl);#if !defined( VERSIONPPC )  // This is handled in m68k code, in order to minimize cache flushes.  /*** AHIET_OUTPUTBUFFER ***/  DoOutputBuffer(dst, audioctrl);  /*** AHIET_CHANNELINFO ***/  DoChannelInfo(audioctrl);#endif /* !defined( VERSIONPPC ) */  return;}