Advanced Linux Sound Architecture - Library API

Jaroslav Kysela <perex@suse.cz> with assistance from Alan Robinson and Fred Floberg

1998-11-11

This document describes, in full detail, the Advanced Linux Sound Architecture library API.

このドキュメントはAdvanced Linux Sound Architecture library APIについて詳細に記述されています。.

目次

1  はじめに
2  エラーコード
    2.1  エラーコードの詳細
    2.2  関数
3  Controlインターフェース
    3.1  Low-Level レイヤ
        3.1.1  Example
4  Mixerインターフェース
    4.1  Low-Level レイヤ
        4.1.1  Example
5  Digital Audio (PCM)インターフェース
    5.1  Low-Level Layer
        5.1.1  Example
    5.2  PCM Loopbackインターフェース
6  RawMidiインターフェース
    6.1  Low Levelレイヤ
        6.1.1  Example

1  はじめに

The Advanced Linux Sound Architecture comes with a kernel API & library API. This document describes the library API and how it interfaces with the kernel API. The kernal API will probably never be documented in standalone form.

Advanced Linux Sound ArchitectureにはKernel APIとlibrary APIがあります。 このドキュメントはlibrary APIとどのようなkernel APIのインターフェースがあるかを記述しています。

Application programmers should use the library API rather than kernel API. The Library offers 100% of the functionally of the kernel API, but add major improvements in usability, making the application code simpler and better looking. In addition, some of the some fixes/compatibility code may be placed in the library code instead of the kernel driver.

アプリケーションプログラマはkernel APIよりむしろlibrary APIを使用すべきです。 library は kernel API の機能を100%提供していますが、用途に適するように大きな改善を加えていて、アプリケーションコードが簡潔に見通し易くなるように作られています。加えて何らかの小さな修正や互換性のあるコードはkernelドライバの代わりにlibraryコードに移すかもしれません。

For a complete list of all variables and functions in the API you should look at the following header files:

APIのすべての変数や関数の完全なリストは次のヘッダーファイルから見ることができます。

2  エラーコード

All functions return int (or some sort of signed value). If this value is negative it represents an error code. Codes up to SND_ERROR_BEGIN (500000) represent standard system errors. Codes equal to or greather than this value represent sound library API errors. All error codes begin with the prefix SND_ERROR_.

すべての関数はint型(またはある種の符号つきの値)を返します。もしこの値が負の値の場合はエラーコードとみなします。コードはSND_ERROR_BEGIN (500000)までの場合は標準のシステムエラーを意味します。それ以上の値の場合はsound library APIのエラーです。すべてのエラーコードはSND_ERROR_で始まります。

2.1  エラーコードの詳細

SND_ERROR_UNCOMPATIBLE_VERSION500000

This error is caused if the driver uses an incompatible kernel API for this interface and hence the library doesn't know how this API can be used.

このエラーはドライバーがこのインターフェースのために矛盾したKernel APIを使ってそのためにライブラリがこのAPIをどのように使われるのかわからない場合が原因となります。

2.2  関数

const char *snd_strerror(int errnum)

This function converts an error code to a string. Its functionality is the same as the strerror function from the standard C library, but this function returns error message strings for sound error codes, as well.

この関数はエラーコードを文字列に変換します。この関数は標準Cライブラリのstrerrorとにていますが、この関数はsoundのエラーコードのエラーメッセージも返します。

3  Controlインターフェース

The control interface gives applications various information about the currently installed sound driver in the system. The interface should be used to detect if another sound interface is present for a selected soundcard or, for example, to create a list of devices (MIXER, PCM etc) from which the user can select.

Controlインターフェースは現在システムにインストールされているサウンドドライバについての多くの情報をアプリケーションに渡します。これは別のサウンドインターフェースが現在の選択しているサウンドカードかどうかを検出するとか、例えば使用者から選択可能なデバイスのリスト(MIXERやPCMなど)を作成するのに使用するでしょう。

3.1  Low-Level レイヤ

int snd_cards(void)

Returns the number of soundcards present in the system, if any. Otherwise it returns a negative value, which maps to an error code. This function will return 0 if no soundcards are detected.

もしあれば現在のシステムにあるサウンドカードの番号を返します。そうでなければエラーコードを示した分値を返します。この関数はサウンドカードを検出しながった場合は0を返すでしょう。

unsigned int snd_cards_mask(void)

Returns the bitmap of soundcards present in the system, if any. This function will return 0 if no soundcards are detected. The first soundcard is represented with bit 0 (0x00000001). See the documentation on installing ALSA and /etc/conf.modules configuration for information on assigning numbers to soundcards.

もしあれば現在のシステムにあるサウンドカードのビットマップを返します。この関数はサウンドカードを検出しながった場合は0を返すでしょう。最初のサウンドカードはビット0 (0x00000001)を示します。インストールされているALSAのドキュメントと/etc/conf.modulesのサウンドカードに割り当てた番号の情報の設定を見て下さい。

int snd_card_name(const char *name)

Returns soundcard number for appropriate soundcard name. String name can contain word identification for card (ALSA driver allows the user choose card identification using snd_id module parameter) or soundcard index (1-N) encoded into ASCII.

サウンドカードの名称に適した番号を返します。文字列nameはカードの識別用の語(ALSAドライバはモジュールパラメータsnd_idを使ってカードの識別を使用者が決めて与えます)またはASCIIに変換したサウンドカードのインデックス(1-N)を含ませることができます。

int snd_ctl_open(void **handle, int card)

Creates a new handle and opens communication with the kernel sound control interface for soundcard number card (0-N). The function also checks if the protocol is compatible, so as to prevent the use of old programs with a new kernel API. Function returns zero if successful, otherwise an error code is returned.

サウンドカード番号card(0-N)に対する新しいハンドルを作成してkernelのサウンドcontrolインターフェースで通信をopenします。この関数はさらプロトコルに互換があるかチェックして、新しいkernel APIにも関わらず古いプログラムが使われるのを防止しています。関数は成功すれば0を返し、そうでなければエラーコードを返します。

int snd_ctl_close(void *handle)

Frees all resources allocated with control handle and closes the kernel sound control interface. This function returns zero if successful, otherwise it returns an error code.

割り当てられたcontrolハンドルのすべてのリソースを解放しkernelのサウンドcontrolインターフェースを閉じます。関数は成功すれば0を返し、そうでなければエラーコードを返します。

int snd_ctl_file_descriptor(void *handle)

Returns a file descriptor for the kernel sound control interface. This function is normally only used in very special cases. This function returns a negative error code if an error was encountered.

kernelのサウンドcontrolインターフェースのためにファイルディスクリプタを返します。この関数は普通は相当特殊なケースで使うのみです。エラーに遭遇した場合は負の数のエラーコードを返します。

int snd_ctl_hw_info(void *handle, snd_ctl_hw_info_t *info)

Fills the info structure with data about the sound hardware referenced by handle. This function returns zero if successful, otherwise it returns an error code.

ハンドルを用いてサウンドハードウェアの照会に関する情報のデータをinfo構造体に与えます。関数は成功すれば0を返し、そうでなければエラーコードを返します。

/* ドライバにMIDIインターフェースがある */ 

#define SND_CTL_GCAPS_MIDI      0x0000001 

/* サウンドカードにシンセサイザがある */

#define SND_CTL_LCAPS_SYNTH     0x0000001

/* サウンドカードにRAW FM/OPL3がある */

#define SND_CTL_LCAPS_RAWFM     0x0000002

 

struct snd_ctl_hw_info {

        /* カードのタイプ SND_CARD_TYPE_XXXX を参照 */

        unsigned int type;

        /* global capabilities  SND_CTL_GCAPS_XXXX を参照 */

        unsigned int gcaps;

        /* local capabilities  SND_CTL_LCAPS_XXXX を参照 */

        unsigned int lcaps;

        /* PCMデバイスの数 (0 から N) */

        unsigned int pcmdevs;

        /* MIXERデバイスの数 (0 から N)*/

        unsigned int mixerdevs;

        /* raw MIDIデバイスの数 (0 から N) */

        unsigned int mididevs;

        /* カードのID (使用者が選択) */

        char id[80];

        /* soundcardの名前や情報 */

        char name[80];

        /* Controlスイッチの数 */

        unsigned int switches;

        /* 予約 */

        unsigned char reserved[124];

};

int snd_ctl_switches(void *handle)

Returns the number of control switches. In this context 'switch' means universal control interface between kernel and application which allows various types of control. Function returns count if successful, otherwise it returns an error code. Return value should be zero if the soundcard doesn't have any control switches.

controlスイッチの数を返します。このスイッチとは一般的なControlインターフェースとkernelやアプリケーション間で与える多くのcontrolのタイプのことです。関数は成功すればその数をそうでなければエラーコードを返します。サウンドカードに何もcontrolスイッチがなければ0を返すでしょう。

int snd_ctl_switch(void *handle, const char *switch_id)

Returns the index for the switch with the name switch_id. This function returns switch index if successful, otherwise it returns an error code.

名称switchの示すスイッチのためのインデックスを返します。この関数は成功すればスイッチインデックスをそうでなければエラーコードを返します。

int snd_ctl_switch_read(void *handle, int switchn, snd_ctl_switch_t *data)

Fills the *data structure with data about the switch with index switchn. This function returns zero if successful, otherwise it returns an error code.

*data構造体にインデックスswitchnの示すスイッチに関するデータを与えます。この関数は成功すれば0を返し、そうでなければエラーコードを返します。

/* 0または1 (共用体のメンバを有効にする) */

#define SND_CTL_SW_TYPE_BOOLEAN       0

/* 0から255 - 最小から最大 (data8[0] 共用体のメンバ) */

#define SND_CTL_SW_TYPE_BYTE          1

/* 0から65535 - 最小から最大 (data16[0] 共用体のメンバ) */

#define SND_CTL_SW_TYPE_WORD          2

/* 0から4294967296 ¯  最小から最大 (data32[0] 共用体のメンバ) */

#define SND_CTL_SW_TYPE_DWORD         3

/* user type - タイプのコントロールではない */

#define SND_CTL_SW_TYPE_USER          (~0)

 

/* 良く知られている(名付けられている)スイッチ */

#define SND_CTL_SW_JOYSTICK           "Joystick"

#define SND_CTL_SW_JOYSTICK_ADDRESS   "Joystick Address"

#define SND_CTL_SW_JOYSTICK_SPEED     "Joystick Speed"

 

struct snd_ctl_switch {

        /* スイッチインデックス (アプリケーションによって与えられる。) */

        unsigned int switchn;

        /* スイッチの(ドライバのための)識別 */

        unsigned char name[32];

        /* スイッチの値の型 - SND_CTL_SW_TYPE_XXXX 参照 */

        unsigned int type;

        /* 最低値の値 */

        unsigned int low;

        /* 最大値の値 */

        unsigned int high;

        union {

                unsigned int enable;        /* 0 = off 1 = on */

                unsigned char data8[32];    /* 8-bit data */

                unsigned short data16[16];  /* 16-bit data */

                unsigned int data32[8];     /* 32-bit data */

        } value;

        /* 将来の拡張用の予約 ¯  ゼロで与えなければならない */

        unsigned char reserved[32];

}

int snd_ctl_switch_write(void *handle int switchn snd_ctl_switch_t *data)

Writes the *data structure with data about the switch with index switchn to kernel. This function returns zero if successful, otherwise it returns an error code.

kernelへ*data構造体にインデックスswitchnの示すスイッチに関するデータを書き込みます。この関数は成功すれば0を返し、そうでなければエラーコードを返します。

int snd_ctl_mixer_info(void *handle, int dev, snd_mixer_info_t *info)

Fills the *info structure with data about the mixer device. Returns zero if successful, otherwise it returns an error code. Details about the snd_mixer_info_t structure are in the Mixer Interface section. The argument dev specifies the device number for the appropriate soundcard. Its range is 0 to N where N is determined by struct snd_ctl_hw_info->mixerdevs - 1. It should be used to collect information about mixer devices.

info構造体にMixerデバイスに関するデータを与えます。成功すれば0を返し、そうでなければエラーコードを返します。snd_mixer_info_t構造体についての詳細はMixerインターフェースにあります。引数devはそのサウンドカードに適したデバイス番号に特定します。 その範囲は0からNで、Nとはstruct snd_ctl_hw_info->mixerdevs - 1によって決まります。Mixerデバイスの情報を集める時に使うでしょう。

int snd_ctl_mixer_switches(void *handle)

Returns count of mixer switches. In this context 'switch' means universal control interface between kernel and application which allows various types control. This function returns count if successful, otherwise it returns an error code. Return value should be zero if soundcard doesn't have any mixer switches.

Mixerスイッチの数を返します。このスイッチとは一般的なControlインターフェースとkernelやアプリケーション間で与える多くのcontrolのタイプのことです。この関数は成功すれば0を返し、そうでなければエラーコードを返します。サウンドカードにMixerスイッチがない場合は値はゼロを返すでしょう。

int snd_ctl_mixer_switch(void *handle, const char *switch_id)

Returns the index for the switch with the name switch_id. This function returns switch index if successful, otherwise it returns an error code.

名称switch_idの示すスイッチのためのインデックスを返します。この関数は成功すれば0を返し、そうでなければエラーコードを返します。

int snd_ctl_mixer_switch_read(void *handle int switchn snd_mixer_switch_t *data)

Fills the *data structure with data about the switch with index switchn. This function returns zero if successful, otherwise it returns an error code. Details about the snd_mixer_switch_t structure are in the Mixer Interface section.

*data構造体にインデックスswitchnの示すスイッチに関するデータを与えます。この関数は成功すれば0を返し、そうでなければエラーコードを返します。snd_mixer_switch_t構造体についての詳細はMixerインターフェースにあります。

int snd_ctl_mixer_switch_write(void *handle int switchn snd_mixer_switch_t *data)

Writes the *data structure with data about switch with index switchn to kernel. Function returns zero if successful, otherwise it returns an error code. Details about the snd_mixer_switch_t structure are in the Mixer Interface Interface section.

kernelへ*data構造体にインデックスswitchnの示すスイッチに関するデータを書き込みます。この関数は成功すれば0を返し、そうでなければエラーコードを返します。snd_mixer_switch_t構造体についての詳細はMixerインターフェースにあります。

int snd_ctl_pcm_info(void *handle, int dev, snd_pcm_info_t *info)

Fills the *info structure with data about the PCM device. Function returns zero if successful, otherwise it returns an error code. Details about the snd_pcm_info_t structure are in the Digital Audio (PCM) Interface section. The argument dev selects the device number for the sound card referenced by *handle. Its range is 0 to N where N is struct snd_ctl_hw_info->pcmdevs - 1. This function will work if the selected PCM device is busy, too. It should be used to collect information about PCM devices without exclusive lock.

info構造体にPCMデバイスに関するデータを与えます。成功すれば0を返し、そうでなければエラーコードを返します。snd_pcm_info_t構造体についての詳細はDigital Audio (PCM)インターフェースにあります。引数dev*handleによって参照されるサウンドカードに適したデバイス番号を選びます。 その範囲は0からNで、Nとはstruct snd_ctl_hw_info->pcmdevs - 1によって決まります。この関数は選択されたPCMデバイスがbusyでも動作するでしょう。排他的ロックをなしにPCMデバイスの情報を集める時に使うべきです。

int snd_ctl_pcm_playback_info(void *handle, int dev, snd_pcm_playback_info_t *info)

Fills the *info structure with data about the PCM device and playback direction. Function returns zero if successful, otherwise it returns an error code. Details about the snd_pcm_playback_info_t structure are in the Digital Audio (PCM) Interface section. The argument dev selects the device number for the sound card referenced by *handle. Its range is 0 to N where N is struct snd_ctl_hw_info->pcmdevs - 1. This function will work if the selected PCM device is busy, too. It should be used to collect information about PCM devices without exclusive lock.

info構造体にPCMデバイスと再生方面に関するデータを与えます。成功すれば0を返し、そうでなければエラーコードを返します。snd_pcm_playback_info_t構造体についての詳細はDigital Audio (PCM)インターフェースにあります。引数dev*handleによって参照されるサウンドカードに適したデバイス番号を選びます。 その範囲は0からNで、Nとはstruct snd_ctl_hw_info->pcmdevs - 1によって決まります。この関数は選択されたPCMデバイスがbusyでも動作するでしょう。排他的ロックをなしにPCMデバイスの情報を集める時に使うべきです。

int snd_ctl_pcm_playback_switches(void *handle)

Returns count of PCM playback switches. In this context 'switch' means universal control interface between kernel and application which allows various types of control. Function returns count if successful, otherwise it returns an error code. Return value should be zero if sound card doesn't have any PCM playback switch.

PCM再生スイッチの数を返します。このスイッチとは一般的なControlインターフェースとkernelやアプリケーション間で与える多くのcontrolのタイプのことです。この関数は成功すれば0を返し、そうでなければエラーコードを返します。サウンドカードにPCM再生スイッチがない場合は値はゼロを返すでしょう。

int snd_ctl_pcm_playback_switch(void *handle, const char *switch_id)

Returns index for switch with name switch_id. Function returns switch index if successful, otherwise it returns an error code.

名称switch_idの示すスイッチのためのインデックスを返します。この関数は成功すれば0を返し、そうでなければエラーコードを返します。

int snd_ctl_pcm_playback_switch_read(void *handle int switchnsnd_pcm_switch_t *data)

Fills the *data structure with data about switch with index switchn. Function returns zero if successful, otherwise it returns an error code. Details about the snd_pcm_switch_t structure are in the Digital Audio (PCM) Interface section.

*data構造体にインデックスswitchnの示すスイッチに関するデータを与えます。この関数は成功すれば0を返し、そうでなければエラーコードを返します。snd_pcm_switch_t構造体についての詳細はDigital Audio (PCM)インターフェースにあります。

int snd_ctl_pcm_playback_switch_write(void *handle int switchnsnd_pcm_switch_t *data)

Writes the *data structure with data about switch with index switchn to kernel. Function returns zero if successful, otherwise it returns an error code. Details about the snd_pcm_switch_t structure are in the Digital Audio (PCM) Interface section.

kernelへ*data構造体にインデックスswitchnの示すスイッチに関するデータを書き込みます。この関数は成功すれば0を返し、そうでなければエラーコードを返します。snd_pcm_switch_t構造体についての詳細はDigital Audio (PCM)インターフェースにあります。

int snd_ctl_pcm_record_info(void *handle, int dev, snd_pcm_record_info_t *info)

Fills the *info structure with data about the PCM device and record direction. Function returns zero if successful, otherwise it returns an error code. Details about the snd_pcm_record_info_t structure are in the Digital Audio (PCM) Interface section. The argument dev selects the device number for the sound card referenced by *handle. Its range is 0 to N where N is struct snd_ctl_hw_info->pcmdevs - 1. This function will work if the selected PCM device is busy, too. It should be used to collect information about PCM devices without exclusive lock.

info構造体にPCMデバイスと録音方面に関するデータを与えます。成功すれば0を返し、そうでなければエラーコードを返します。snd_pcm_record_info_t構造体についての詳細はDigital Audio (PCM)インターフェースにあります。引数dev*handleによって参照されるサウンドカードに適したデバイス番号を選びます。 その範囲は0からNで、Nとはstruct snd_ctl_hw_info->pcmdevs - 1によって決まります。この関数は選択されたPCMデバイスがbusyでも動作するでしょう。排他的ロックをなしにPCMデバイスの情報を集める時に使うべきです。

int snd_ctl_pcm_record_switches(void *handle)

Returns count of PCM record switches. In this context 'switch' means universal control interface between kernel and application which allows various types of control. Function returns count if successful, otherwise it returns an error code. Return value should be zero if sound card doesn't have any PCM record switch.

PCM録音スイッチの数を返します。このスイッチとは一般的なControlインターフェースとkernelやアプリケーション間で与える多くのcontrolのタイプのことです。この関数は成功すれば0を返し、そうでなければエラーコードを返します。サウンドカードにPCM録音スイッチがない場合は値はゼロを返すでしょう。

int snd_ctl_pcm_record_switch(void *handle, const char *switch_id)

Returns index for switch with name switch_id. Function returns switch index if successful, otherwise it returns an error code.

名称switch_idの示すスイッチのためのインデックスを返します。この関数は成功すれば0を返し、そうでなければエラーコードを返します。

int snd_ctl_pcm_record_switch_read(void *handle int switchnsnd_pcm_switch_t *data)

Fills the *data structure with data about switch with index switchn. Function returns zero if successful, otherwise it returns an error code. Details about the snd_pcm_switch_t structure are in the Digital Audio (PCM) Interface section.

*data構造体にインデックスswitchnの示すスイッチに関するデータを与えます。この関数は成功すれば0を返し、そうでなければエラーコードを返します。snd_pcm_switch_t構造体についての詳細はDigital Audio (PCM)インターフェースにあります。

int snd_ctl_pcm_record_switch_write(void *handle int switchnsnd_pcm_switch_t *data)

Writes the *data structure with data about switch with index switchn to kernel. Function returns zero if successful, otherwise it returns an error code. Details about the snd_pcm_switch_t structure are in the Digital Audio (PCM) Interface section.

kernelへ*data構造体にインデックスswitchnの示すスイッチに関するデータを書き込みます。この関数は成功すれば0を返し、そうでなければエラーコードを返します。snd_pcm_switch_t構造体についての詳細はDigital Audio (PCM)インターフェースにあります。

int snd_ctl_rawmidi_info(void *handle, int dev, snd_rawmidi_info_t *info)

Fills the *info structure with data about the rawmidi device. Function returns zero if successful, otherwise it returns an error code. Details about the snd_rawmidi_info_t structure are in the RawMidi Interface section. The argument dev selects the device number for the sound card referenced by *handle. Its range is 0 to N where N is struct snd_ctl_hw_info->mididevs - 1. This function will work if the selected rawmidi device is busy, too. It should be used to collect information about rawmidi devices without exclusive lock.

info構造体にrawmidiデバイスに関するデータを与えます。成功すれば0を返し、そうでなければエラーコードを返します。snd_rawmidi_info_t構造体についての詳細はRaw Midiインターフェースにあります。引数dev*handleによって参照されるサウンドカードに適したデバイス番号を選びます。 その範囲は0からNで、Nとはstruct snd_ctl_hw_info->mididevs - 1によって決まります。この関数は選択されたPCMデバイスがbusyでも動作するでしょう。排他的ロックをなしにrawmidiデバイスの情報を集める時に使うべきです。

int snd_ctl_rawmidi_output_info(void *handle, int dev, snd_rawmidi_output_info_t *info)

Fills the *info structure with data about the rawmidi device and output direction. Function returns zero if successful, otherwise it returns an error code. Details about the snd_rawmidi_output_info_t structure are in the RawMidi Interface section. The argument dev selects the device number for the sound card referenced by *handle. Its range is 0 to N where N is struct snd_ctl_hw_info->mididevs - 1. This function will work if the selected rawmidi device is busy, too. It should be used to collect information about rawmidi devices without exclusive lock.

info構造体にrawmidiデバイスと出力方面に関するデータを与えます。成功すれば0を返し、そうでなければエラーコードを返します。snd_rawmidi_output_info_t構造体についての詳細はRaw Midiインターフェースにあります。引数dev*handleによって参照されるサウンドカードに適したデバイス番号を選びます。 その範囲は0からNで、Nとはstruct snd_ctl_hw_info->mididevs - 1によって決まります。この関数は選択されたrawmidiデバイスがbusyでも動作するでしょう。排他的ロックをなしにrawmidiデバイスの情報を集める時に使うべきです。

int snd_ctl_rawmidi_output_switches(void *handle)

Returns count of rawmidi output switches. In this context 'switch' means universal control interface between kernel and application which allows various types of control. Function returns count if successful, otherwise it returns an error code. Return value should be zero if sound card doesn't have any control switch.

rawmidi出力スイッチの数を返します。このスイッチとは一般的なControlインターフェースとkernelやアプリケーション間で与える多くのcontrolのタイプのことです。この関数は成功すれば0を返し、そうでなければエラーコードを返します。サウンドカードにcontrolスイッチがない場合は値はゼロを返すでしょう。

int snd_ctl_rawmidi_output_switch(void *handle, const char *switch_id)

Returns index for switch with name switch_id. Function returns switch index if successful, otherwise it returns an error code. Return value should be zero if sound card doesn't have any rawmidi output switch.

名称switch_idの示すスイッチのためにインデックスを返します。この関数は成功すれば0を返し、そうでなければエラーコードを返します。サウンドカードにrawmidi出力スイッチがない場合は値はゼロを返すでしょう。

int snd_ctl_rawmidi_output_switch_read(void *handle int switchnsnd_rawmidi_switch_t *data)

Fills the *data structure with data about switch with index switchn. Function returns zero if successful, otherwise it returns an error code. Details about the snd_rawmidi_switch_t structure are in the RawMidi Interface section.

*data構造体にインデックスswitchnの示すスイッチに関するデータを与えます。この関数は成功すれば0を返し、そうでなければエラーコードを返します。snd_rawmidi_switch_t構造体についての詳細はRawMidiインターフェースにあります。

int snd_ctl_rawmidi_output_switch_write(void *handle int switchnsnd_rawmidi_switch_t *data)

Writes the *data structure with data about switch with index switchn to kernel. Function returns zero if successful, otherwise it returns an error code. Details about the snd_rawmidi_switch_t structure are in the RawMidi Interface section.

kernelへ*data構造体にインデックスswitchnの示すスイッチに関するデータを書き込みます。この関数は成功すれば0を返し、そうでなければエラーコードを返します。snd_rawmidi_switch_t構造体についての詳細はRawMidiインターフェースにあります。

int snd_ctl_rawmidi_input_info(void *handle, int dev, snd_rawmidi_input_info_t *info)

Fills the *info structure with data about the rawmidi device and input direction. Function returns zero if successful, otherwise it returns an error code. Details about the snd_rawmidi_record_info_t structure are in the RawMidi Interface section. The argument dev selects the device number for the sound card referenced by *handle. Its range is 0 to N where N is struct snd_ctl_hw_info->mididevs - 1. This function will work if the selected rawmidi device is busy, too. It should be used to collect information about rawmidi devices without exclusive lock.

info構造体にrawmidiデバイスと入力方面に関するデータを与えます。成功すれば0を返し、そうでなければエラーコードを返します。snd_rawmidi_input_info_t構造体についての詳細はRaw Midiインターフェースにあります。引数dev*handleによって参照されるサウンドカードに適したデバイス番号を選びます。 その範囲は0からNで、Nとはstruct snd_ctl_hw_info->mididevs - 1によって決まります。この関数は選択されたrawmidiデバイスがbusyでも動作するでしょう。排他的ロックをなしにrawmidiデバイスの情報を集める時に使うべきです。

int snd_ctl_rawmidi_input_switches(void *handle)

Returns count of rawmidi input switches. In this context 'switch' means universal control interface between kernel and application which allows various types of control. Function returns count if successful, otherwise it returns an error code. Return value should be zero if sound card doesn't have any rawmidi input switch.

rawmidi入力スイッチの数を返します。このスイッチとは一般的なControlインターフェースとkernelやアプリケーション間で与える多くのcontrolのタイプのことです。この関数は成功すれば0を返し、そうでなければエラーコードを返します。rawmidi入力スイッチがない場合は値はゼロを返すでしょう。

int snd_ctl_rawmidi_input_switch(void *handle, const char *switch_id)

Returns index for switch with name switch_id. Function returns switch index if successful, otherwise it returns an error code.

名称switch_idの示すスイッチのためにインデックスを返します。この関数は成功すれば0を返し、そうでなければエラーコードを返します。

int snd_ctl_rawmidi_input_switch_read(void *handle int switchnsnd_pcm_switch_t *data)

Fills the *data structure with data about switch with index switchn. Function returns zero if successful, otherwise it returns an error code. Details about the snd_rawmidi_switch_t structure are in the RawMidi Interface Interface section.

*data構造体にインデックスswitchnの示すスイッチに関するデータを与えます。この関数は成功すれば0を返し、そうでなければエラーコードを返します。snd_rawmidi_switch_t構造体についての詳細はRawMidiインターフェースにあります。

int snd_ctl_rawmidi_input_switch_write(void *handle int switchnsnd_pcm_switch_t *data)

Writes the *data structure with data about switch with index switchn to kernel. Function returns zero if successful, otherwise it returns an error code. Details about the snd_rawmidi_switch_t structure are in the RawMidi Interface section.

kernelへ*data構造体にインデックスswitchnの示すスイッチに関するデータを書き込みます。この関数は成功すれば0を返し、そうでなければエラーコードを返します。snd_rawmidi_switch_t構造体についての詳細はRawMidiインターフェースにあります。

3.1.1  Example

The following example shows how all PCM devices can be detected for the first sound card (#0) in the system.

以下の例はシステムで最初のサウンドカード(#0)に検出可能なすべてのPCMデバイスがどのようなものかを見せます。

int card = 0, err; 

void *handle; 

snd_ctl_hw_info_t info;

if ((err = snd_ctl_open(&handle, card)) < 0) { 

        fprintf(stderr, "open failed: %s\n", snd_strerror(err));

        return; 

if ((err = snd_ctl_hw_info(handle, &info)) < 0) {

        fprintf(stderr, "hw info failed: %s\n",

                                        snd_strerror(err)); 

        snd_ctl_close(handle);

        return; 

}

printf("Installed PCM devices for card #i: %i\n",

                                    card + 1, info.pcmdevs); 

snd_ctl_close(handle);