Subversion Repositories pentevo

Rev

Blame | Last modification | View Log | Download | RSS feed | ?url?

  1. #ifndef _SNDRENDER_H_INCLUDED
  2. #define _SNDRENDER_H_INCLUDED
  3.  
  4. /*
  5.    sound resampling core for Unreal Speccy project
  6.    created under public domain license by SMT, jan.2006
  7. */
  8.  
  9.  
  10.  
  11.  
  12. #include "sndbuffer.h"
  13. #include "../sysdefs.h"
  14.  
  15. //=============================================================================
  16. #ifdef SND_EXTERNAL_BUFFER
  17.     #if ((SND_EXTERNAL_BUFFER_SIZE & (SND_EXTERNAL_BUFFER_SIZE-1)) != 0)
  18.         #pragma error("SND_EXTERNAL_BUFFER_SIZE must be power of 2")
  19.     #endif
  20. #endif
  21. //=============================================================================
  22.  
  23. union SNDSAMPLE;
  24. struct SNDOUT;
  25.  
  26. const unsigned SNDR_DEFAULT_SYSTICK_RATE = 3500000; // ZX-Spectrum Z80 clock
  27. const unsigned SNDR_DEFAULT_SAMPLE_RATE = 44100;
  28. const unsigned TICK_FF = 6;            // oversampling ratio: 2^6 = 64
  29. const unsigned MULT_C = 12;   // fixed point precision for 'system tick -> sound tick'
  30.  
  31. #ifdef SND_EXTERNAL_BUFFER
  32.  typedef unsigned bufptr_t;
  33. #else
  34.  typedef SNDSAMPLE *bufptr_t;
  35. #endif
  36.  
  37. //=============================================================================
  38. class SNDRENDER
  39. {
  40.     friend class SNDCOUNTER;
  41.    
  42. //-----------------------------------------------------------------------------
  43. public:
  44.  
  45.     //-------------------------------------------------------------------------
  46.     void set_timings(   unsigned clock_rate,
  47.                         unsigned sample_rate
  48.                 );
  49.     //-------------------------------------------------------------------------
  50.     // 'render' is a function that converts array of DAC inputs into PCM-buffer
  51.     unsigned render(    SNDOUT *src,
  52.                         unsigned srclen,
  53.                         unsigned clk_ticks,
  54.                         bufptr_t dst
  55.                 );
  56.     //-------------------------------------------------------------------------
  57.     // set of functions that fills buffer in emulation progress
  58.     void start_frame( bufptr_t dst);
  59.     //-------------------------------------------------------------------------
  60.     void update(     unsigned timestamp,
  61.                      unsigned l,
  62.                      unsigned r
  63.                 );
  64.     //-------------------------------------------------------------------------
  65.     unsigned end_frame( unsigned clk_ticks);
  66.     //-------------------------------------------------------------------------
  67.     unsigned end_empty_frame( unsigned clk_ticks);
  68.     //-------------------------------------------------------------------------
  69.     // new start position as previous end position
  70.     // (continue to fill buffer)
  71.     void start_frame()
  72.     {
  73.         start_frame( dstpos);
  74.     }
  75.     //-------------------------------------------------------------------------
  76.     SNDRENDER();
  77.    
  78. //-----------------------------------------------------------------------------
  79. protected:
  80.  
  81.     unsigned mix_l;
  82.     unsigned mix_r;
  83.    
  84.     bufptr_t dstpos;
  85.     bufptr_t dst_start;
  86.    
  87.     unsigned clock_rate;  // ┬їюфэр  ўрёЄюЄр (эр ¤Єющ ўрёЄюЄх ъышхэЄ фхырхЄ чряшё№ т SNDRENDER)
  88.     unsigned sample_rate; // ┬√їюфэр  ўрёЄюЄр (эр ¤Єющ ўрёЄюЄх ЇюЁьшЁєхЄё  т√їюфэющ pcm)
  89.  
  90. //-----------------------------------------------------------------------------
  91. private:
  92.  
  93.     unsigned base_tick; // ╥хъє∙шщ ЄръЄ ё ьюьхэЄр шэшЎшрышчрЎшш эр ўрёЄюЄх ютхЁё¤ьяышэур
  94.     unsigned tick;      // ╥ръЄ юЄ эрўрыр ърфЁр эр ўрёЄюЄх ютхЁё¤ьяышэур
  95.     unsigned s1_l;
  96.     unsigned s1_r;
  97.     unsigned s2_l;
  98.     unsigned s2_r;
  99.    
  100.     unsigned firstsmp;  // Alone Coder
  101.    
  102.     int oldleft;        // Alone Coder
  103.     int useleft;
  104.     int olduseleft;
  105.     int oldfrmleft;    
  106.    
  107.     int oldright;       // Alone Coder
  108.     int useright;      
  109.     int olduseright;
  110.     int oldfrmright;
  111.  
  112.     uint64_t passed_clk_ticks;  // ╫шёыю ЄръЄют тїюфэющ ўрёЄюЄ√ яЁю°хф°хх ё ьюьхэЄр шэшЎшрышчрЎшш
  113.     uint64_t passed_snd_ticks;  // ╫шёыю т√їюфэ√ї ё¤ьяыют эр ўрёЄюЄх ютхЁё¤ьяышэур яЁю°хф°хх ё ьюьхэЄр шэшЎшрышчрЎшш
  114. //   unsigned mult_const;
  115.  
  116.     void flush( unsigned endtick);
  117. };
  118. //=============================================================================
  119.  
  120.  
  121. //=============================================================================
  122. union SNDSAMPLE
  123. {
  124.    unsigned sample; // left/right channels in low/high WORDs
  125.    struct { unsigned short left, right; } ch; // or left/right separately
  126. };
  127.  
  128. struct SNDOUT
  129. {
  130.    unsigned timestamp; // in 'system clock' ticks
  131.    SNDSAMPLE newvalue;
  132. };
  133.  
  134.  
  135.  
  136. #endif // _SNDRENDER_H_INCLUDED
  137.