本文整理汇总了C++中snd_pcm_format_physical_width函数的典型用法代码示例。如果您正苦于以下问题:C++ snd_pcm_format_physical_width函数的具体用法?C++ snd_pcm_format_physical_width怎么用?C++ snd_pcm_format_physical_width使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了snd_pcm_format_physical_width函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init_data
static void init_data(struct linear_priv *data,
snd_pcm_format_t src_format, snd_pcm_format_t dst_format)
{
int src_le, dst_le, src_bytes, dst_bytes;
src_bytes = snd_pcm_format_width(src_format) / 8;
dst_bytes = snd_pcm_format_width(dst_format) / 8;
src_le = snd_pcm_format_little_endian(src_format) > 0;
dst_le = snd_pcm_format_little_endian(dst_format) > 0;
data->dst_bytes = dst_bytes;
data->cvt_endian = src_le != dst_le;
data->copy_bytes = src_bytes < dst_bytes ? src_bytes : dst_bytes;
if (src_le) {
data->copy_ofs = 4 - data->copy_bytes;
data->src_ofs = src_bytes - data->copy_bytes;
} else
data->src_ofs = snd_pcm_format_physical_width(src_format) / 8 -
src_bytes;
if (dst_le)
data->dst_ofs = 4 - data->dst_bytes;
else
data->dst_ofs = snd_pcm_format_physical_width(dst_format) / 8 -
dst_bytes;
if (snd_pcm_format_signed(src_format) !=
snd_pcm_format_signed(dst_format)) {
if (dst_le)
data->flip = (__force u32)cpu_to_le32(0x80000000);
else
data->flip = (__force u32)cpu_to_be32(0x80000000);
}
}
示例2: share_areas
static void share_areas(snd_pcm_direct_t *dshare,
const snd_pcm_channel_area_t *src_areas,
const snd_pcm_channel_area_t *dst_areas,
snd_pcm_uframes_t src_ofs,
snd_pcm_uframes_t dst_ofs,
snd_pcm_uframes_t size)
{
unsigned int chn, dchn, channels;
snd_pcm_format_t format;
channels = dshare->channels;
format = dshare->shmptr->s.format;
if (dshare->interleaved) {
unsigned int fbytes = snd_pcm_format_physical_width(format) / 8;
memcpy(((char *)dst_areas[0].addr) + (dst_ofs * channels * fbytes),
((char *)src_areas[0].addr) + (src_ofs * channels * fbytes),
size * channels * fbytes);
} else {
for (chn = 0; chn < channels; chn++) {
dchn = dshare->bindings ? dshare->bindings[chn] : chn;
snd_pcm_area_copy(&dst_areas[dchn], dst_ofs, &src_areas[chn], src_ofs, size, format);
}
}
}
示例3: pcm_init
/**********************************************************************************
* pcm_init()
*
***********************************************************************************/
static void pcm_init(void)
{
int err;
snd_pcm_hw_params_t *hwparams;
snd_pcm_sw_params_t *swparams;
snd_pcm_hw_params_alloca(&hwparams);
snd_pcm_sw_params_alloca(&swparams);
if ((err = snd_pcm_open(&handle, device, SND_PCM_STREAM_PLAYBACK, 0)) < 0)
{
printf("Playback open error: %s\n", snd_strerror(err));
}
if ((err = set_hwparams(handle, hwparams,SND_PCM_ACCESS_RW_INTERLEAVED)) < 0)
{
printf("Setting of hwparams failed: %s\n", snd_strerror(err));
exit(EXIT_FAILURE);
}
if ((err = set_swparams(handle, swparams)) < 0)
{
printf("Setting of swparams failed: %s\n", snd_strerror(err));
exit(EXIT_FAILURE);
}
/*分配空间 period的空间,period指向空间首地址*/
period_size_real = period_size * channels * snd_pcm_format_physical_width(format) / 8;//snd_pcm_format_physical_width:return bits needed to store a PCM sample.
period = malloc(period_size_real);
if (period == NULL)
{
printf("No enough memory\n");
exit(EXIT_FAILURE);
}
fprintf(stdout,"pcm_init sucess !\n");
}
示例4: snd_pcm_plugin_build_copy
int snd_pcm_plugin_build_copy(struct snd_pcm_substream *plug,
struct snd_pcm_plugin_format *src_format,
struct snd_pcm_plugin_format *dst_format,
struct snd_pcm_plugin **r_plugin)
{
int err;
struct snd_pcm_plugin *plugin;
int width;
snd_assert(r_plugin != NULL, return -ENXIO);
*r_plugin = NULL;
snd_assert(src_format->format == dst_format->format, return -ENXIO);
snd_assert(src_format->rate == dst_format->rate, return -ENXIO);
snd_assert(src_format->channels == dst_format->channels, return -ENXIO);
width = snd_pcm_format_physical_width(src_format->format);
snd_assert(width > 0, return -ENXIO);
err = snd_pcm_plugin_build(plug, "copy", src_format, dst_format,
0, &plugin);
if (err < 0)
return err;
plugin->transfer = copy_transfer;
*r_plugin = plugin;
return 0;
}
示例5: snd_pcm_area_silence
int snd_pcm_area_silence(const snd_pcm_channel_area_t *dst_area,
snd_pcm_uframes_t dst_offset,
unsigned int samples, snd_pcm_format_t format)
{
char *dst;
unsigned int dst_step;
int width;
if (!dst_area->addr)
return 0;
width = snd_pcm_format_physical_width(format);
if (width < 8)
return area_silence_4bit(dst_area, dst_offset, samples, format);
dst = snd_pcm_channel_area_addr(dst_area, dst_offset);
if (dst_area->step == (unsigned int) width) {
snd_pcm_format_set_silence(format, dst, samples);
return 0;
}
dst_step = dst_area->step / 8;
while (samples-- > 0) {
snd_pcm_format_set_silence(format, dst, 1);
dst += dst_step;
}
return 0;
}
示例6: snd_pcm_linear_get_index
int snd_pcm_linear_get_index(snd_pcm_format_t src_format, snd_pcm_format_t dst_format)
{
int sign, width, pwidth, endian;
sign = (snd_pcm_format_signed(src_format) !=
snd_pcm_format_signed(dst_format));
#ifdef SND_LITTLE_ENDIAN
endian = snd_pcm_format_big_endian(src_format);
#else
endian = snd_pcm_format_little_endian(src_format);
#endif
if (endian < 0)
endian = 0;
pwidth = snd_pcm_format_physical_width(src_format);
width = snd_pcm_format_width(src_format);
if (pwidth == 24) {
switch (width) {
case 24:
width = 0; break;
case 20:
width = 1; break;
case 18:
default:
width = 2; break;
}
return width * 4 + endian * 2 + sign + 16;
} else {
width = width / 8 - 1;
return width * 4 + endian * 2 + sign;
}
}
示例7: sndo_pcm_param_format
/**
* \brief Set stream format
* \param pcm ordinary PCM handle
* \param rate requested channels
* \param used_rate returned real channels
* \return 0 on success otherwise a negative error code
*/
int sndo_pcm_param_format(sndo_pcm_t *pcm, snd_pcm_format_t format, snd_pcm_subformat_t subformat)
{
int err;
if (subformat != SND_PCM_SUBFORMAT_STD)
return -EINVAL;
err = snd_pcm_format_physical_width(format);
if (err < 0)
return err;
if (err % 8)
return -EINVAL;
err = sndo_pcm_setup(pcm);
if (err < 0)
return err;
if (pcm->playback) {
err = snd_pcm_hw_params_set_format(pcm->capture, pcm->p_hw_params, format);
if (err < 0) {
SNDERR("cannot set requested format for the playback direction");
return err;
}
}
if (pcm->capture) {
err = snd_pcm_hw_params_set_format(pcm->capture, pcm->c_hw_params, format);
if (err < 0) {
SNDERR("cannot set requested format for the capture direction");
return err;
}
}
return 0;
}
示例8: play_callback
static void play_callback(snd_async_handler_t *ahandler)
{
snd_pcm_t *handle = snd_async_handler_get_pcm(ahandler);
int err;
signed short *samples_buf;
samples_buf = malloc((period_size * channels * snd_pcm_format_physical_width(format)) / 8);
if(file_capture == 0)
{
printf("err file\r\n");
}
struct timeval oldtv;
struct timeval tv;
/*avasounil = snd_pcm_avail_update(handle);*/
if ((err = snd_pcm_readi (handle, samples_buf,period_size)) != period_size)
{
fprintf (stderr, "read from audio interface failed (%s)\n",snd_strerror (err));
exit (1);
}
else
{
gettimeofday(&tv,NULL);
printf("time %lu\n",(tv.tv_sec-oldtv.tv_sec)*1000000+tv.tv_usec-oldtv.tv_usec);
oldtv = tv;
fwrite(samples_buf,2,910,file_capture);
}
}
示例9: zylonite_voice_hw_params
static int zylonite_voice_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params)
{
struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_soc_dai *codec_dai = rtd->codec_dai;
struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
unsigned int pll_out = 0;
unsigned int wm9713_div = 0;
int ret = 0;
int rate = params_rate(params);
int width = snd_pcm_format_physical_width(params_format(params));
/* Only support ratios that we can generate neatly from the AC97
* based master clock - in particular, this excludes 44.1kHz.
* In most applications the voice DAC will be used for telephony
* data so multiples of 8kHz will be the common case.
*/
switch (rate) {
case 8000:
wm9713_div = 12;
break;
case 16000:
wm9713_div = 6;
break;
case 48000:
wm9713_div = 2;
break;
default:
/* Don't support OSS emulation */
return -EINVAL;
}
/* Add 1 to the width for the leading clock cycle */
pll_out = rate * (width + 1) * 8;
ret = snd_soc_dai_set_sysclk(cpu_dai, PXA_SSP_CLK_AUDIO, 0, 1);
if (ret < 0)
return ret;
ret = snd_soc_dai_set_pll(cpu_dai, 0, 0, 0, pll_out);
if (ret < 0)
return ret;
if (clk_pout)
ret = snd_soc_dai_set_clkdiv(codec_dai, WM9713_PCMCLK_PLL_DIV,
WM9713_PCMDIV(wm9713_div));
else
ret = snd_soc_dai_set_clkdiv(codec_dai, WM9713_PCMCLK_DIV,
WM9713_PCMDIV(wm9713_div));
if (ret < 0)
return ret;
return 0;
}
示例10: snd_format_alloc
static struct snd_format*
snd_format_alloc(int rate, int channels) {
struct snd_format* f = malloc(sizeof(struct snd_format));
f->format = SND_PCM_FORMAT_S16_BE;
f->rate = rate;
f->channels = channels;
f->sample_bits = snd_pcm_format_physical_width(f->format);
f->bps = (rate * f->sample_bits * channels) >> 3;
return f;
}
示例11: snd_rpi_iqaudio_dac_hw_params
static int snd_rpi_iqaudio_dac_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params)
{
struct snd_soc_pcm_runtime *rtd = substream->private_data;
// NOT USED struct snd_soc_dai *codec_dai = rtd->codec_dai;
// NOT USED struct snd_soc_codec *codec = rtd->codec;
struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
unsigned int sample_bits =
snd_pcm_format_physical_width(params_format(params));
return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
}
示例12: set_params
static void set_params(void)
{
hwparams.format=SND_PCM_FORMAT_S16_LE;
hwparams.channels=2;
hwparams.rate=44100;
snd_pcm_hw_params_t *params;
snd_pcm_sw_params_t *swparams;
snd_pcm_hw_params_alloca(¶ms);
snd_pcm_sw_params_alloca(&swparams);
snd_pcm_hw_params_any(handle, params);
snd_pcm_hw_params_set_format(handle, params, hwparams.format);
snd_pcm_hw_params_set_channels(handle, params, hwparams.channels);
snd_pcm_hw_params_set_rate_near(handle, params, &hwparams.rate, 0);
buffer_time=0;
snd_pcm_hw_params_get_buffer_time_max(params,&buffer_time, 0);
period_time=125000;
snd_pcm_hw_params_set_period_time_near(handle, params,&period_time, 0);
buffer_time = 500000;
snd_pcm_hw_params_set_buffer_time_near(handle, params, &buffer_time, 0);
/*monotonic = */snd_pcm_hw_params_is_monotonic(params);
/*can_pause = */snd_pcm_hw_params_can_pause(params);
printf("sizeof(params) : %d\n",sizeof(params));
snd_pcm_hw_params(handle, params);
snd_pcm_uframes_t buffer_size;
snd_pcm_hw_params_get_period_size(params, &chunk_size, 0);
size_t n=chunk_size;
snd_pcm_sw_params_set_avail_min(handle, swparams, n);
snd_pcm_uframes_t start_threshold, stop_threshold;
start_threshold=22050;
snd_pcm_sw_params_set_start_threshold(handle, swparams, start_threshold);
stop_threshold=22050;
snd_pcm_sw_params_set_stop_threshold(handle, swparams, stop_threshold);
snd_pcm_format_physical_width(hwparams.format);
}
示例13: snd_pcm_plugin_alloc
static int snd_pcm_plugin_alloc(snd_pcm_plugin_t *plugin, snd_pcm_uframes_t frames)
{
snd_pcm_plugin_format_t *format;
ssize_t width;
size_t size;
unsigned int channel;
snd_pcm_plugin_channel_t *c;
if (plugin->stream == SNDRV_PCM_STREAM_PLAYBACK) {
format = &plugin->src_format;
} else {
format = &plugin->dst_format;
}
if ((width = snd_pcm_format_physical_width(format->format)) < 0)
return width;
size = frames * format->channels * width;
snd_assert((size % 8) == 0, return -ENXIO);
size /= 8;
if (plugin->buf_frames < frames) {
if (plugin->buf)
vfree(plugin->buf);
plugin->buf = vmalloc(size);
plugin->buf_frames = frames;
}
if (!plugin->buf) {
plugin->buf_frames = 0;
return -ENOMEM;
}
c = plugin->buf_channels;
if (plugin->access == SNDRV_PCM_ACCESS_RW_INTERLEAVED) {
for (channel = 0; channel < format->channels; channel++, c++) {
c->frames = frames;
c->enabled = 1;
c->wanted = 0;
c->area.addr = plugin->buf;
c->area.first = channel * width;
c->area.step = format->channels * width;
}
} else if (plugin->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
snd_assert((size % format->channels) == 0,);
size /= format->channels;
for (channel = 0; channel < format->channels; channel++, c++) {
c->frames = frames;
c->enabled = 1;
c->wanted = 0;
c->area.addr = plugin->buf + (channel * size);
c->area.first = 0;
c->area.step = width;
}
} else
示例14: omap_pcm_limit_supported_formats
/* sDMA supports only 1, 2, and 4 byte transfer elements. */
static void omap_pcm_limit_supported_formats(void)
{
int i;
for (i = 0; i < SNDRV_PCM_FORMAT_LAST; i++) {
switch (snd_pcm_format_physical_width(i)) {
case 8:
case 16:
case 32:
omap_pcm_hardware.formats |= (1LL << i);
break;
default:
break;
}
}
}
示例15: playpaq_wm8510_calc_ssc_clock
static struct ssc_clock_data playpaq_wm8510_calc_ssc_clock(
struct snd_pcm_hw_params *params,
struct snd_soc_dai *cpu_dai)
{
struct at32_ssc_info *ssc_p = snd_soc_dai_get_drvdata(cpu_dai);
struct ssc_device *ssc = ssc_p->ssc;
struct ssc_clock_data cd;
unsigned int rate, width_bits, channels;
unsigned int bitrate, ssc_div;
unsigned actual_rate;
/*
* Figure out required bitrate
*/
rate = params_rate(params);
channels = params_channels(params);
width_bits = snd_pcm_format_physical_width(params_format(params));
bitrate = rate * width_bits * channels;
/*
* Figure out required SSC divider and period for required bitrate
*/
cd.ssc_rate = clk_get_rate(ssc->clk);
ssc_div = cd.ssc_rate / bitrate;
cd.cmr_div = ssc_div / 2;
if (ssc_div & 1) {
/* round cmr_div up */
cd.cmr_div++;
}
cd.period = width_bits - 1;
/*
* Find actual rate, compare to requested rate
*/
actual_rate = (cd.ssc_rate / (cd.cmr_div * 2)) / (2 * (cd.period + 1));
pr_debug("playpaq_wm8510: Request rate = %u, actual rate = %u\n",
rate, actual_rate);
return cd;
}