00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef AUDIO_H
00022 #define AUDIO_H
00023
00024 #include <stdint.h>
00025
00026 #define AUDIO_DEVICE_NAME_LENGTH 20
00027
00029 typedef struct ts_audio_device *p_audio_device;
00031 typedef struct ts_audio_api *p_audio_api;
00032
00034 typedef enum te_audio_segments {
00036 BUFFER_SEGMENT_1 = 0,
00038 BUFFER_SEGMENT_2,
00046 AUDIO_BUFFER_SEGMENTS
00047 } te_audio_segments;
00048
00050 typedef enum te_audio_channels {
00052 AUDIO_MONO = 0,
00054 AUDIO_STEREO
00055 } te_audio_channels;
00056
00057 typedef void (*message_handler)(char* message);
00058 typedef void (*audio_error_message_handler)(char* error_message);
00059
00061 typedef enum te_audio_rec_play {
00062 AUDIO_DEVICE_RECORD = 0,
00063 AUDIO_DEVICE_PLAY
00064 } te_audio_rec_play;
00065
00067 typedef struct ts_audio_pub {
00069 te_audio_rec_play play_record;
00071 char name[AUDIO_DEVICE_NAME_LENGTH];
00073 int32_t samplesize;
00075 int32_t sample_frequency;
00077 int32_t format;
00079 int32_t handle;
00082 te_audio_segments buffer_segments;
00084 int32_t audio_buffer_size;
00085 int32_t fragsize;
00087 uint8_t *audio_buffer_raw;
00089 te_audio_channels dsp_channels;
00090 int32_t samples;
00092 audio_error_message_handler error_msg_handler;
00093 } ts_audio_pub, *p_audio_pub;
00094
00096 typedef struct ts_audio_api {
00097 char* audio_device_type_name;
00098 int32_t (*open)(p_audio_pub device);
00099 int32_t (*init)(p_audio_pub device);
00100 int32_t (*close)(p_audio_pub device);
00101 void (*play)(p_audio_pub device, te_audio_segments buffer_segment);
00102 void (*record)(p_audio_pub device, te_audio_segments buffer_segment);
00103 } ts_audio_api;
00104
00106 #define AUDIO_DEVICE_TEMINATOR {0, NULL, NULL, NULL, NULL, NULL}
00107
00113 p_audio_device audio_create(uint32_t device_type,
00114 te_audio_rec_play rec_play
00115 );
00116
00123 int32_t audio_open(p_audio_device device, int32_t sample_frequency);
00124
00130 int32_t audio_close(p_audio_device device);
00131
00137 int32_t audio_init(p_audio_device device);
00138
00144 int32_t audio_destroy(p_audio_device *device);
00145
00150 void audio_capture(p_audio_device device, te_audio_segments buffer_segment);
00151
00156 void audio_capture_wait(p_audio_device device, te_audio_segments buffer_segment);
00157
00162 void audio_play(p_audio_device device, te_audio_segments buffer_segment);
00163
00170 void audio_raw2double(p_audio_device device, te_audio_segments buffer_segment, double *audio_data);
00171
00179 void audio_double2raw(p_audio_device device, te_audio_segments buffer_segment, double *audio_data);
00180
00182 void register_error_message_handler(message_handler handler);
00183
00188 uint32_t audio_device_samples_get(p_audio_device device);
00189
00193 int32_t audio_supported_device_types_get(void);
00194
00199 char* audio_device_type_name_get(int32_t audio_device_type_id);
00200
00206 void audio_device_name_set(p_audio_device device, const char *name);
00207
00212 void audio_device_name_get(p_audio_device device, char **name);
00213
00218 void audio_sample_rate_set(p_audio_device device, int32_t Hertz);
00219
00223 int32_t audio_sample_rate_get(p_audio_device device);
00224
00225 #endif