1 module pulse.simple; 2 3 version(linux): 4 5 import pulse.channelmap; 6 import pulse.sample; 7 import pulse.def; 8 9 extern (C): 10 11 /*** 12 This file is part of PulseAudio. 13 14 Copyright 2004-2006 Lennart Poettering 15 Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB 16 17 PulseAudio is free software; you can redistribute it and/or modify 18 it under the terms of the GNU Lesser General Public License as published 19 by the Free Software Foundation; either version 2.1 of the License, 20 or (at your option) any later version. 21 22 PulseAudio is distributed in the hope that it will be useful, but 23 WITHOUT ANY WARRANTY; without even the implied warranty of 24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 General Public License for more details. 26 27 You should have received a copy of the GNU Lesser General Public License 28 along with PulseAudio; if not, see <http://www.gnu.org/licenses/>. 29 ***/ 30 31 /** \page simple Simple API 32 * 33 * \section overv_sec Overview 34 * 35 * The simple API is designed for applications with very basic sound 36 * playback or capture needs. It can only support a single stream per 37 * connection and has no support for handling of complex features like 38 * events, channel mappings and volume control. It is, however, very simple 39 * to use and quite sufficient for many programs. 40 * 41 * \section conn_sec Connecting 42 * 43 * The first step before using the sound system is to connect to the 44 * server. This is normally done this way: 45 * 46 * \code 47 * pa_simple *s; 48 * pa_sample_spec ss; 49 * 50 * ss.format = PA_SAMPLE_S16NE; 51 * ss.channels = 2; 52 * ss.rate = 44100; 53 * 54 * s = pa_simple_new(NULL, // Use the default server. 55 * "Fooapp", // Our application's name. 56 * PA_STREAM_PLAYBACK, 57 * NULL, // Use the default device. 58 * "Music", // Description of our stream. 59 * &ss, // Our sample format. 60 * NULL, // Use default channel map 61 * NULL, // Use default buffering attributes. 62 * NULL, // Ignore error code. 63 * ); 64 * \endcode 65 * 66 * At this point a connected object is returned, or NULL if there was a 67 * problem connecting. 68 * 69 * \section transfer_sec Transferring data 70 * 71 * Once the connection is established to the server, data can start flowing. 72 * Using the connection is very similar to the normal read() and write() 73 * system calls. The main difference is that they're called pa_simple_read() 74 * and pa_simple_write(). Note that these operations always block. 75 * 76 * \section ctrl_sec Buffer control 77 * 78 * \li pa_simple_get_latency() - Will return the total latency of 79 * the playback or record pipeline, respectively. 80 * \li pa_simple_flush() - Will throw away all data currently in buffers. 81 * 82 * If a playback stream is used then the following operation is available: 83 * 84 * \li pa_simple_drain() - Will wait for all sent data to finish playing. 85 * 86 * \section cleanup_sec Cleanup 87 * 88 * Once playback or capture is complete, the connection should be closed 89 * and resources freed. This is done through: 90 * 91 * \code 92 * pa_simple_free(s); 93 * \endcode 94 */ 95 96 /** \file 97 * A simple but limited synchronous playback and recording 98 * API. This is a synchronous, simplified wrapper around the standard 99 * asynchronous API. 100 * 101 * See also \subpage simple 102 */ 103 104 /** \example pacat-simple.c 105 * A simple playback tool using the simple API */ 106 107 /** \example parec-simple.c 108 * A simple recording tool using the simple API */ 109 110 /** \struct pa_simple 111 * An opaque simple connection object */ 112 struct pa_simple; 113 114 /** Create a new connection to the server. */ 115 116 /**< Server name, or NULL for default */ 117 /**< A descriptive name for this client (application name, ...) */ 118 /**< Open this stream for recording or playback? */ 119 /**< Sink (resp. source) name, or NULL for default */ 120 /**< A descriptive name for this stream (application name, song title, ...) */ 121 /**< The sample type to use */ 122 /**< The channel map to use, or NULL for default */ 123 /**< Buffering attributes, or NULL for default */ 124 /**< A pointer where the error code is stored when the routine returns NULL. It is OK to pass NULL here. */ 125 pa_simple* pa_simple_new ( 126 const(char)* server, 127 const(char)* name, 128 pa_stream_direction_t dir, 129 const(char)* dev, 130 const(char)* stream_name, 131 const(pa_sample_spec)* ss, 132 const(pa_channel_map)* map, 133 const(pa_buffer_attr)* attr, 134 int* error); 135 136 /** Close and free the connection to the server. The connection object becomes invalid when this is called. */ 137 void pa_simple_free (pa_simple* s); 138 139 /** Write some data to the server. Returns zero on success, negative on error. */ 140 int pa_simple_write (pa_simple* s, const(void)* data, size_t bytes, int* error); 141 142 /** Wait until all data already written is played by the daemon. 143 * Returns zero on success, negative on error. */ 144 int pa_simple_drain (pa_simple* s, int* error); 145 146 /** Read some data from the server. This function blocks until \a bytes amount 147 * of data has been received from the server, or until an error occurs. 148 * Returns zero on success, negative on failure. */ 149 150 /**< The connection object. */ 151 /**< A pointer to a buffer. */ 152 /**< The number of bytes to read. */ 153 154 /**< A pointer where the error code is stored when the function returns 155 * a negative value. It is OK to pass NULL here. */ 156 int pa_simple_read (pa_simple* s, void* data, size_t bytes, int* error); 157 158 /** Return the playback or record latency. */ 159 pa_usec_t pa_simple_get_latency (pa_simple* s, int* error); 160 161 /** Flush the playback or record buffer. This discards any audio in the buffer. 162 * Returns zero on success, negative on error. */ 163 int pa_simple_flush (pa_simple* s, int* error); 164