/* mono control */ static void softvol_convert_mono_vol(snd_pcm_softvol_t *svol, const snd_pcm_channel_area_t *dst_areas, snd_pcm_uframes_t dst_offset, const snd_pcm_channel_area_t *src_areas, snd_pcm_uframes_t src_offset, unsigned int channels, snd_pcm_uframes_t frames) { const snd_pcm_channel_area_t *dst_area, *src_area; unsigned int src_step, dst_step; unsigned int vol_scale; if (svol->cur_vol[0] == 0) { snd_pcm_areas_silence(dst_areas, dst_offset, channels, frames, svol->sformat); return; } else if (svol->cur_vol[0] == svol->max_val) { snd_pcm_areas_copy(dst_areas, dst_offset, src_areas, src_offset, channels, frames, svol->sformat); return; } vol_scale = svol->dB_value[svol->cur_vol[0]]; if (svol->sformat == SND_PCM_FORMAT_S16) { /* 16bit samples */ CONVERT_AREA(short); } else { /* 32bit samples */ CONVERT_AREA(int); } }
static void snd_pcm_file_add_frames(snd_pcm_t *pcm, const snd_pcm_channel_area_t *areas, snd_pcm_uframes_t offset, snd_pcm_uframes_t frames) { snd_pcm_file_t *file = pcm->private_data; while (frames > 0) { snd_pcm_uframes_t n = frames; snd_pcm_uframes_t cont = file->wbuf_size - file->appl_ptr; snd_pcm_uframes_t avail = file->wbuf_size - snd_pcm_bytes_to_frames(pcm, file->wbuf_used_bytes); if (n > cont) n = cont; if (n > avail) n = avail; snd_pcm_areas_copy(file->wbuf_areas, file->appl_ptr, areas, offset, pcm->channels, n, pcm->format); frames -= n; offset += n; file->appl_ptr += n; if (file->appl_ptr == file->wbuf_size) file->appl_ptr = 0; file->wbuf_used_bytes += snd_pcm_frames_to_bytes(pcm, n); if (file->wbuf_used_bytes > file->buffer_bytes) snd_pcm_file_write_bytes(pcm, file->wbuf_used_bytes - file->buffer_bytes); assert(file->wbuf_used_bytes < file->wbuf_size_bytes); } }
static snd_pcm_sframes_t snd_pcm_mmap_read_areas(snd_pcm_t *pcm, const snd_pcm_channel_area_t *areas, snd_pcm_uframes_t offset, snd_pcm_uframes_t size) { snd_pcm_uframes_t xfer = 0; if (snd_pcm_mmap_capture_avail(pcm) < size) { SNDMSG("too short avail %ld to size %ld", snd_pcm_mmap_capture_avail(pcm), size); return -EPIPE; } while (size > 0) { const snd_pcm_channel_area_t *pcm_areas; snd_pcm_uframes_t pcm_offset; snd_pcm_uframes_t frames = size; snd_pcm_sframes_t result; snd_pcm_mmap_begin(pcm, &pcm_areas, &pcm_offset, &frames); snd_pcm_areas_copy(areas, offset, pcm_areas, pcm_offset, pcm->channels, frames, pcm->format); result = snd_pcm_mmap_commit(pcm, pcm_offset, frames); if (result < 0) return xfer > 0 ? (snd_pcm_sframes_t)xfer : result; offset += result; xfer += result; size -= result; } return (snd_pcm_sframes_t)xfer; }