Update of /cvsroot/playerstage/code/player/client_libs/libplayerc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14471/client_libs/libplayerc Modified Files: Makefile.am dev_graphics2d.c dev_graphics3d.c dev_ir.c dev_wsn.c playerc.h Added Files: dev_audio.c Log Message: major overhaul of audio interface and associated proxies minor fixes to other c client proxies and tests to remove build warnings Index: dev_graphics3d.c =================================================================== RCS file: /cvsroot/playerstage/code/player/client_libs/libplayerc/dev_graphics3d.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** dev_graphics3d.c 1 May 2006 09:09:18 -0000 1.1 --- dev_graphics3d.c 8 May 2006 12:39:05 -0000 1.2 *************** *** 79,82 **** --- 79,83 ---- { device->color = col; + return 0; } --- NEW FILE: dev_audio.c --- /* * libplayerc : a Player client library * Copyright (C) Andrew Howard 2002-2003 * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ /* * Player - One Hell of a Robot Server * Copyright (C) Andrew Howard 2003 * * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <string.h> #include <stdlib.h> #include "playerc.h" #include "error.h" // Local declarations void playerc_audio_putmsg(playerc_audio_t *device, player_msghdr_t *header, uint8_t *data, size_t len); // Create an audio proxy playerc_audio_t *playerc_audio_create(playerc_client_t *client, int index) { playerc_audio_t *device; device = malloc(sizeof(playerc_audio_t)); memset(device, 0, sizeof(playerc_audio_t)); playerc_device_init(&device->info, client, PLAYER_AUDIO_CODE, index, (playerc_putmsg_fn_t) playerc_audio_putmsg); return device; } // Destroy an audio proxy void playerc_audio_destroy(playerc_audio_t *device) { playerc_device_term(&device->info); free(device); } // Subscribe to the audio device int playerc_audio_subscribe(playerc_audio_t *device, int access) { return playerc_device_subscribe(&device->info, access); } // Un-subscribe from the audio device int playerc_audio_unsubscribe(playerc_audio_t *device) { return playerc_device_unsubscribe(&device->info); } void playerc_audio_putmsg(playerc_audio_t *device, player_msghdr_t *header, uint8_t *data, size_t len) { if((header->type == PLAYER_MSGTYPE_DATA) && (header->subtype == PLAYER_AUDIO_WAV_REC_DATA)) { assert(header->size > 0); player_audio_wav_t * wdata = (player_audio_wav_t *) data; device->wav_data.data_count = wdata->data_count; memcpy(device->wav_data.data, wdata->data, wdata->data_count * sizeof(device->wav_data.data[0])); device->wav_data.format = wdata->format; } else if((header->type == PLAYER_MSGTYPE_DATA) && (header->subtype == PLAYER_AUDIO_SEQ_DATA)) { assert(header->size > 0); player_audio_seq_t * sdata = (player_audio_seq_t *) data; device->seq_data.tones_count = sdata->tones_count; memcpy(device->seq_data.tones, sdata->tones, sdata->tones_count * sizeof(device->seq_data.tones[0])); } else if((header->type == PLAYER_MSGTYPE_DATA) && (header->subtype == PLAYER_AUDIO_MIXER_CHANNEL_DATA)) { assert(header->size > 0); player_audio_mixer_channel_list_t * wdata = (player_audio_mixer_channel_list_t *) data; device->mixer_data.channels_count = wdata->channels_count; memcpy(device->mixer_data.channels, wdata->channels, wdata->channels_count * sizeof(device->mixer_data.channels[0])); } else PLAYERC_WARN2("skipping audio message with unknown type/subtype: %d/%d\n", header->type, header->subtype); } /** @brief Command to play an audio block */ int playerc_audio_wav_play_cmd(playerc_audio_t *device, player_audio_wav_t * data) { return playerc_client_write(device->info.client, &device->info, PLAYER_AUDIO_WAV_PLAY_CMD, data, NULL); } /** @brief Command to set recording state */ int playerc_audio_wav_stream_rec_cmd(playerc_audio_t *device, uint8_t state) { player_bool_t cmd; cmd.state = state; return playerc_client_write(device->info.client, &device->info, PLAYER_AUDIO_WAV_STREAM_REC_CMD, &cmd, NULL); } /** @brief Command to play prestored sample */ int playerc_audio_sample_play_cmd(playerc_audio_t *device, int index) { player_audio_sample_item_t cmd; cmd.index = index; return playerc_client_write(device->info.client, &device->info, PLAYER_AUDIO_SAMPLE_PLAY_CMD, &cmd, NULL); } /** @brief Command to play sequence of tones */ int playerc_audio_seq_play_cmd(playerc_audio_t *device, player_audio_seq_t * tones) { return playerc_client_write(device->info.client, &device->info, PLAYER_AUDIO_SEQ_PLAY_CMD, tones, NULL); } /** @brief Command to set mixer levels */ int playerc_audio_mixer_channel_cmd(playerc_audio_t *device, player_audio_mixer_channel_list_t * levels) { return playerc_client_write(device->info.client, &device->info, PLAYER_AUDIO_MIXER_CHANNEL_CMD, levels, NULL); } /** @brief Request to record a single audio block Value is returned into wav_data, block length is determined by device */ int playerc_audio_wav_rec(playerc_audio_t *device) { int result = 0; if((result = playerc_client_request(device->info.client, &device->info, PLAYER_AUDIO_WAV_REC_REQ, NULL, (void*)&device->wav_data, sizeof(device->wav_data))) < 0) return result; return 0; } /** @brief Request to load an audio sample */ int playerc_audio_sample_load(playerc_audio_t *device, int index, player_audio_wav_t * data) { int result = 0; player_audio_sample_t req; req.sample.data_count = data->data_count; memcpy(req.sample.data, data->data, req.sample.data_count * sizeof(req.sample.data[0])); req.sample.format = data->format; req.index = index; if((result = playerc_client_request(device->info.client, &device->info, PLAYER_AUDIO_SAMPLE_LOAD_REQ, &req, NULL, 0)) < 0) return result; return 0; } /** @brief Request to retrieve an audio sample Data is stored in wav_data */ int playerc_audio_sample_retrieve(playerc_audio_t *device, int index) { int result = 0; player_audio_sample_t req; req.sample.data_count = 0; req.index = index; if((result = playerc_client_request(device->info.client, &device->info, PLAYER_AUDIO_SAMPLE_RETRIEVE_REQ, &req, &req, sizeof(req))) < 0) return result; device->wav_data.data_count = req.sample.data_count; memcpy(device->wav_data.data, req.sample.data, req.sample.data_count * sizeof(device->wav_data.data[0])); device->wav_data.format = req.sample.format; return 0; } /** @brief Request to record new sample */ int playerc_audio_sample_rec(playerc_audio_t *device, int index) { int result = 0; player_audio_sample_item_t req; req.index = index; if((result = playerc_client_request(device->info.client, &device->info, PLAYER_AUDIO_SAMPLE_REC_REQ, &req, NULL, 0)) < 0) return result; return 0; } /** @brief Request mixer channel data result is stored in mixer_data*/ int playerc_audio_get_mixer_levels(playerc_audio_t *device) { int result = 0; player_audio_mixer_channel_list_t req; if((result = playerc_client_request(device->info.client, &device->info, PLAYER_AUDIO_MIXER_CHANNEL_LIST_REQ , NULL, &req, sizeof(req))) < 0) return result; device->mixer_data.channels_count = req.channels_count; memcpy(device->mixer_data.channels, req.channels, req.channels_count * sizeof(device->mixer_data.channels[0])); return 0; } /** @brief Request mixer channel details list result is stored in channel_details_list*/ int playerc_audio_get_mixer_details(playerc_audio_t *device) { int result; player_audio_mixer_channel_list_detail_t req; if((result = playerc_client_request(device->info.client, &device->info, PLAYER_AUDIO_MIXER_CHANNEL_LIST_REQ , NULL, &req, sizeof(req))) < 0) return result; device->channel_details_list.details_count = req.details_count; memcpy(device->channel_details_list.details, req.details, req.details_count * sizeof(device->channel_details_list.details[0])); device->channel_details_list.default_output = req.default_output; device->channel_details_list.default_input = req.default_input; return 0; } Index: dev_wsn.c =================================================================== RCS file: /cvsroot/playerstage/code/player/client_libs/libplayerc/dev_wsn.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** dev_wsn.c 11 Apr 2006 15:40:31 -0000 1.1 --- dev_wsn.c 8 May 2006 12:39:05 -0000 1.2 *************** *** 78,82 **** void *data) { ! int i, j; if((header->type == PLAYER_MSGTYPE_DATA) && --- 78,82 ---- void *data) { ! // int i, j; if((header->type == PLAYER_MSGTYPE_DATA) && Index: Makefile.am =================================================================== RCS file: /cvsroot/playerstage/code/player/client_libs/libplayerc/Makefile.am,v retrieving revision 1.89 retrieving revision 1.90 diff -C2 -d -r1.89 -r1.90 *** Makefile.am 1 May 2006 09:09:18 -0000 1.89 --- Makefile.am 8 May 2006 12:39:03 -0000 1.90 *************** *** 26,29 **** --- 26,30 ---- dev_actarray.c \ dev_aio.c \ + dev_audio.c \ dev_bumper.c \ dev_blobfinder.c \ Index: dev_graphics2d.c =================================================================== RCS file: /cvsroot/playerstage/code/player/client_libs/libplayerc/dev_graphics2d.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** dev_graphics2d.c 17 Apr 2006 04:11:01 -0000 1.7 --- dev_graphics2d.c 8 May 2006 12:39:05 -0000 1.8 *************** *** 79,82 **** --- 79,83 ---- { device->color = col; + return 0; } Index: playerc.h =================================================================== RCS file: /cvsroot/playerstage/code/player/client_libs/libplayerc/playerc.h,v retrieving revision 1.193 retrieving revision 1.194 diff -C2 -d -r1.193 -r1.194 *** playerc.h 6 May 2006 23:08:58 -0000 1.193 --- playerc.h 8 May 2006 12:39:06 -0000 1.194 *************** *** 898,901 **** --- 898,986 ---- /**************************************************************************/ + /***************************************************************************/ + /** @ingroup playerc_proxies + * @defgroup playerc_proxy_audio audio + + The audio proxy provides access to drivers supporting the @ref audio_interface. + See the Player User Manual for a complete description of the drivers that support + this interface. + + @{ + */ + + /** @brief Audio device data. */ + typedef struct + { + /** Device info; must be at the start of all device structures. */ + playerc_device_t info; + + /** Details of the channels from the mixer. */ + player_audio_mixer_channel_list_detail_t channel_details_list; + + /** last block of recorded data */ + player_audio_wav_t wav_data; + + /** last block of seq data */ + player_audio_seq_t seq_data; + + /** current channel data */ + player_audio_mixer_channel_list_t mixer_data; + + + } playerc_audio_t; + + /** @brief Create an audio proxy. */ + playerc_audio_t *playerc_audio_create(playerc_client_t *client, int index); + + /** @brief Destroy an audio proxy. */ + void playerc_audio_destroy(playerc_audio_t *device); + + /** @brief Subscribe to the audio device. */ + int playerc_audio_subscribe(playerc_audio_t *device, int access); + + /** @brief Un-subscribe from the audio device. */ + int playerc_audio_unsubscribe(playerc_audio_t *device); + + /** @brief Command to play an audio block */ + int playerc_audio_wav_play_cmd(playerc_audio_t *device, player_audio_wav_t * data); + + /** @brief Command to set recording state */ + int playerc_audio_wav_stream_rec_cmd(playerc_audio_t *device, uint8_t state); + + /** @brief Command to play prestored sample */ + int playerc_audio_sample_play_cmd(playerc_audio_t *device, int index); + + /** @brief Command to play sequence of tones */ + int playerc_audio_seq_play_cmd(playerc_audio_t *device, player_audio_seq_t * tones); + + /** @brief Command to set mixer levels */ + int playerc_audio_mixer_channel_cmd(playerc_audio_t *device, player_audio_mixer_channel_list_t * levels); + + /** @brief Request to record a single audio block + Value is returned into wav_data, block length is determined by device */ + int playerc_audio_wav_rec(playerc_audio_t *device); + + /** @brief Request to load an audio sample */ + int playerc_audio_sample_load(playerc_audio_t *device, int index, player_audio_wav_t * data); + + /** @brief Request to retrieve an audio sample + Data is stored in wav_data */ + int playerc_audio_sample_retrieve(playerc_audio_t *device, int index); + + /** @brief Request to record new sample */ + int playerc_audio_sample_rec(playerc_audio_t *device, int index); + + /** @brief Request mixer channel data + result is stored in mixer_data*/ + int playerc_audio_get_mixer_levels(playerc_audio_t *device); + + /** @brief Request mixer channel details list + result is stored in channel_details_list*/ + int playerc_audio_get_mixer_details(playerc_audio_t *device); + + /** @} */ + /**************************************************************************/ + + /***************************************************************************/ Index: dev_ir.c =================================================================== RCS file: /cvsroot/playerstage/code/player/client_libs/libplayerc/dev_ir.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dev_ir.c 6 Sep 2005 05:39:26 -0000 1.5 --- dev_ir.c 8 May 2006 12:39:05 -0000 1.6 *************** *** 103,107 **** void *data) { ! int i; if((header->type == PLAYER_MSGTYPE_DATA) && (header->subtype == PLAYER_IR_DATA_RANGES)) --- 103,107 ---- void *data) { ! //int i; if((header->type == PLAYER_MSGTYPE_DATA) && (header->subtype == PLAYER_IR_DATA_RANGES)) |