spu: try to improve timing
[pcsx_rearmed.git] / plugins / dfsound / externals.h
index de4b5db..f3fbc67 100644 (file)
  *                                                                         *\r
  ***************************************************************************/\r
 \r
+#ifndef __P_SOUND_EXTERNALS_H__\r
+#define __P_SOUND_EXTERNALS_H__\r
+\r
 #include <stdint.h>\r
 \r
 /////////////////////////////////////////////////////////\r
 // generic defines\r
 /////////////////////////////////////////////////////////\r
 \r
+//#define log_unhandled printf\r
+#define log_unhandled(...)\r
+\r
 #ifdef __GNUC__\r
 #define noinline __attribute__((noinline))\r
 #define unlikely(x) __builtin_expect((x), 0)\r
@@ -111,8 +117,15 @@ typedef struct
  unsigned int      bFMod:2;                            // freq mod (0=off, 1=sound channel, 2=freq channel)\r
  unsigned int      prevflags:3;                        // flags from previous block\r
  unsigned int      bIgnoreLoop:1;                      // Ignore loop\r
- int               iLeftVolume;                        // left volume\r
- int               iRightVolume;                       // right volume\r
+ unsigned int      bNewPitch:1;                        // pitch changed\r
+ unsigned int      bStarting:1;                        // starting after keyon\r
+ union {\r
+  struct {\r
+   int             iLeftVolume;                        // left volume\r
+   int             iRightVolume;                       // right volume\r
+  };\r
+  int              iVolume[2];\r
+ };\r
  ADSRInfoEx        ADSRX;\r
  int               iRawPitch;                          // raw pitch (0...3fff)\r
 } SPUCHAN;\r
@@ -185,6 +198,7 @@ typedef struct
  unsigned char * pSpuIrq;\r
 \r
  unsigned int    cycles_played;\r
+ unsigned int    cycles_dma_end;\r
  int             decode_pos;\r
  int             decode_dirty_ch;\r
  unsigned int    bSpuInit:1;\r
@@ -194,14 +208,14 @@ typedef struct
  unsigned int    dwNoiseVal;           // global noise generator\r
  unsigned int    dwNoiseCount;\r
  unsigned int    dwNewChannel;         // flags for faster testing, if new channel starts\r
- unsigned int    dwChannelOn;          // not silent channels\r
+ unsigned int    dwChannelsAudible;    // not silent channels\r
  unsigned int    dwChannelDead;        // silent+not useful channels\r
 \r
  unsigned char * pSpuBuffer;\r
  short         * pS;\r
 \r
  void (CALLBACK *irqCallback)(void);   // func of main emu, called on spu irq\r
- void (CALLBACK *cddavCallback)(unsigned short,unsigned short);\r
+ void (CALLBACK *cddavCallback)(short, short);\r
  void (CALLBACK *scheduleCallback)(unsigned int);\r
 \r
  xa_decode_t   * xapGlobal;\r
@@ -228,11 +242,12 @@ typedef struct
  int           * SB;\r
  int           * SSumLR;\r
 \r
- int             pad[29];\r
  unsigned short  regArea[0x400];\r
 } SPUInfo;\r
 \r
-#define regAreaGet(ch,offset) \\r
+#define regAreaGet(offset) \\r
+  spu.regArea[((offset) - 0xc00)>>1]\r
+#define regAreaGetCh(ch, offset) \\r
   spu.regArea[((ch<<4)|(offset))>>1]\r
 \r
 ///////////////////////////////////////////////////////////\r
@@ -245,12 +260,14 @@ extern SPUInfo spu;
 \r
 void do_samples(unsigned int cycles_to, int do_sync);\r
 void schedule_next_irq(void);\r
+void check_irq_io(unsigned int addr);\r
 \r
-#define do_samples_if_needed(c, sync) \\r
+#define do_samples_if_needed(c, sync, samples) \\r
  do { \\r
-  if (sync || (int)((c) - spu.cycles_played) >= 16 * 768) \\r
+  if (sync || (int)((c) - spu.cycles_played) >= (samples) * 768) \\r
    do_samples(c, sync); \\r
  } while (0)\r
 \r
 #endif\r
 \r
+#endif /* __P_SOUND_EXTERNALS_H__ */\r