ALSA:PCM ヘルパー関数

フォーマット
snd_pcm_format_signedフォーマットが符号付きか
snd_pcm_format_unsignedフォーマットが符号なしか
snd_pcm_format_linearフォーマットが線形か
snd_pcm_format_floatフォーマットが浮動小数点数か
snd_pcm_format_little_endianフォーマットがリトルエンディアンか
snd_pcm_format_big_endianフォーマットがビッグエンディアンか
snd_pcm_format_cpu_endianフォーマットが CPU と同じエンディアンか
snd_pcm_format_widthフォーマットのビット幅を取得
snd_pcm_format_physical_widthフォーマットの物理ビット幅を取得
snd_pcm_build_linear_format情報を指定してフォーマット取得
snd_pcm_format_size指定サンプル数に必要なバイト数を取得
無音
snd_pcm_format_silence無音を示す8bit値を取得
snd_pcm_format_silence_16無音を示す16bit値を取得
snd_pcm_format_silence_32無音を示す32bit値を取得
snd_pcm_format_silence_64無音を示す64bit値を取得
snd_pcm_format_set_silenceバッファに無音データをセット
変換
snd_pcm_bytes_to_framesバイト数からフレーム数に変換
snd_pcm_frames_to_bytesフレーム数をバイト数に変換
snd_pcm_bytes_to_samplesバイト数をサンプル数に変換
snd_pcm_samples_to_bytesサンプル数をバイト数に変換
フォーマット
int snd_pcm_format_signed(snd_pcm_format_t format);
フォーマットが符号付きか
int snd_pcm_format_unsigned(snd_pcm_format_t format);
フォーマットが符号なしか
int snd_pcm_format_linear(snd_pcm_format_t format);
フォーマットが線形か
戻り値
0 で線形でない、1 で線形
int snd_pcm_format_float(snd_pcm_format_t format);
フォーマットが浮動小数点数か
戻り値
0 で浮動小数点数でない、1 で浮動小数点数
int snd_pcm_format_little_endian(snd_pcm_format_t format);
フォーマットがリトルエンディアンか
戻り値
0 でビッグエンディアン、1 でリトルエンディアン、負の値でエンディアンに依存しない
int snd_pcm_format_big_endian(snd_pcm_format_t format);
フォーマットがビッグエンディアンか
戻り値
0 でリトルエンディアン、1 でビッグエンディアン、負の値でエンディアンに依存しない
int snd_pcm_format_cpu_endian(snd_pcm_format_t format);
フォーマットが CPU と同じエンディアンか
戻り値
0 でスワップされる、1 で同じエンディアン、負の値でエンディアンに依存しない
int snd_pcm_format_width(snd_pcm_format_t format);
フォーマットのビット幅を取得
戻り値
該当しない場合は負のエラーコード
int snd_pcm_format_physical_width(snd_pcm_format_t format);
フォーマットの物理ビット幅を取得。
サンプルを格納するのに必要なビット幅。
戻り値
該当しない場合は負のエラーコード
snd_pcm_format_t snd_pcm_build_linear_format(int width, int pwidth, int unsignd, int big_endian);
情報を指定してフォーマット取得
width
ビット幅
pwidth
物理的なビット幅
unsigned
符号なしか
big_endian
ビッグエンディアンか
戻り値
一致しない場合は SND_PCM_FORMAT_UNKNOWN
ssize_t snd_pcm_format_size(snd_pcm_format_t format, size_t samples);
指定サンプル数に必要なバイト数を取得
戻り値
整数でない場合や不明な場合は、負のエラーコード
無音
uint8_t snd_pcm_format_silence(snd_pcm_format_t format);
無音を示す8bit値を取得
uint16_t snd_pcm_format_silence_16(snd_pcm_format_t format);
無音を示す16bit値を取得
uint32_t snd_pcm_format_silence_32(snd_pcm_format_t format);
無音を示す32bit値を取得
uint64_t snd_pcm_format_silence_64(snd_pcm_format_t format);
無音を示す64bit値を取得
int snd_pcm_format_set_silence(snd_pcm_format_t format, void *buf, unsigned int samples);
バッファに無音データをセット
samples
サンプル数
戻り値
0 で成功、負の値でエラーコード
変換
snd_pcm_sframes_t snd_pcm_bytes_to_frames(snd_pcm_t *pcm, ssize_t bytes);
バイト数からフレーム数に変換
ssize_t snd_pcm_frames_to_bytes(snd_pcm_t *pcm, snd_pcm_sframes_t frames);
フレーム数をバイト数に変換
long snd_pcm_bytes_to_samples(snd_pcm_t *pcm, ssize_t bytes);
バイト数をサンプル数に変換
ssize_t snd_pcm_samples_to_bytes(snd_pcm_t *pcm, long samples);
サンプル数をバイト数に変換