aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md4
-rw-r--r--include/tinyalsa/pcm.h4
-rw-r--r--src/mixer.c90
-rw-r--r--src/pcm.c30
4 files changed, 124 insertions, 4 deletions
diff --git a/README.md b/README.md
index 7bcc596..71a18d6 100644
--- a/README.md
+++ b/README.md
@@ -51,7 +51,7 @@ man tinyplay
man tinycap
man tinymix
man tinypcminfo
-man tinyalsa-pcm
-man tinyalsa-mixer
+man libtinyalsa-pcm
+man libtinyalsa-mixer
```
diff --git a/include/tinyalsa/pcm.h b/include/tinyalsa/pcm.h
index 30d6da1..3d9dfaa 100644
--- a/include/tinyalsa/pcm.h
+++ b/include/tinyalsa/pcm.h
@@ -69,7 +69,7 @@ extern "C" {
*/
#define PCM_NOIRQ 0x00000002
-/* When set, calls to @ref pcm_write
+/** When set, calls to @ref pcm_write
* for a playback stream will not attempt
* to restart the stream in the case of an
* underflow, but will return -EPIPE instead.
@@ -121,7 +121,7 @@ extern "C" {
* Following the underscore, specifiers whether the sample is big endian or little endian.
* The letters 'LE' mean little endian.
* The letters 'BE' mean big endian.
- * This enumeration is used in the @ref config structure.
+ * This enumeration is used in the @ref pcm_config structure.
* @ingroup libtinyalsa-pcm
*/
enum pcm_format {
diff --git a/src/mixer.c b/src/mixer.c
index e6f50bb..0fe9c99 100644
--- a/src/mixer.c
+++ b/src/mixer.c
@@ -53,7 +53,9 @@
struct mixer_ctl {
/** The mixer that the mixer control belongs to */
struct mixer *mixer;
+ /** Information on the control's value (i.e. type, number of values) */
struct snd_ctl_elem_info info;
+ /** A list of string representations of enumerated values (only valid for enumerated controls) */
char **ename;
};
@@ -363,6 +365,13 @@ static int int_to_percent(struct snd_ctl_elem_info *ei, int value)
return ((value - ei->value.integer.min) / range) * 100;
}
+/** Gets a percentage representation of a specified control value.
+ * @param ctl An initialized control handle.
+ * @param id The index of the value within the control.
+ * @returns On success, the percentage representation of the control value.
+ * On failure, -EINVAL is returned.
+ * @ingroup libtinyalsa-mixer
+ */
int mixer_ctl_get_percent(struct mixer_ctl *ctl, unsigned int id)
{
if (!ctl || (ctl->info.type != SNDRV_CTL_ELEM_TYPE_INTEGER))
@@ -371,6 +380,14 @@ int mixer_ctl_get_percent(struct mixer_ctl *ctl, unsigned int id)
return int_to_percent(&ctl->info, mixer_ctl_get_value(ctl, id));
}
+/** Sets the value of a control by percent, specified by the value index.
+ * @param ctl An initialized control handle.
+ * @param id The index of the value to set
+ * @param percent A percentage value between 0 and 100.
+ * @returns On success, zero is returned.
+ * On failure, non-zero is returned.
+ * @ingroup libtinyalsa-mixer
+ */
int mixer_ctl_set_percent(struct mixer_ctl *ctl, unsigned int id, int percent)
{
if (!ctl || (ctl->info.type != SNDRV_CTL_ELEM_TYPE_INTEGER))
@@ -379,6 +396,13 @@ int mixer_ctl_set_percent(struct mixer_ctl *ctl, unsigned int id, int percent)
return mixer_ctl_set_value(ctl, id, percent_to_int(&ctl->info, percent));
}
+/** Gets the value of a control.
+ * @param ctl An initialized control handle.
+ * @param id The index of the control value.
+ * @returns On success, the specified value is returned.
+ * On failure, -EINVAL is returned.
+ * @ingroup libtinyalsa-mixer
+ */
int mixer_ctl_get_value(struct mixer_ctl *ctl, unsigned int id)
{
struct snd_ctl_elem_value ev;
@@ -413,6 +437,18 @@ int mixer_ctl_get_value(struct mixer_ctl *ctl, unsigned int id)
return 0;
}
+/** Gets the contents of a control's value array.
+ * @param ctl An initialized control handle.
+ * @param array A pointer to write the array data to.
+ * The size of this array must be equal to the number of items in the array
+ * multiplied by the size of each item.
+ * @param count The number of items in the array.
+ * This parameter must match the number of items in the control.
+ * The number of items in the control may be accessed via @ref mixer_ctl_get_num_values
+ * @returns On success, zero.
+ * On failure, non-zero.
+ * @ingroup libtinyalsa-mixer
+ */
int mixer_ctl_get_array(struct mixer_ctl *ctl, void *array, size_t count)
{
struct snd_ctl_elem_value ev;
@@ -475,6 +511,16 @@ int mixer_ctl_get_array(struct mixer_ctl *ctl, void *array, size_t count)
return 0;
}
+/** Sets the value of a control, specified by the value index.
+ * @param ctl An initialized control handle.
+ * @param id The index of the value within the control.
+ * @param value The value to set.
+ * This must be in a range specified by @ref mixer_ctl_get_range_min
+ * and @ref mixer_ctl_get_range_max.
+ * @returns On success, zero is returned.
+ * On failure, non-zero is returned.
+ * @ingroup libtinyalsa-mixer
+ */
int mixer_ctl_set_value(struct mixer_ctl *ctl, unsigned int id, int value)
{
struct snd_ctl_elem_value ev;
@@ -518,6 +564,16 @@ int mixer_ctl_set_value(struct mixer_ctl *ctl, unsigned int id, int value)
return ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_ELEM_WRITE, &ev);
}
+/** Sets the contents of a control's value array.
+ * @param ctl An initialized control handle.
+ * @param array The array containing control values.
+ * @param count The number of values in the array.
+ * This must match the number of values in the control.
+ * The number of values in a control may be accessed via @ref mixer_ctl_get_num_values
+ * @returns On success, zero.
+ * On failure, non-zero.
+ * @ingroup libtinyalsa-mixer
+ */
int mixer_ctl_set_array(struct mixer_ctl *ctl, const void *array, size_t count)
{
struct snd_ctl_elem_value ev;
@@ -570,6 +626,14 @@ int mixer_ctl_set_array(struct mixer_ctl *ctl, const void *array, size_t count)
return ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_ELEM_WRITE, &ev);
}
+/** Gets the minimum value of an control.
+ * The control must have an integer type.
+ * The type of the control can be checked with @ref mixer_ctl_get_type.
+ * @param ctl An initialized control handle.
+ * @returns On success, the minimum value of the control.
+ * On failure, -EINVAL.
+ * @ingroup libtinyalsa-mixer
+ */
int mixer_ctl_get_range_min(struct mixer_ctl *ctl)
{
if (!ctl || (ctl->info.type != SNDRV_CTL_ELEM_TYPE_INTEGER))
@@ -578,6 +642,14 @@ int mixer_ctl_get_range_min(struct mixer_ctl *ctl)
return ctl->info.value.integer.min;
}
+/** Gets the maximum value of an control.
+ * The control must have an integer type.
+ * The type of the control can be checked with @ref mixer_ctl_get_type.
+ * @param ctl An initialized control handle.
+ * @returns On success, the maximum value of the control.
+ * On failure, -EINVAL.
+ * @ingroup libtinyalsa-mixer
+ */
int mixer_ctl_get_range_max(struct mixer_ctl *ctl)
{
if (!ctl || (ctl->info.type != SNDRV_CTL_ELEM_TYPE_INTEGER))
@@ -586,6 +658,11 @@ int mixer_ctl_get_range_max(struct mixer_ctl *ctl)
return ctl->info.value.integer.max;
}
+/** Get the number of enumerated items in the control.
+ * @param ctl An initialized control handle.
+ * @returns The number of enumerated items in the control.
+ * @ingroup libtinyalsa-mixer
+ */
unsigned int mixer_ctl_get_num_enums(struct mixer_ctl *ctl)
{
if (!ctl)
@@ -632,6 +709,12 @@ fail:
return -1;
}
+/** Gets the string representation of an enumerated item.
+ * @param ctl An initialized control handle.
+ * @param enum_id The index of the enumerated value.
+ * @returns A string representation of the enumerated item.
+ * @ingroup libtinyalsa-mixer
+ */
const char *mixer_ctl_get_enum_string(struct mixer_ctl *ctl,
unsigned int enum_id)
{
@@ -643,6 +726,13 @@ const char *mixer_ctl_get_enum_string(struct mixer_ctl *ctl,
return (const char *)ctl->ename[enum_id];
}
+/** Set an enumeration value by string value.
+ * @param ctl An enumerated mixer control.
+ * @param string The string representation of an enumeration.
+ * @returns On success, zero.
+ * On failure, zero.
+ * @ingroup libtinyalsa-mixer
+ */
int mixer_ctl_set_enum_by_string(struct mixer_ctl *ctl, const char *string)
{
unsigned int i, num_enums;
diff --git a/src/pcm.c b/src/pcm.c
index 2ceeb33..1ce1a54 100644
--- a/src/pcm.c
+++ b/src/pcm.c
@@ -172,6 +172,7 @@ struct pcm {
int underruns;
/** Size of the buffer */
unsigned int buffer_size;
+ /** The boundary for ring buffer pointers */
unsigned int boundary;
/** Description of the last error that occured */
char error[PCM_ERROR_MAX];
@@ -182,7 +183,9 @@ struct pcm {
struct snd_pcm_sync_ptr *sync_ptr;
void *mmap_buffer;
unsigned int noirq_frames_per_msec;
+ /** The delay of the PCM, in terms of frames */
long pcm_delay;
+ /** The subdevice corresponding to the PCM */
unsigned int subdevice;
};
@@ -198,6 +201,7 @@ unsigned int pcm_get_buffer_size(struct pcm *pcm)
/** Gets the file descriptor of the PCM.
* Useful for extending functionality of the PCM when needed.
+ * @param pcm A PCM handle.
* @return The file descriptor of the PCM.
* @ingroup libtinyalsa-pcm
*/
@@ -709,6 +713,12 @@ struct pcm_mask *pcm_params_get_mask(struct pcm_params *pcm_params,
return (struct pcm_mask *)param_to_mask(params, p);
}
+/** Get the minimum of a specified PCM parameter.
+ * @param pcm_params A PCM parameters structure.
+ * @param param The specified parameter to get the minimum of.
+ * @returns On success, the parameter minimum.
+ * On failure, zero.
+ */
unsigned int pcm_params_get_min(struct pcm_params *pcm_params,
enum pcm_param param)
{
@@ -725,6 +735,12 @@ unsigned int pcm_params_get_min(struct pcm_params *pcm_params,
return param_get_min(params, p);
}
+/** Get the maximum of a specified PCM parameter.
+ * @param pcm_params A PCM parameters structure.
+ * @param param The specified parameter to get the maximum of.
+ * @returns On success, the parameter maximum.
+ * On failure, zero.
+ */
unsigned int pcm_params_get_max(struct pcm_params *pcm_params,
enum pcm_param param)
{
@@ -1118,6 +1134,14 @@ int pcm_state(struct pcm *pcm)
return pcm->mmap_status->state;
}
+/** Waits for frames to be available for read or write operations.
+ * @param pcm A PCM handle.
+ * @param timeout The maximum amount of time to wait for, in terms of milliseconds.
+ * @returns If frames became available, one is returned.
+ * If a timeout occured, zero is returned.
+ * If an error occured, a negative number is returned.
+ * @ingroup libtinyalsa-pcm
+ */
int pcm_wait(struct pcm *pcm, int timeout)
{
struct pollfd pfd;
@@ -1253,6 +1277,12 @@ int pcm_mmap_read(struct pcm *pcm, void *data, unsigned int count)
return pcm_mmap_transfer(pcm, data, count);
}
+/** Gets the delay of the PCM, in terms of frames.
+ * @param pcm A PCM handle.
+ * @returns On success, the delay of the PCM.
+ * On failure, a negative number.
+ * @ingroup libtinyalsa-pcm
+ */
long pcm_get_delay(struct pcm *pcm)
{
if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_DELAY, &pcm->pcm_delay) < 0)