libtinyalsa-pcm(3)
β¨ libtinyalsa-pcm(3) β PCM Interface β¨
Library Functions Manual Β· the libtinyalsa-pcm page, bestie π
πΈ NAME
libtinyalsa-pcm β PCM Interface
- All macros, structures and functions that make up the PCM interface.
π¦ SYNOPSIS
π Data Structures
struct pcmβ A PCM handle. πstruct pcm_configβ Encapsulates the hardware and software parameters of a PCM.struct pcm_plugin_opsβ Operations that are required to be registered by the plugin.struct pcm_plugin_min_maxβ Minimum and maximum values for hardware parameter constraints.struct pcm_plugin_hw_constraintsβ Encapsulate the hardware parameter constraints. π
π Macros
#define PCM_OUT 0x00000000β A flag that specifies that the PCM is an output. π#define PCM_IN 0x10000000β Specifies that the PCM is an input.#define PCM_MMAP 0x00000001β Specifies that the PCM will usemmapread and write methods.#define PCM_NOIRQ 0x00000002β Specifies no interrupt requests.#define PCM_NORESTART 0x00000004β When set, calls topcm_writefor a playback stream will not attempt to restart the stream in the case of an underflow, but will return-EPIPEinstead. π#define PCM_MONOTONIC 0x00000008β Specifies monotonic timestamps.#define PCM_NONBLOCK 0x00000010β If used withpcm_openandpcm_params_get, it will not cause the function to block if the PCM is not available.#define PCM_STATE_OPEN 0x00β Means a PCM is opened.#define PCM_STATE_SETUP 0x01β Means a PCMHW_PARAMSis set.#define PCM_STATE_PREPARED 0x02β Means a PCM is prepared.#define PCM_STATE_RUNNING 0x03β For inputs, this means the PCM is recording audio samples. ποΈ#define PCM_STATE_SUSPENDED 0x07β Means a PCM is suspended.#define PCM_STATE_DISCONNECTED 0x08β Means a PCM has been disconnected. π
π Enumerations
enum pcm_format β Audio sample format of a PCM.
enum pcm_format { PCM_FORMAT_INVALID = -1, PCM_FORMAT_S16_LE = 0, PCM_FORMAT_S32_LE, PCM_FORMAT_S8, PCM_FORMAT_S24_LE, PCM_FORMAT_S24_3LE, PCM_FORMAT_S16_BE, PCM_FORMAT_S24_BE, PCM_FORMAT_S24_3BE, PCM_FORMAT_S32_BE, PCM_FORMAT_MAX }
enum pcm_param β Enumeration of a PCM's hardware parameters.
enum pcm_param { PCM_PARAM_ACCESS, PCM_PARAM_FORMAT, PCM_PARAM_SUBFORMAT, PCM_PARAM_SAMPLE_BITS, PCM_PARAM_FRAME_BITS, PCM_PARAM_CHANNELS, PCM_PARAM_RATE, PCM_PARAM_PERIOD_TIME, PCM_PARAM_PERIOD_SIZE, PCM_PARAM_PERIOD_BYTES, PCM_PARAM_PERIODS, PCM_PARAM_BUFFER_TIME, PCM_PARAM_BUFFER_SIZE, PCM_PARAM_BUFFER_BYTES, PCM_PARAM_TICK_TIME }
π«Ά Functions
unsigned int pcm_get_buffer_size (const struct pcm *pcm)β Gets the buffer size of the PCM. πunsigned int pcm_get_channels (const struct pcm *pcm)β Gets the channel count of the PCM.const struct pcm_config * pcm_get_config (const struct pcm *pcm)β Gets the PCM configuration.unsigned int pcm_get_rate (const struct pcm *pcm)β Gets the rate of the PCM.enum pcm_format pcm_get_format (const struct pcm *pcm)β Gets the format of the PCM.int pcm_get_file_descriptor (const struct pcm *pcm)β Gets the file descriptor of the PCM.const char * pcm_get_error (const struct pcm *pcm)β Gets the error message for the last error that occured. πint pcm_set_config (struct pcm *pcm, const struct pcm_config *config)β Sets the PCM configuration.unsigned int pcm_format_to_bits (enum pcm_format format)β Determines the number of bits occupied by apcm_format.unsigned int pcm_bytes_to_frames (const struct pcm *pcm, unsigned int bytes)β Determines how many frames of a PCM can fit into a number of bytes.unsigned int pcm_frames_to_bytes (const struct pcm *pcm, unsigned int frames)β Determines how many bytes are occupied by a number of frames of a PCM.struct pcm_params * pcm_params_get (unsigned int card, unsigned int device, unsigned int flags)β Gets the hardware parameters of a PCM, without created a PCM handle.void pcm_params_free (struct pcm_params *pcm_params)β Frees the hardware parameters returned bypcm_params_get.const struct pcm_mask * pcm_params_get_mask (const struct pcm_params *pcm_params, enum pcm_param param)β Gets a mask from a PCM's hardware parameters.int pcm_close (struct pcm *pcm)β Closes a PCM returned bypcm_open.struct pcm * pcm_open_by_name (const char *name, unsigned int flags, const struct pcm_config *config)β Opens a PCM by it's name.struct pcm * pcm_open (unsigned int card, unsigned int device, unsigned int flags, const struct pcm_config *config)β Opens a PCM.int pcm_is_ready (const struct pcm *pcm)β Checks if a PCM file has been opened without error.int pcm_link (struct pcm *pcm1, struct pcm *pcm2)β Links two PCMs. πint pcm_unlink (struct pcm *pcm)β Unlinks a PCM.int pcm_prepare (struct pcm *pcm)β Prepares a PCM, if it has not been prepared already.int pcm_start (struct pcm *pcm)β Starts a PCM. π₯int pcm_stop (struct pcm *pcm)β Stops a PCM.int pcm_wait (struct pcm *pcm, int timeout)β Waits for frames to be available for read or write operations.int pcm_writei (struct pcm *pcm, const void *data, unsigned int frame_count)β Writes audio samples to PCM.int pcm_readi (struct pcm *pcm, void *data, unsigned int frame_count)β Reads audio samples from PCM.int pcm_write (struct pcm *pcm, const void *data, unsigned int count)β Writes audio samples to PCM.int pcm_read (struct pcm *pcm, void *data, unsigned int count)β Reads audio samples from PCM.long pcm_get_delay (struct pcm *pcm)β Gets the delay of the PCM, in terms of frames. β³
π₯ Detailed Description
All macros, structures and functions that make up the PCM interface. That's the whole vibe, bestie. π
π Macro Definition Documentation
#define PCM_IN 0x10000000β Specifies that the PCM is an input. May not be bitwiseAND'dwithPCM_OUT. Used inpcm_open. π«Ά#define PCM_MMAP 0x00000001β Specifies that the PCM will usemmapread and write methods. Used inpcm_open.#define PCM_MONOTONIC 0x00000008β Specifies monotonic timestamps. Used inpcm_open.#define PCM_NOIRQ 0x00000002β Specifies no interrupt requests. May only be bitwiseAND'dwithPCM_MMAP. Used inpcm_open.#define PCM_NONBLOCK 0x00000010β If used withpcm_openandpcm_params_get, it will not cause the function to block if the PCM is not available. It will also cause the functionspcm_readiandpcm_writeito exit if they would cause the caller to wait. π#define PCM_NORESTART 0x00000004β When set, calls topcm_writefor a playback stream will not attempt to restart the stream in the case of an underflow, but will return-EPIPEinstead. After the first-EPIPEerror, the stream is considered to be stopped, and a second call topcm_writewill attempt to restart the stream. Used inpcm_open. π#define PCM_OUT 0x00000000β A flag that specifies that the PCM is an output. May not be bitwiseAND'dwithPCM_IN. Used inpcm_open. π#define PCM_STATE_RUNNING 0x03β For inputs, this means the PCM is recording audio samples. For outputs, this means the PCM is playing audio samples. πΆ
π§ Enumeration Type Documentation
π enum pcm_format
Audio sample format of a PCM. The first letter specifiers whether the sample is signed or unsigned. The letter S means signed. The letter U means unsigned. The following number is the amount of bits that the sample occupies in memory. 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 pcm_config structure. π
Enumerator
PCM_FORMAT_S16_LEβ Signed 16-bit, little endian.PCM_FORMAT_S32_LEβ Signed, 32-bit, little endian.PCM_FORMAT_S8β Signed, 8-bit.PCM_FORMAT_S24_LEβ Signed, 24-bit (32-bit in memory), little endian.PCM_FORMAT_S24_3LEβ Signed, 24-bit, little endian.PCM_FORMAT_S16_BEβ Signed, 16-bit, big endian.PCM_FORMAT_S24_BEβ Signed, 24-bit (32-bit in memory), big endian.PCM_FORMAT_S24_3BEβ Signed, 24-bit, big endian.PCM_FORMAT_S32_BEβ Signed, 32-bit, big endian.PCM_FORMAT_MAXβ Max of the enumeration list, not an actual format. β
π¦ enum pcm_param
Enumeration of a PCM's hardware parameters. Each of these parameters is either a mask or an interval. π
Enumerator
PCM_PARAM_ACCESSβ A mask that represents the type of read or write method available (e.g. interleaved,mmap).PCM_PARAM_FORMATβ A mask that represents thepcm_formatavailable (e.g.PCM_FORMAT_S32_LE)PCM_PARAM_SUBFORMATβ A mask that represents the subformat available.PCM_PARAM_SAMPLE_BITSβ An interval representing the range of sample bits available (e.g. 8 to 32)PCM_PARAM_FRAME_BITSβ An interval representing the range of frame bits available (e.g. 8 to 64)PCM_PARAM_CHANNELSβ An interval representing the range of channels available (e.g. 1 to 2)PCM_PARAM_RATEβ An interval representing the range of rates available (e.g. 44100 to 192000)PCM_PARAM_PERIOD_SIZEβ The number of frames in a period.PCM_PARAM_PERIOD_BYTESβ The number of bytes in a period.PCM_PARAM_PERIODSβ The number of periods for a PCM.
π Function Documentation π
pcm_bytes_to_frames
unsigned int pcm_bytes_to_frames (const struct pcm * pcm, unsigned int bytes)
Bestie, this is the βhow many frames fit in this many bytes?β math moment. It determines how many frames of a PCM can fit into a number of bytes.
Parameters:
pcmβ a PCM handle.bytesβ the number of bytes.
Returns: the number of frames that may fit into bytes.
pcm_close
int pcm_close (struct pcm * pcm)
Closes a PCM returned by pcm_open.
Parameters:
pcmβ a PCM returned bypcm_open. May not beNULL.
Returns: always returns zero. Slay, no drama.
pcm_format_to_bits
unsigned int pcm_format_to_bits (enum pcm_format format)
Determines the number of bits occupied by a pcm_format.
Parameters:
formatβ a PCM format.
Returns: the number of bits associated with format.
pcm_frames_to_bytes
unsigned int pcm_frames_to_bytes (const struct pcm * pcm, unsigned int frames)
Determines how many bytes are occupied by a number of frames of a PCM. Byte math era π₯
Parameters:
pcmβ a PCM handle.framesβ the number of frames of a PCM.
Returns: the bytes occupied by frames.
pcm_get_buffer_size
unsigned int pcm_get_buffer_size (const struct pcm * pcm)
Gets the buffer size of the PCM.
Parameters:
pcmβ a PCM handle.
Returns: the buffer size of the PCM.
pcm_get_channels
unsigned int pcm_get_channels (const struct pcm * pcm)
Gets the channel count of the PCM.
Parameters:
pcmβ a PCM handle.
Returns: the channel count of the PCM.
pcm_get_config
const struct pcm_config * pcm_get_config (const struct pcm * pcm)
Gets the PCM configuration.
Parameters:
pcmβ a PCM handle.
Returns: the PCM configuration. This function only returns NULL if pcm is NULL. iykyk π«Ά
pcm_get_delay
long pcm_get_delay (struct pcm * pcm)
Gets the delay of the PCM, in terms of frames.
Parameters:
pcmβ a PCM handle.
Returns: on success, the delay of the PCM. On failure, a negative number.
pcm_get_error
const char * pcm_get_error (const struct pcm * pcm)
Gets the error message for the last error that occured. β οΈ Heads up: if no error occured and this function is called, the results are undefined.
Parameters:
pcmβ a PCM handle.
Returns: the error message of the last error that occured.
pcm_get_file_descriptor
int pcm_get_file_descriptor (const struct pcm * pcm)
Gets the file descriptor of the PCM. Useful for extending functionality of the PCM when needed.
Parameters:
pcmβ a PCM handle.
Returns: the file descriptor of the PCM.
pcm_get_format
enum pcm_format pcm_get_format (const struct pcm * pcm)
Gets the format of the PCM.
Parameters:
pcmβ a PCM handle.
Returns: the format of the PCM.
pcm_get_rate
unsigned int pcm_get_rate (const struct pcm * pcm)
Gets the rate of the PCM. The rate is given in frames per second.
Parameters:
pcmβ a PCM handle.
Returns: the rate of the PCM.
pcm_is_ready
int pcm_is_ready (const struct pcm * pcm)
Checks if a PCM file has been opened without error.
Parameters:
pcmβ a PCM handle. May beNULL.
Returns: if a PCMβs file descriptor is not valid or the pointer is NULL, it returns zero. Otherwise, the function returns one. vibe check passed β
pcm_link
int pcm_link (struct pcm * pcm1, struct pcm * pcm2)
Links two PCMs. After this function is called, the two PCMs will prepare, start and stop in sync (at the same time). If an error occurs, the error message will be written to pcm1.
Parameters:
pcm1β a PCM handle.pcm2β another PCM handle.
Returns: on success, zero; on failure, a negative number.
pcm_open
struct pcm * pcm_open (unsigned int card, unsigned int device, unsigned int flags, const struct pcm_config * config)
Opens a PCM. main character moment β¨
Parameters:
cardβ the card that the pcm belongs to. The default card is zero.deviceβ the device that the pcm belongs to. The default device is zero.flagsβ specify characteristics and functionality about the pcm. May be a bitwise AND of the following:PCM_INPCM_OUTPCM_MMAPPCM_NOIRQPCM_MONOTONIC
configβ the hardware and software parameters to open the PCM with.
Returns: a PCM structure. If an error occurs, the pointer of bad_pcm is returned. Otherwise, it returns the pointer of PCM object. Client code should check that the PCM opened properly by calling pcm_is_ready. If pcm_is_ready returns false, check pcm_get_error for more information.
pcm_open_by_name
struct pcm * pcm_open_by_name (const char * name, unsigned int flags, const struct pcm_config * config)
Opens a PCM by itβs name.
Parameters:
nameβ the name of the PCM. The name is given in the format:hw:card,deviceflagsβ specify characteristics and functionality about the pcm. May be a bitwise AND of the following:PCM_INPCM_OUTPCM_MMAPPCM_NOIRQPCM_MONOTONIC
configβ the hardware and software parameters to open the PCM with.
Returns: a PCM structure. If an error occurs, the pointer of bad_pcm is returned. Otherwise, it returns the pointer of PCM object. Client code should check that the PCM opened properly by calling pcm_is_ready. If pcm_is_ready returns false, check pcm_get_error for more information.
pcm_params_free
void pcm_params_free (struct pcm_params * pcm_params)
Frees the hardware parameters returned by pcm_params_get.
Parameters:
pcm_paramsβ hardware parameters of a PCM. May beNULL.
pcm_params_get
struct pcm_params * pcm_params_get (unsigned int card, unsigned int device, unsigned int flags)
Gets the hardware parameters of a PCM, without created a PCM handle. no handle needed, weβre just peeking π
Parameters:
cardβ the card of the PCM. The default card is zero.deviceβ the device of the PCM. The default device is zero.flagsβ specifies whether the PCM is an input or output. May be one of the following:PCM_INPCM_OUT
Returns: on success, the hardware parameters of the PCM; on failure, NULL.
pcm_params_get_mask
const struct pcm_mask * pcm_params_get_mask (const struct pcm_params * pcm_params, enum pcm_param param)
Gets a mask from a PCMβs hardware parameters.
Parameters:
pcm_paramsβ a PCMβs hardware parameters.paramβ the parameter to get.
Returns: if pcm_params is NULL or param is not a mask, NULL is returned. Otherwise, the mask associated with param is returned.
pcm_prepare
int pcm_prepare (struct pcm * pcm)
Prepares a PCM, if it has not been prepared already.
Parameters:
pcmβ a PCM handle.
Returns: on success, zero; on failure, a negative number.
pcm_read
int pcm_read (struct pcm * pcm, void * data, unsigned int count)
Reads audio samples from PCM. If the PCM has not been started, it is started in this function. This function is only valid for PCMs opened with the PCM_IN flag. This function is not valid for PCMs opened with the PCM_MMAP flag.
Parameters:
pcmβ a PCM handle.dataβ the audio sample array.countβ the number of bytes occupied by the sample array.
Returns: on success, this function returns zero; otherwise, a negative number.
β οΈ Deprecated β yes bestie, itβs deprecated.
pcm_readi
int pcm_readi (struct pcm * pcm, void * data, unsigned int frame_count)
Reads audio samples from PCM. If the PCM has not been started, it is started in this function. This function is only valid for PCMs opened with the PCM_IN flag.
Parameters:
pcmβ a PCM handle.dataβ the audio sample array.frame_countβ the number of frames occupied by the sample array. This value should not be greater thanTINYALSA_FRAMES_MAXorINT_MAX.
Returns: on success, this function returns the number of frames written; otherwise, a negative number.
pcm_set_config
int pcm_set_config (struct pcm * pcm, const struct pcm_config * config)
Sets the PCM configuration.
Parameters:
pcmβ a PCM handle.configβ the configuration to use for the PCM. This parameter may beNULL, in which case the default configuration is used.
Returns: zero on success, a negative errno value on failure.
pcm_start
int pcm_start (struct pcm * pcm)
Starts a PCM. go go go π
Parameters:
pcmβ a PCM handle.
Returns: on success, zero; on failure, a negative number.
pcm_stop
int pcm_stop (struct pcm * pcm)
Stops a PCM.
Parameters:
pcmβ a PCM handle.
Returns: on success, zero; on failure, a negative number.
pcm_unlink
int pcm_unlink (struct pcm * pcm)
Unlinks a PCM.
See also: pcm_link
Parameters:
pcmβ a PCM handle.
Returns: on success, zero; on failure, a negative number.
pcm_wait
int pcm_wait (struct pcm * pcm, int timeout)
Waits for frames to be available for read or write operations.
Parameters:
pcmβ a PCM handle.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.
pcm_write
int pcm_write (struct pcm * pcm, const void * data, unsigned int count)
Writes audio samples to PCM. If the PCM has not been started, it is started in this function. This function is only valid for PCMs opened with the PCM_OUT flag. This function is not valid for PCMs opened with the PCM_MMAP flag.
Parameters:
pcmβ a PCM handle.dataβ the audio sample array.countβ the number of bytes occupied by the sample array.
Returns: on success, this function returns zero; otherwise, a negative number.
β οΈ Deprecated β another deprecated icon, bestie.
pcm_writei
int pcm_writei (struct pcm * pcm, const void * data, unsigned int frame_count)
Writes audio samples to PCM. If the PCM has not been started, it is started in this function. This function is only valid for PCMs opened with the PCM_OUT flag.
Parameters:
pcmβ a PCM handle.dataβ the audio sample array.frame_countβ the number of frames occupied by the sample array. This value should not be greater thanTINYALSA_FRAMES_MAXorINT_MAX.
Returns: on success, this function returns the number of frames written; otherwise, a negative number.
π Author π
Generated automatically by Doxygen for TinyALSA from the source code.
Thatβs the whole function roster, bestie! π This page is from TinyALSA, version 1.1.0, manual page libtinyalsa-pcm(3) β and the footer didnβt give us a date, so Iβm not making one up. π«Άβ¨
π¦ where this page comes from
- alpine 3.24: tinyalsa-doc 2.0.0-r4 Β· BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms