/* * PCM Interface - misc routines * Copyright (c) 1998 by Jaroslav Kysela <perex@perex.cz> * * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
*/
/** * snd_pcm_format_signed - Check the PCM format is signed linear * @format: the format to check * * Return: 1 if the given PCM format is signed linear, 0 if unsigned * linear, and a negative error code for non-linear formats.
*/ int snd_pcm_format_signed(snd_pcm_format_t format)
{ int val; if (!valid_format(format)) return -EINVAL;
val = pcm_formats[(INT)format].signd; if (val < 0) return -EINVAL; return val;
}
EXPORT_SYMBOL(snd_pcm_format_signed);
/** * snd_pcm_format_unsigned - Check the PCM format is unsigned linear * @format: the format to check * * Return: 1 if the given PCM format is unsigned linear, 0 if signed * linear, and a negative error code for non-linear formats.
*/ int snd_pcm_format_unsigned(snd_pcm_format_t format)
{ int val;
val = snd_pcm_format_signed(format); if (val < 0) return val; return !val;
}
EXPORT_SYMBOL(snd_pcm_format_unsigned);
/** * snd_pcm_format_linear - Check the PCM format is linear * @format: the format to check * * Return: 1 if the given PCM format is linear, 0 if not.
*/ int snd_pcm_format_linear(snd_pcm_format_t format)
{ return snd_pcm_format_signed(format) >= 0;
}
EXPORT_SYMBOL(snd_pcm_format_linear);
/** * snd_pcm_format_little_endian - Check the PCM format is little-endian * @format: the format to check * * Return: 1 if the given PCM format is little-endian, 0 if * big-endian, or a negative error code if endian not specified.
*/ int snd_pcm_format_little_endian(snd_pcm_format_t format)
{ int val; if (!valid_format(format)) return -EINVAL;
val = pcm_formats[(INT)format].le; if (val < 0) return -EINVAL; return val;
}
EXPORT_SYMBOL(snd_pcm_format_little_endian);
/** * snd_pcm_format_big_endian - Check the PCM format is big-endian * @format: the format to check * * Return: 1 if the given PCM format is big-endian, 0 if * little-endian, or a negative error code if endian not specified.
*/ int snd_pcm_format_big_endian(snd_pcm_format_t format)
{ int val;
val = snd_pcm_format_little_endian(format); if (val < 0) return val; return !val;
}
EXPORT_SYMBOL(snd_pcm_format_big_endian);
/** * snd_pcm_format_width - return the bit-width of the format * @format: the format to check * * Return: The bit-width of the format, or a negative error code * if unknown format.
*/ int snd_pcm_format_width(snd_pcm_format_t format)
{ int val; if (!valid_format(format)) return -EINVAL;
val = pcm_formats[(INT)format].width; if (!val) return -EINVAL; return val;
}
EXPORT_SYMBOL(snd_pcm_format_width);
/** * snd_pcm_format_physical_width - return the physical bit-width of the format * @format: the format to check * * Return: The physical bit-width of the format, or a negative error code * if unknown format.
*/ int snd_pcm_format_physical_width(snd_pcm_format_t format)
{ int val; if (!valid_format(format)) return -EINVAL;
val = pcm_formats[(INT)format].phys; if (!val) return -EINVAL; return val;
}
EXPORT_SYMBOL(snd_pcm_format_physical_width);
/** * snd_pcm_format_size - return the byte size of samples on the given format * @format: the format to check * @samples: sampling rate * * Return: The byte size of the given samples for the format, or a * negative error code if unknown format.
*/
ssize_t snd_pcm_format_size(snd_pcm_format_t format, size_t samples)
{ int phys_width = snd_pcm_format_physical_width(format); if (phys_width < 0) return -EINVAL; return samples * phys_width / 8;
}
EXPORT_SYMBOL(snd_pcm_format_size);
/** * snd_pcm_format_silence_64 - return the silent data in 8 bytes array * @format: the format to check * * Return: The format pattern to fill or %NULL if error.
*/ constunsignedchar *snd_pcm_format_silence_64(snd_pcm_format_t format)
{ if (!valid_format(format)) return NULL; if (! pcm_formats[(INT)format].phys) return NULL; return pcm_formats[(INT)format].silence;
}
EXPORT_SYMBOL(snd_pcm_format_silence_64);
/** * snd_pcm_format_set_silence - set the silence data on the buffer * @format: the PCM format * @data: the buffer pointer * @samples: the number of samples to set silence * * Sets the silence data on the buffer for the given samples. * * Return: Zero if successful, or a negative error code on failure.
*/ int snd_pcm_format_set_silence(snd_pcm_format_t format, void *data, unsignedint samples)
{ int width; unsignedchar *dst; constunsignedchar *pat;
if (!valid_format(format)) return -EINVAL; if (samples == 0) return 0;
width = pcm_formats[(INT)format].phys; /* physical width */ if (!width) return -EINVAL;
pat = pcm_formats[(INT)format].silence; /* signed or 1 byte data */ if (pcm_formats[(INT)format].signd == 1 || width <= 8) { unsignedint bytes = samples * width / 8;
memset(data, *pat, bytes); return 0;
} /* non-zero samples, fill using a loop */
width /= 8;
dst = data; #if 0 while (samples--) {
memcpy(dst, pat, width);
dst += width;
} #else /* a bit optimization for constant width */ switch (width) { case 2: while (samples--) {
memcpy(dst, pat, 2);
dst += 2;
} break; case 3: while (samples--) {
memcpy(dst, pat, 3);
dst += 3;
} break; case 4: while (samples--) {
memcpy(dst, pat, 4);
dst += 4;
} break; case 8: while (samples--) {
memcpy(dst, pat, 8);
dst += 8;
} break;
} #endif return 0;
}
EXPORT_SYMBOL(snd_pcm_format_set_silence);
/** * snd_pcm_hw_limit_rates - determine rate_min/rate_max fields * @hw: the pcm hw instance * * Determines the rate_min and rate_max fields from the rates bits of * the given hw. * * Return: Zero if successful.
*/ int snd_pcm_hw_limit_rates(struct snd_pcm_hardware *hw)
{ int i; unsignedint rmin, rmax;
rmin = UINT_MAX;
rmax = 0; for (i = 0; i < (int)snd_pcm_known_rates.count; i++) { if (hw->rates & (1 << i)) {
rmin = min(rmin, snd_pcm_known_rates.list[i]);
rmax = max(rmax, snd_pcm_known_rates.list[i]);
}
} if (rmin > rmax) return -EINVAL;
hw->rate_min = rmin;
hw->rate_max = rmax; return 0;
}
EXPORT_SYMBOL(snd_pcm_hw_limit_rates);
/** * snd_pcm_rate_to_rate_bit - converts sample rate to SNDRV_PCM_RATE_xxx bit * @rate: the sample rate to convert * * Return: The SNDRV_PCM_RATE_xxx flag that corresponds to the given rate, or * SNDRV_PCM_RATE_KNOT for an unknown rate.
*/ unsignedint snd_pcm_rate_to_rate_bit(unsignedint rate)
{ unsignedint i;
for (i = 0; i < snd_pcm_known_rates.count; i++) if (snd_pcm_known_rates.list[i] == rate) return 1u << i; return SNDRV_PCM_RATE_KNOT;
}
EXPORT_SYMBOL(snd_pcm_rate_to_rate_bit);
/** * snd_pcm_rate_bit_to_rate - converts SNDRV_PCM_RATE_xxx bit to sample rate * @rate_bit: the rate bit to convert * * Return: The sample rate that corresponds to the given SNDRV_PCM_RATE_xxx flag * or 0 for an unknown rate bit.
*/ unsignedint snd_pcm_rate_bit_to_rate(unsignedint rate_bit)
{ unsignedint i;
for (i = 0; i < snd_pcm_known_rates.count; i++) if ((1u << i) == rate_bit) return snd_pcm_known_rates.list[i]; return 0;
}
EXPORT_SYMBOL(snd_pcm_rate_bit_to_rate);
/** * snd_pcm_rate_mask_intersect - computes the intersection between two rate masks * @rates_a: The first rate mask * @rates_b: The second rate mask * * This function computes the rates that are supported by both rate masks passed * to the function. It will take care of the special handling of * SNDRV_PCM_RATE_CONTINUOUS and SNDRV_PCM_RATE_KNOT. * * Return: A rate mask containing the rates that are supported by both rates_a * and rates_b.
*/ unsignedint snd_pcm_rate_mask_intersect(unsignedint rates_a, unsignedint rates_b)
{
rates_a = snd_pcm_rate_mask_sanitize(rates_a);
rates_b = snd_pcm_rate_mask_sanitize(rates_b);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.