1 /* 2 * Copyright 2003-2004 Chris Morgan <cmorgan@alum.wpi.edu> 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Lesser General Public 6 * License as published by the Free Software Foundation; either 7 * version 2.1 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public 15 * License along with this library; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 */ 18 19 #ifndef _H_JACK_OUT_H 20 #define _H_JACK_OUT_H 21 22 #include <jack/jack.h> 23 24 #ifdef __cplusplus 25 extern "C" { 26 #else 27 #define bool long 28 #endif 29 30 #ifndef TRUE 31 #define TRUE 1 32 #endif 33 34 #ifndef FALSE 35 #define FALSE 0 36 #endif 37 38 #define ERR_SUCCESS 0 39 #define ERR_OPENING_JACK 1 40 #define ERR_RATE_MISMATCH 2 41 #define ERR_BYTES_PER_OUTPUT_FRAME_INVALID 3 42 #define ERR_BYTES_PER_INPUT_FRAME_INVALID 4 43 #define ERR_TOO_MANY_OUTPUT_CHANNELS 5 44 #define ERR_PORT_NAME_OUTPUT_CHANNEL_MISMATCH 6 45 #define ERR_PORT_NOT_FOUND 7 46 #define ERR_TOO_MANY_INPUT_CHANNELS 8 47 #define ERR_PORT_NAME_INPUT_CHANNEL_MISMATCH 9 48 49 enum status_enum { PLAYING, PAUSED, STOPPED, CLOSED, RESET }; 50 enum pos_enum { BYTES, MILLISECONDS }; 51 52 #define PLAYED 1 /* played out of the speakers(estimated value but should be close */ 53 #define WRITTEN_TO_JACK 2 /* amount written out to jack */ 54 #define WRITTEN 3 /* amount written to the bio2jack device */ 55 56 /**********************/ 57 /* External functions */ 58 void JACK_Init(void); /* call this before any other bio2jack calls */ 59 void JACK_DoSampleRateConversion(bool value); /* whether the next device that's Open()d should do 60 sample rate conversion if necessary */ 61 int JACK_Open(int *deviceID, unsigned int bits_per_sample, unsigned long *rate, int channels); /* Note: defaults to 0 input channels 62 if you need input (record) use OpenEx 63 instead */ 64 int JACK_OpenEx(int *deviceID, unsigned int bits_per_channel, 65 unsigned long *rate, 66 unsigned int input_channels, unsigned int output_channels, 67 const char **jack_port_name, unsigned int jack_port_name_count, 68 unsigned long jack_port_flags); 69 int JACK_Close(int deviceID); /* return 0 for success */ 70 void JACK_Reset(int deviceID); /* free all buffered data and reset several values in the device */ 71 long JACK_Write(int deviceID, unsigned char *data, unsigned long bytes); /* returns the number of bytes written */ 72 long JACK_Read(int deviceID, unsigned char *data, unsigned long bytes); /* returns the number of bytes read */ 73 74 /* state setting values */ 75 /* set/get the written/played/buffered value based on a byte or millisecond input value */ 76 long JACK_GetPosition(int deviceID, enum pos_enum position, int type); 77 void JACK_SetPosition(int deviceID, enum pos_enum position, long value); 78 79 long JACK_GetJackLatency(int deviceID); /* deprectated, you probably want JACK_GetJackOutputLatency */ 80 long JACK_GetJackOutputLatency(int deviceID); /* return the output latency in frames */ 81 long JACK_GetJackInputLatency(int deviceID); /* return the input latency in frames */ 82 83 int JACK_SetState(int deviceID, enum status_enum state); /* playing, paused, stopped */ 84 enum status_enum JACK_GetState(int deviceID); 85 86 long JACK_GetMaxOutputBufferedBytes(int deviceID); 87 long JACK_GetMaxInputBufferedBytes(int deviceID); 88 89 /* bytes that jack requests during each callback */ 90 unsigned long JACK_GetJackBufferedBytes(int deviceID); 91 92 /* Properties of the jack driver */ 93 94 /* linear means 0 volume is silence, 100 is full volume */ 95 /* dbAttenuation means 0 volume is 0dB attenuation */ 96 /* Bio2jack defaults to linear */ 97 /* Note: volume controls only effect output channels for now */ 98 enum JACK_VOLUME_TYPE { linear, dbAttenuation }; 99 enum JACK_VOLUME_TYPE JACK_SetVolumeEffectType(int deviceID, 100 enum JACK_VOLUME_TYPE type); 101 102 int JACK_SetAllVolume(int deviceID, unsigned int volume); /* returns 0 on success */ 103 int JACK_SetVolumeForChannel(int deviceID, unsigned int channel, unsigned int volume); 104 void JACK_GetVolumeForChannel(int deviceID, unsigned int channel, unsigned int *volume); 105 106 107 unsigned long JACK_GetOutputBytesPerSecond(int deviceID); /* bytes_per_output_frame * sample_rate */ 108 unsigned long JACK_GetInputBytesPerSecond(int deviceID); /* bytes_per_input_frame * sample_rate */ 109 unsigned long JACK_GetBytesStored(int deviceID); /* bytes currently buffered in the output buffer */ 110 unsigned long JACK_GetBytesFreeSpace(int deviceID); /* bytes of free space in the output buffer */ 111 unsigned long JACK_GetBytesUsedSpace(int deviceID); /* bytes of space used in the input buffer */ 112 unsigned long JACK_GetBytesPerOutputFrame(int deviceID); 113 unsigned long JACK_GetBytesPerInputFrame(int deviceID); 114 115 /* Note: these will probably be removed in a future release */ 116 int JACK_GetNumInputChannels(int deviceID); 117 int JACK_GetNumOutputChannels(int deviceID); 118 119 long JACK_GetSampleRate(int deviceID); /* samples per second */ 120 121 void JACK_SetClientName(char *name); /* sets the name that bio2jack will use when 122 creating a new jack client. name_%pid%_%deviceID%%counter% 123 will be used 124 NOTE: this defaults to name = bio2jack 125 NOTE: we limit the size of the client name to 126 jack_client_name_size() */ 127 128 enum JACK_PORT_CONNECTION_MODE 129 { 130 CONNECT_ALL, /* connect to all avaliable ports */ 131 CONNECT_OUTPUT, /* connect only to the ports we need for output */ 132 CONNECT_NONE /* don't connect to any ports */ 133 }; 134 135 /* set the mode for port connections */ 136 /* defaults to CONNECT_ALL */ 137 void JACK_SetPortConnectionMode(enum JACK_PORT_CONNECTION_MODE mode); 138 139 #ifdef __cplusplus 140 } 141 #endif 142 143 #endif /* #ifndef JACK_OUT_H */ 144