/*
	YIFF Sound Server

	Copyright (C) 1997-2003 WolfPack Entertainment
 */

#ifndef YIFF_H
#define YIFF_H

#include <sys/types.h>

#include "ytypes.h"
#include "ytiming.h"

#include "soundpaths.h"
#include "yconnection.h"
#include "ysound.h"
#include "playstack.h"

#include "afw.h"


/*
 *	Program name and version:
 */
#define PROG_NAME		"YIFF"
#define PROG_VERSION		"2.14.5"

#define PROG_VERSION_MAJOR	2
#define PROG_VERSION_MINOR	14
#define PROG_VERSION_RELEASE	5

#define PROG_VENDOR_NAME	"WolfPack Entertainment"

#define YPROTOCOL_VERSION_MAJOR	2
#define YPROTOCOL_VERSION_MINOR	14

/*
 *	Program help message:
 */
#ifdef HAVE_LIBKMID
#define PROG_HELP_MESG "\
Usage: yiff [config_file] [options]\n\
\n\
    [config_file] specifies the configuration file to be used.\n\
\n\
    [options] can be any of the following:\n\
\n\
        --device <device>       Specifies the digital audio device.\n\
        --mixer <device>        Specifies the mixer device.\n\
        --mixer_rc <file>       Specifies alternate mixer settings file.\n\
        --port <port>           Specifies the port number to accept\n\
                                incoming connections on.\n\
        --path <path>           Adds a sound path (can be used\n\
                                more than once).\n\
        --midi_port             MIDI device port (needed by ALSA and\n\
                                libkmid).\n\
        --foreground            Run in foreground, do not fork into background.\n\
        --help                  Prints (this) help screen and exits.\n\
        --version               Prints version information and exits.\n\
\n"
#else	/* HAVE_LIBKMID */
#define PROG_HELP_MESG "\
Usage: yiff [config_file] [options]\n\
\n\
    [config_file] specifies the configuration file to be used.\n\
\n\
    [options] can be any of the following:\n\
\n\
        --device <device>       Specifies the digital audio device.\n\
        --mixer <device>        Specifies the mixer device.\n\
        --mixer_rc <file>       Specifies alternate mixer settings file.\n\
        --port <port>           Specifies the port number to accept\n\
                                incoming connections on.\n\
        --path <path>           Adds a sound path (can be used\n\
                                more than once).\n\
        --foreground            Run in foreground, do not fork into background.\n\
        --help                  Prints (this) help screen and exits.\n\
        --version               Prints version information and exits.\n\
\n"
#endif


/*
 *	Copyright mesg:
 */
#define PROG_COPYRIGHT "\
Copyright (C) 1997-2005 WolfPack Entertainment.\n\
This program is protected by international copyright laws and treaties,\n\
distribution and/or modification of this software in violation of the\n\
GNU Public License is strictly prohibited. Violators will be prosicuted\n\
to the fullest extent of the law."


/*
 *	Listening Socket Backlog:
 */
#define LISTEN_SOCKET_BACKLOG   10

/*
 *	Network recieve buffer:
 *
 *	Should be big enough to hold a few large yiff network
 *	data segments.
 */
#define YNET_SEG_MAX	10000


/*
 *	Program statistics:
 */
typedef struct {

	/* PID of this program's process. */
	pid_t pid;

	/* When the program was started (in systime seconds). */
	time_t start_time;

	/*    Cycle load in microseconds. Calculated by taking the
         *    compensated cycle interval - the time it took to
         *    process stuff per loop / the compensated cycle interval.
	 */
	Coefficient cycle_load;

} yiff_stats_struct;
extern yiff_stats_struct ystats;


/*
 *	Program master run level:
 */
extern int runlevel;


/*
 *	Current time since midnight:
 */
extern YTime cur_time;



/*
 *	Next operation timers:
 *
 *	(In milliseconds unless noted otherwise.)
 */
typedef struct {

	YTime	refresh;

} yiff_next_struct;
extern yiff_next_struct next;


/*
 *	Sound device data pointer.
 */
extern Recorder *recorder;

/*
 *	Network incoming connections listening socket:
 */
extern int listen_socket;



/* In bufmix.c */
extern void YiffMixBuffers(
	Audio *audio,
        SoundBuffer *tar_buf, const SoundBuffer *src_buf,
        YDataLength len,
        Coefficient volume_left, Coefficient volume_right
);
extern void YiffShortenBuffer16(
        u_int16_t *buf,
        int buf_len,	/* In u_int8_t (not u_int16_t) units. */
        int buf_shoren_len
);
extern void YiffShortenBuffer8(
        u_int8_t *buf,
        int buf_len,	/* In u_int8_t units. */
        int buf_shoren_len
);


/* In main.c */
extern void YiffResetMixer(void);
extern void YiffHangupHandle(void);
extern void YiffSignalHandler(int sig);

extern int YiffInit(int argc, char **argv);
extern void YiffShutdown(void);

extern void YiffCloseConnection(YConnectionNumber con_num);
extern int YiffCheckNewConnection(int socket);
extern void YiffManageConnections(void);

extern int YiffReadNextDSP(
        PlayStack *ps_ptr,
        int bytes_per_cycle
);
extern int YiffCreatePlaystack(
	const char *path, 
        YConnectionNumber owner,
        YID yid,
        YDataPosition pos,
        YVolumeStruct *volume,
	int sample_rate,
        int repeats
);
extern void YiffDestroyPlaystack(int n);
extern void YiffManageSound(void);

extern void YiffUpdateTimers(void);
extern void YiffResetTimers(void);




#endif	/* YIFF_H */
