/*
 * Sound.h
 * By: Odis
 */
#ifndef INC_SOUND
#define INC_SOUND

//#define DX 1

/* for easy access to the table, not within the ifdef because of hard coded MAX_SOUND ref's */
typedef enum
{
    SONG1 = 0, WHOA_STRANGE, MAX_SOUND /*should always be last! */
} songs;

#ifdef DX
  #include <dsound.h>

  /* typedef! */
  typedef struct sound SOUND;
  
  extern HMMIO wave;
  extern bool stopped;
  extern int volume;
  extern int spause;
  

  extern LPDIRECTSOUND ds;

  /* resource crap */
  extern HGLOBAL songmem;
  extern HRSRC res;

  extern SOUND *first_sound;
  extern SOUND *last_sound;

  extern LPDIRECTSOUNDBUFFER song;
  extern int current_song;

  #define BUFFER_SIZE 46756 /* roughly 2.1 seconds or so */
  #define STREAM_TIMER 99

  /* sound effects */
  struct sounds
  {
     char *fname;
     char *name;
     DWORD bytes;
  };
  
  const struct sounds sound_table[MAX_SOUND+1];
  /****/
  
  /* playing sound list */
  struct sound
  {
    SOUND *next;
    SOUND *prev;
    
    int    index;
    LPDIRECTSOUNDBUFFER sound; /* thing this points to */
  };
  /***/

  LPDIRECTSOUNDBUFFER load_wave_from_file( LPSTR file, DWORD bytes, int index );
  LPDIRECTSOUNDBUFFER load_wave_from_resource( HGLOBAL mem, DWORD bytes, int index );
  LPDIRECTSOUNDBUFFER init_buffer( DWORD bytes, int index );
  bool   init_dx( int song );
  void   set_volume( LPDIRECTSOUNDBUFFER buf, LONG amount );
  void   stop_wave( LPDIRECTSOUNDBUFFER buf );
  void   play_wave( LPDIRECTSOUNDBUFFER buf, bool loop );
  void   play_sound( int s );
  void   delete_wave( LPDIRECTSOUNDBUFFER buf );
  void   handle_dx( bool restart );
  void   close_dx( void );
  void   evaluate_waves( void );
  int    get_sound( char *name );
  SOUND *get_sound_buf( LPDIRECTSOUNDBUFFER buf );
#endif
#endif