Subversion Repositories pentevo

Rev

Rev 796 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed | ?url?

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