#ifndef _OTI_AUDIO_DEVICE_H
#define	_OTI_AUDIO_DEVICE_H

#ifdef __cplusplus
extern "C" {
#endif

/*  
 * The routines defined in this file replace the standard 
 * "Audio Device" routines as defined by audio_device.h in
 * libaudio. For the Osprey-1x00 product line, these calls
 * must be used. Internally, if the file descriptor does not
 * refer to an Osprey Device, the standard libaudio call will
 * be made. Otherwise, the call will be handled in an Osprey
 * specific way. Refer to the Osprey-1x00 documentation for
 * further information.
 */
  

/*
 * The following macros read the current audio device configuration
 * and convert the data encoding format into an Audio_hdr.
 * 'F' is an open audio file descriptor.
 * 'H' is a pointer to an Audio_hdr.
 * The structure '*H' is updated after the device state has been read.
 */
#define	oti_audio_get_play_config(F, H)					\
		oti_audio__setplayhdr((F), (H), AUDIO__PLAY)
#define	oti_audio_get_record_config(F, H)					\
		oti_audio__setplayhdr((F), (H), AUDIO__RECORD)

/*
 * The following macros attempt to reconfigure the audio device so that
 * it operates on data encoded according to a given Audio_hdr.
 * 'F' is an open audio file descriptor.
 * 'H' is a pointer to an Audio_hdr describing the desired encoding.
 * The structure '*H' is updated after the device state has been read
 * to reflect the actual state of the device.
 *
 * AUDIO_SUCCESS is returned if the device configuration matches the
 * requested encoding.  AUDIO_ERR_NOEFFECT is returned if it does not.
 */
#define	oti_audio_set_play_config(F, H)					\
		oti_audio__setplayhdr((F), (H), AUDIO__SET|AUDIO__PLAY)
#define	oti_audio_set_record_config(F, H)					\
		oti_audio__setplayhdr((F), (H), AUDIO__SET|AUDIO__RECORD)


/*
 * The following macros pause or resume the audio play and/or record channels.
 * Note that requests to pause a channel that is not open will have no effect.
 * In such cases, AUDIO_ERR_NOEFFECT is returned.
 */
#define	oti_audio_pause(F)							\
		oti_audio__setpause((F), AUDIO__PLAYREC|AUDIO__PAUSE)
#define	oti_audio_pause_play(F)						\
		oti_audio__setpause((F), AUDIO__PLAY|AUDIO__PAUSE)
#define	oti_audio_pause_record(F)						\
		oti_audio__setpause((F), AUDIO__RECORD|AUDIO__PAUSE)

#define	oti_audio_resume(F)							\
		oti_audio__setpause((F), AUDIO__PLAYREC|AUDIO__RESUME)
#define	oti_audio_resume_play(F)						\
		oti_audio__setpause((F), AUDIO__PLAY|AUDIO__RESUME)
#define	oti_audio_resume_record(F)						\
		oti_audio__setpause((F), AUDIO__RECORD|AUDIO__RESUME)


/*
 * The following macros get individual state values.
 * 'F' is an open audio file descriptor.
 * 'V' is a pointer to an unsigned int.
 * The value '*V' is updated after the device state has been read.
 */
#define	oti_audio_get_play_port(F, V)					\
		oti_audio__setval((F), (V), AUDIO__PLAY|AUDIO__PORT)
#define	oti_audio_get_record_port(F, V)					\
		oti_audio__setval((F), (V), AUDIO__RECORD|AUDIO__PORT)
#define	oti_audio_get_play_balance(F, V)					\
		oti_audio__setval((F), (V), AUDIO__PLAY|AUDIO__BALANCE)
#define	oti_audio_get_record_balance(F, V)					\
		oti_audio__setval((F), (V), AUDIO__RECORD|AUDIO__BALANCE)
#define	oti_audio_get_play_samples(F, V)					\
		oti_audio__setval((F), (V), AUDIO__PLAY|AUDIO__SAMPLES)
#define	oti_audio_get_record_samples(F, V)					\
		oti_audio__setval((F), (V), AUDIO__RECORD|AUDIO__SAMPLES)
#define	oti_audio_get_play_error(F, V)					\
		oti_audio__setval((F), (V), AUDIO__PLAY|AUDIO__ERROR)
#define	oti_audio_get_record_error(F, V)					\
		oti_audio__setval((F), (V), AUDIO__RECORD|AUDIO__ERROR)
#define	oti_audio_get_play_eof(F, V)					\
		oti_audio__setval((F), (V), AUDIO__PLAY|AUDIO__EOF)

#define	oti_audio_get_play_open(F, V)					\
		oti_audio__setval((F), (V), AUDIO__PLAY|AUDIO__OPEN)
#define	oti_audio_get_record_open(F, V)					\
		oti_audio__setval((F), (V), AUDIO__RECORD|AUDIO__OPEN)
#define	oti_audio_get_play_active(F, V)					\
		oti_audio__setval((F), (V), AUDIO__PLAY|AUDIO__ACTIVE)
#define	oti_audio_get_record_active(F, V)					\
		oti_audio__setval((F), (V), AUDIO__RECORD|AUDIO__ACTIVE)
#define	oti_audio_get_play_waiting(F, V)					\
		oti_audio__setval((F), (V), AUDIO__PLAY|AUDIO__WAITING)
#define	oti_audio_get_record_waiting(F, V)					\
		oti_audio__setval((F), (V), AUDIO__RECORD|AUDIO__WAITING)

/*
 * The following macros set individual state values.
 * 'F' is an open audio file descriptor.
 * 'V' is a pointer to an unsigned int.
 * The value '*V' is updated after the device state has been read.
 */
#define	oti_audio_set_play_port(F, V)					\
		oti_audio__setval((F), (V), AUDIO__SET|AUDIO__PLAY|AUDIO__PORT)
#define	oti_audio_set_record_port(F, V)					\
		oti_audio__setval((F), (V), AUDIO__SET|AUDIO__RECORD|AUDIO__PORT)

/*
 * The value returned for these is the value *before* the state was changed.
 * This allows you to atomically read and reset their values.
 */
#define	oti_audio_set_play_balance(F, V)					\
		oti_audio__setval((F), (V), AUDIO__SET|AUDIO__PLAY|AUDIO__BALANCE)
#define	oti_audio_set_record_balance(F, V)					\
		oti_audio__setval((F), (V), AUDIO__SET|AUDIO__RECORD|AUDIO__BALANCE)
#define	oti_audio_set_play_samples(F, V)					\
		oti_audio__setval((F), (V), AUDIO__SET|AUDIO__PLAY|AUDIO__SAMPLES)
#define	oti_audio_set_record_samples(F, V)					\
		oti_audio__setval((F), (V), AUDIO__SET|AUDIO__RECORD|AUDIO__SAMPLES)
#define	oti_audio_set_play_error(F, V)					\
		oti_audio__setval((F), (V), AUDIO__SET|AUDIO__PLAY|AUDIO__ERROR)
#define	oti_audio_set_record_error(F, V)					\
		oti_audio__setval((F), (V), AUDIO__SET|AUDIO__RECORD|AUDIO__ERROR)
#define	oti_audio_set_play_eof(F, V)					\
		oti_audio__setval((F), (V), AUDIO__SET|AUDIO__PLAY|AUDIO__EOF)

/* The value can only be set to one.  It is reset to zero on close(). */
#define	oti_audio_set_play_waiting(F, V)					\
		oti_audio__setval((F), (V), AUDIO__SET|AUDIO__PLAY|AUDIO__WAITING)
#define	oti_audio_set_record_waiting(F, V)					\
		oti_audio__setval((F), (V), AUDIO__SET|AUDIO__RECORD|AUDIO__WAITING)

/*
 * Gain routines take double values, mapping the valid range of gains
 * to a floating-point value between zero and one, inclusive.
 * The value returned will likely be slightly different than the value set.
 * This is because the value is quantized by the device.
 *
 * Make sure that 'V' is a (double *)!
 */
#define	oti_audio_get_play_gain(F, V)					\
		oti_audio__setgain((F), (V), AUDIO__PLAY|AUDIO__GAIN)
#define	oti_audio_get_record_gain(F, V)					\
		oti_audio__setgain((F), (V), AUDIO__RECORD|AUDIO__GAIN)
#define	oti_audio_get_monitor_gain(F, V)					\
		oti_audio__setgain((F), (V), AUDIO__MONGAIN)

#define	oti_audio_set_play_gain(F, V)					\
		oti_audio__setgain((F), (V), AUDIO__SET|AUDIO__PLAY|AUDIO__GAIN)
#define	oti_audio_set_record_gain(F, V)					\
		oti_audio__setgain((F), (V), AUDIO__SET|AUDIO__RECORD|AUDIO__GAIN)
#define	oti_audio_set_monitor_gain(F, V)					\
		oti_audio__setgain((F), (V), AUDIO__SET|AUDIO__MONGAIN)

/*
 * The following macros flush the audio play and/or record queues.
 * Note that requests to flush a channel that is not open will have no effect.
 */
#define	oti_audio_flush(F)							\
		oti_audio__flush((F), AUDIO__PLAYREC)
#define	oti_audio_flush_play(F)						\
		oti_audio__flush((F), AUDIO__PLAY)
#define	oti_audio_flush_record(F)						\
		oti_audio__flush((F), AUDIO__RECORD)

#ifdef __cplusplus
}
#endif

#endif

