#ifndef R_S_ALSA
#define R_S_ALSA

#define nCHN 12
// Channels, muss bei Ice1712 capture 12 sein!

#define snd_HZ 22050 /* z.B. 22050 */ 
/* Ice1712pro/Linux kann nur S32_LE, aber 8-48kHz Samplingrate... */

#define fmtSOCK signed short int
// Datenformat fuer die Uebertragung per Socket
#define snd_inBITS 16
/* *** Achtung, zur Zeit werden nur 16 Bit signed verwendet!!! *** */

/* ***************************************************************** */

#include <sys/asoundlib.h>
#include <linux/asound.h>
#include <stdio.h>
#include <string.h> // strncpy
#include <sys/types.h>
#include <errno.h> // ...
#include <fcntl.h> // open
#include <sys/stat.h> // stat
#include <stdlib.h> // malloc
#include <unistd.h> // usleep
#include <sys/uio.h> // iovec

#include <netinet/in.h> 
#include <sys/socket.h>
#include <sys/wait.h>
#include <pthread.h>

#define BACKLOG 24     /* how many pending connections queue will hold */

/* ***************************************************************** */

// #define DEBUG
#define USLEEP
#define RBUF 4096 /* ReadBufferSize in Samples */

#define snd_SHL (31-snd_inBITS) /* 24 MSB of 32 used bei ice1712 */
// Ich habe ein MSB weggelassen (absichtlich)
// 386: __BYTE_ORDER == __LITTLE_ENDIAN

// ice1712pro kann nur genau 10 voices playback und 12 voices capture
// ausserdem geht im stream mode nur write/interleaved richtig!?

// Werte < 0 bzw. != 0 signalisieren Fehler.

pthread_mutex_t mutex;
#define LOCK (void)pthread_mutex_lock(&mutex)
#define UNLOCK (void)pthread_mutex_unlock(&mutex)
// evtl. Errorhandling

int run_server;
int in_buffer;

int open_sound(snd_pcm_t ** handle /* ptr auf ptr */);
int close_sound(snd_pcm_t * handle);

int open_socket(int port); /* liefert handle als return value */
int close_socket(int handle);

int send_buffer(int sockfd, int channel);
// verbindet beide Welten!

#endif
