/**********************************************************************
audio i/o streams (.au format)

$Id: austream.h,v 1.6 2003/01/19 23:17:09 purnhage Exp $

Header file: austream.h

(c) Heiko Purnhagen 1998-2003
e-mail: purnhage@tnt.uni-hannover.de
WWW:    http://www.tnt.uni-hannover.de/~purnhage/

This module is available under the terms of the GNU Lesser General
Public License. See file COPYING-LGPL for further details. All usual
disclaimers apply!

Authors:
HP    Heiko Purnhagen, Uni Hannover <purnhage@tnt.uni-hannover.de>
NM    Nikolaus Meine, Uni Hannover <meine@tnt.uni-hannover.de>

Changes:
16-sep-98   HP/NM   born, based on au_io.c
06-jun-00   HP      added non-blocking i/o: AuOpenReadNB(), AuOpenWriteNB()
20-Aug-2001 HP      added 16 bit raw i/o (big/little endian, skip header)
05-Nov-2001 HP      openNB returns file descriptor
                    read/writeNB return actual numSample count
**********************************************************************/

/* Audio i/o streaming with stdin/stdout support. */
/* Header format: .au (Sun audio file format, aka SND or AFsp) */
/*                or no/skip header for big/little endian 16 bit raw  */
/* Sample format: 16 bit twos complement, uniform quantisation */
/* Data size set to -1 (=unknown) */

/* Multi channel data is interleaved: l0 r0 l1 r1 ... */
/* Total number of samples (over all channels) is used. */


#ifndef _austream_h_
#define _austream_h_


/* ---------- declarations ---------- */

typedef struct AuStreamStruct AuStream;	/* audio stream handle */


/* ---------- functions ---------- */

#ifdef __cplusplus
extern "C" {
#endif


/* AuInit() */
/* Init audio i/o streams. */

void AuInit (
  int debugLevel);		/* in: debug level */
				/*     0=off  1=basic  2=full */


/* AuOpenRead() */
/* Open audio stream for reading. */

AuStream *AuOpenRead (
  char *streamName,		/* in: stream name, "-" for stdin */
  int *numChannel,		/* out: number of channels */
  float *fSample,		/* out: sampling frequency [Hz] */
  long *numSample);		/* out: number of samples in stream */
				/*      or -1 if not available */
				/* returns: */
				/*  audio stream (handle) */
				/*  or NULL if error */


/* AuOpenWrite() */
/* Open audio stream for writing. */

AuStream *AuOpenWrite (
  char *streamName,		/* in: stream name, "-" for stdout */
  int numChannel,		/* in: number of channels */
  float fSample);		/* in: sampling frequency [Hz] */
				/* returns: */
				/*  audio stream (handle) */
				/*  or NULL if error */


/* AuOpenReadNB() */
/* Open audio stream for reading, non-blocking mode possible. */

AuStream *AuOpenReadNB (
  char *streamName,		/* in: stream name, "-" for stdin */
  int nonBlocking,		/* in: 1 for non-blocking mode */
  int rawFormat,		/* in: 0=au 1,2=raw (1=big, 2=little endian) */
  int skipHeader,		/* in: num header bytes to skip if raw */
  int *numChannel,		/* out: number of channels */
				/*      or -1 if raw */
  float *fSample,		/* out: sampling frequency [Hz] */
				/*      or -1 if raw */
  long *numSample,		/* out: number of samples in stream */
				/*      or -1 if not available */
  int *fd);			/* out: file descriptor if nonBlocking */
				/*      or -1 otherwise (may be NULL) */
				/* returns: */
				/*  audio stream (handle) */
				/*  or NULL if error */


/* AuOpenWriteNB() */
/* Open audio stream for writing, non-blocking mode possible. */

AuStream *AuOpenWriteNB (
  char *streamName,		/* in: stream name, "-" for stdout */
  int nonBlocking,		/* in: 1 for non-blocking mode */
  int rawFormat,		/* in: 0=au 1,2=raw (1=big, 2=little endian) */
  int numChannel,		/* in: number of channels */
  float fSample,		/* in: sampling frequency [Hz] */
  int *fd);			/* out: file descriptor if nonBlocking */
				/*      or -1 otherwise (may be NULL) */
				/* returns: */
				/*  audio stream (handle) */
				/*  or NULL if error */


/* AuReadData() */
/* Read data from audio stream. */
/* if non-blocking: fill with 0 if samples can not be read */
/*                  returns number of samples actually transfered */

long AuReadData (
  AuStream *stream,		/* in: audio stream (handle) */
  short *data,			/* out: data[] */
  long numSample);		/* in: number of samples to be read */
				/* returns: */
				/*  number of samples read */


/* AuWriteData() */
/* Write data to audio stream. */
/* if non-blocking: discard samples that could not be written */
/*                  returns number of samples actually transfered */

long AuWriteData (
  AuStream *stream,		/* in: audio stream (handle) */
  short *data,			/* in: data[] */
  long numSample);		/* in: number of samples to be written */
				/* returns: */
				/*  number of samples written */


/* AuClose() */
/* Close audio stream.*/

void AuClose (
  AuStream *stream);		/* in: audio stream (handle) */


#ifdef __cplusplus
}
#endif

#endif	/* #ifndef _austream_h_ */

/* end of austream.h */

