Subversion Repositories pentevo

Rev

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

  1. #ifndef __SNDCOUNTER_H_INCLUDED
  2. #define __SNDCOUNTER_H_INCLUDED
  3.  
  4. #include "sndrender.h"
  5.  
  6. #ifdef SND_EXTERNAL_BUFFER
  7.  
  8. // to get available samples in external buffer, common for all SNDRENDERs,
  9. // call begin(), count() for each SNDRENDER (SNDCHIP) object,
  10. // and end() to get data position and size
  11.  
  12. class SNDCOUNTER
  13. {
  14.  public:
  15.    void reset();
  16.    SNDCOUNTER() { reset(); } // ctor
  17.  
  18.    void begin();
  19.    void count(SNDRENDER &render);
  20.    void end(bufptr_t &start_offset, unsigned &n_samples);
  21.  
  22.  private:
  23.    bufptr_t bufstart;
  24.    unsigned n_samples;
  25. };
  26.  
  27. #endif // SND_EXTERNAL_BUFFER
  28. #endif //__SNDCOUNTER_H_INCLUDED
  29.  
  30.  
  31. #if 0 // USAGE EXAMPLE
  32.  
  33.   #define USE_SND_EXTERNAL_BUFFER
  34.   #include "sndrender/*.h"
  35.   #include "sndrender/*.cpp"
  36.  
  37.   SNDCHIP ay1, ay2;
  38.   SNDRENDER beeper;
  39.   SNDCOUNTER cnt;
  40.  
  41.   // global emulation loop
  42.   for (;;) {
  43.      ay1.start_frame();
  44.      ay2.start_frame();
  45.      beeper.start_frame();
  46.  
  47.      // Z80 emulation before INT
  48.      for (int t = 0; t < 71680; t++) {
  49.         ay1.select(0);
  50.         ay1.write(t, t % 100);
  51.         ay2.select(3);
  52.         ay2.write(t, t % 100);
  53.         beeper.update(t, t % 4000, t % 400);
  54.      }
  55.      ay1.end_frame(t);
  56.      ay2.end_frame(t);
  57.      beeper.end_frame(t);
  58.  
  59.      cnt.begin();
  60.      cnt.count(ay1);
  61.      cnt.count(ay2);
  62.      cnt.count(beeper);
  63.      unsigned bufplay, n_samples;
  64.      cnt.end(bufplay, n_samples);
  65.  
  66.      unsigned sndplaybuf[10000];
  67.      for (unsigned k = 0; k < n_samples; k++, bufplay++) {
  68.         sndplaybuf[k] = sndbuf[bufplay & (SNDBUFSIZE-1)];
  69.         sndbuf[bufplay & (SNDBUFSIZE-1)] = 0;
  70.      }
  71.      spbsize = n_samples*4;
  72.      wav_play((SNDSAMPLE*)sndplaybuf, n_samples);
  73.   }
  74.  
  75. #endif
  76.