X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/blobdiff_plain/7a2c706849ecf6cee19d9e502f8491ffac3322e0..4fd3886810d93a7d3d2c2505e8b9ac38df2430d1:/lib/uaudio.c diff --git a/lib/uaudio.c b/lib/uaudio.c index aa00f66..f18af09 100644 --- a/lib/uaudio.c +++ b/lib/uaudio.c @@ -28,6 +28,26 @@ /** @brief Options for chosen uaudio API */ static hash *uaudio_options; +/** @brief Sample rate (Hz) */ +int uaudio_rate; + +/** @brief Bits per channel */ +int uaudio_bits; + +/** @brief Number of channels */ +int uaudio_channels; + +/** @brief Whether samples are signed or unsigned */ +int uaudio_signed; + +/** @brief Sample size in bytes + * + * NB one sample is a single point sample; up to @c uaudio_channels samples may + * play at the same time through different speakers. Thus this value is + * independent of @ref uaudio_channels. + */ +size_t uaudio_sample_size; + /** @brief Set a uaudio option */ void uaudio_set(const char *name, const char *value) { if(!uaudio_options) @@ -44,6 +64,31 @@ const char *uaudio_get(const char *name) { return value ? xstrdup(value) : NULL; } +/** @brief Set sample format + * @param rate Sample rate in KHz + * @param channels Number of channels (i.e. 2 for stereo) + * @param bits Number of bits per channel (typically 8 or 16) + * @param signed_ True for signed samples, false for unsigned + * + * Sets @ref uaudio_rate, @ref uaudio_channels, @ref uaudio_bits, @ref + * uaudio_signed and @ref uaudio_sample_size. + * + * Currently there is no way to specify non-native endian formats even if the + * underlying API can conveniently handle them. Actually this would be quite + * convenient for playrtp, so it might be added at some point. + * + * Not all APIs can support all sample formats. Generally the @c start + * function will do some error checking but some may be deferred to the point + * the device is opened (which might be @c activate). + */ +void uaudio_set_format(int rate, int channels, int bits, int signed_) { + uaudio_rate = rate; + uaudio_channels = channels; + uaudio_bits = bits; + uaudio_signed = signed_; + uaudio_sample_size = bits / CHAR_BIT; +} + /** @brief List of known APIs * * Terminated by a null pointer.