home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 106 / EnigmaAmiga106CD.iso / software / sviluppo / ahisrc / device / dspecho.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-04-22  |  4.7 KB  |  206 lines

  1. /* $Id: dspecho.c,v 4.4 1999/04/22 19:42:07 lcs Exp $ */
  2.  
  3. /*
  4.      AHI - Hardware independent audio subsystem
  5.      Copyright (C) 1996-1999 Martin Blom <martin@blom.org>
  6.      
  7.      This library is free software; you can redistribute it and/or
  8.      modify it under the terms of the GNU Library General Public
  9.      License as published by the Free Software Foundation; either
  10.      version 2 of the License, or (at your option) any later version.
  11.      
  12.      This library is distributed in the hope that it will be useful,
  13.      but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.      Library General Public License for more details.
  16.      
  17.      You should have received a copy of the GNU Library General Public
  18.      License along with this library; if not, write to the
  19.      Free Software Foundation, Inc., 59 Temple Place - Suite 330, Cambridge,
  20.      MA 02139, USA.
  21. */
  22.  
  23. #include <config.h>
  24. #include <CompilerSpecific.h>
  25.  
  26. #include "ahi_def.h"
  27. #include "dsp.h"
  28.  
  29.  
  30. /* See dspecho_68k.a för more information */
  31.  
  32.  
  33.  
  34. static void
  35. EchoMono32 ( LONG          loops,
  36.              struct Echo  *es,
  37.              void        **buffer,
  38.              void        **srcptr,
  39.              void        **dstptr)
  40. {
  41.   LONG *buf;
  42.   WORD *src, *dst;
  43.   LONG sample, delaysample;
  44.  
  45.   buf = *buffer;
  46.   src = *srcptr;
  47.   dst = *dstptr;
  48.  
  49.   while(loops > 0)
  50.   {
  51.     sample      = *buf >> 16;
  52.     delaysample = *src++;
  53.  
  54.     *buf++ = es->ahiecho_MixN * sample + es->ahiecho_MixD * delaysample;
  55.  
  56.     sample = es->ahiecho_FeedbackNS * sample + 
  57.              es->ahiecho_FeedbackDS * (delaysample + 1);
  58.     
  59.     *dst++ = sample >> 16;
  60.  
  61.     loops--;
  62.   }
  63.  
  64.   *buffer = buf;
  65.   *srcptr = src;
  66.   *dstptr = dst;
  67. }
  68.  
  69. static void
  70. EchoStereo32 ( LONG          loops,
  71.                struct Echo  *es,
  72.                void        **buffer,
  73.                void        **srcptr,
  74.                void        **dstptr)
  75. {
  76.   LONG *buf;
  77.   WORD *src, *dst;
  78.   LONG sample, sampleL, sampleR, delaysampleL, delaysampleR;
  79.   
  80.   buf = *buffer;
  81.   src = *srcptr;
  82.   dst = *dstptr;
  83.  
  84.   while(loops > 0)
  85.   {
  86.     sampleL      = *buf >> 16;
  87.     delaysampleL = *src++;
  88.  
  89.     *buf++ = es->ahiecho_MixN * sampleL + es->ahiecho_MixD * delaysampleL;
  90.  
  91.     sampleR      = *buf >> 16;
  92.     delaysampleR = *src++;
  93.  
  94.     *buf++ = es->ahiecho_MixN * sampleR + es->ahiecho_MixD * delaysampleR;
  95.  
  96.     sample = es->ahiecho_FeedbackDS * (delaysampleL + 1) +
  97.              es->ahiecho_FeedbackDO * (delaysampleR + 1) +
  98.              es->ahiecho_FeedbackNS * sampleL +
  99.              es->ahiecho_FeedbackNO * sampleR;
  100.  
  101.     *dst++ = sample >> 16;
  102.  
  103.     sample = es->ahiecho_FeedbackDO * (delaysampleL + 1) +
  104.              es->ahiecho_FeedbackDS * (delaysampleR + 1) +
  105.              es->ahiecho_FeedbackNO * sampleL +
  106.              es->ahiecho_FeedbackNS * sampleR;
  107.  
  108.     *dst++ = sample >> 16;
  109.  
  110.     loops--;
  111.   }
  112.  
  113.   *buffer = buf;
  114.   *srcptr = src;
  115.   *dstptr = dst;
  116. }
  117.  
  118.  
  119.  
  120. static void
  121. do_DSPEcho ( struct Echo *es,
  122.              void *buf,
  123.              struct AHIPrivAudioCtrl *audioctrl,
  124.              void (*echofunc)(LONG, struct Echo *, void **, void **, void **) )
  125. {
  126.   LONG  samples, loops;
  127.   ULONG offset;
  128.   void *srcptr, *dstptr;
  129.  
  130.   samples = audioctrl->ac.ahiac_BuffSamples;
  131.   offset  = es->ahiecho_Offset;
  132.   srcptr  = es->ahiecho_SrcPtr;
  133.   dstptr  = es->ahiecho_DstPtr;
  134.  
  135.   while(samples > 0)
  136.   {
  137.     /* Circular buffer stuff */  
  138.     
  139.     if(srcptr >= es->ahiecho_EndPtr)
  140.     {
  141.       srcptr = (char *) srcptr - es->ahiecho_BufferSize;
  142.     }
  143.  
  144.     if(dstptr >= es->ahiecho_EndPtr)
  145.     {
  146.       dstptr = (char *) dstptr - es->ahiecho_BufferSize;
  147.     }
  148.  
  149.     if(offset >= es->ahiecho_BufferLength)
  150.     {
  151.       offset -= es->ahiecho_BufferLength;
  152.     }
  153.  
  154.  
  155.  
  156.     if(offset < audioctrl->ac.ahiac_MaxBuffSamples)
  157.     {
  158.       loops = audioctrl->ac.ahiac_MaxBuffSamples - offset;
  159.     }
  160.     else if(offset <= es->ahiecho_Delay)
  161.     {
  162.       loops = audioctrl->ac.ahiac_MaxBuffSamples;
  163.     }
  164.     else
  165.     {
  166.       loops = audioctrl->ac.ahiac_MaxBuffSamples + es->ahiecho_Delay - offset;
  167.     }
  168.  
  169.     loops = min(loops, samples);
  170.     
  171.     samples -= loops;
  172.     offset  += loops;
  173.  
  174.     /* Call echo function */
  175.  
  176.     echofunc(loops, es, &buf, &srcptr, &dstptr);
  177.  
  178.   } // while(samples > 0)
  179.  
  180.   es->ahiecho_Offset = offset;
  181.   es->ahiecho_SrcPtr = srcptr;
  182.   es->ahiecho_DstPtr = dstptr;
  183. }
  184.  
  185.  
  186.  
  187.  
  188. /* Entry points **************************************************************/
  189.  
  190. void
  191. do_DSPEchoMono32 ( struct Echo *es,
  192.                    void *buf,
  193.                    struct AHIPrivAudioCtrl *audioctrl )
  194. {
  195.   do_DSPEcho(es, buf, audioctrl, EchoMono32);
  196. }
  197.  
  198. void
  199. do_DSPEchoStereo32 ( struct Echo *es,
  200.                      void *buf,
  201.                      struct AHIPrivAudioCtrl *audioctrl )
  202.   do_DSPEcho(es, buf, audioctrl, EchoStereo32);
  203. }
  204.  
  205.