aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRicardo Biehl Pasquali <pasqualirb@gmail.com>2018-12-24 18:34:48 -0200
committerRicardo Biehl Pasquali <pasqualirb@gmail.com>2019-01-08 16:48:19 -0200
commitb8ea4c4b0c3da305d97bdf297520b9ace0346281 (patch)
tree57f76e090bc4eca4f781e036c4e3b7e0c17f963c
parent297d24b7eb264f1fad464c15e4298f714452877e (diff)
pcm: Put transfer functions together
A generic transfer function will be created. Put together functions related to it. Signed-off-by: Ricardo Biehl Pasquali <pasqualirb@gmail.com>
-rw-r--r--src/pcm.c246
1 files changed, 122 insertions, 124 deletions
diff --git a/src/pcm.c b/src/pcm.c
index f49be90..d20a954 100644
--- a/src/pcm.c
+++ b/src/pcm.c
@@ -585,130 +585,6 @@ static void pcm_hw_munmap_status(struct pcm *pcm) {
pcm->mmap_control = NULL;
}
-/** Writes audio samples to PCM.
- * If the PCM has not been started, it is started in this function.
- * This function is only valid for PCMs opened with the @ref PCM_OUT flag.
- * This function is not valid for PCMs opened with the @ref PCM_MMAP flag.
- * @param pcm A PCM handle.
- * @param data The audio sample array
- * @param frame_count The number of frames occupied by the sample array.
- * This value should not be greater than @ref TINYALSA_FRAMES_MAX
- * or INT_MAX.
- * @return On success, this function returns the number of frames written; otherwise, a negative number.
- * @ingroup libtinyalsa-pcm
- */
-int pcm_writei(struct pcm *pcm, const void *data, unsigned int frame_count)
-{
- struct snd_xferi x;
-
- if (pcm->flags & PCM_IN)
- return -EINVAL;
-#if UINT_MAX > TINYALSA_FRAMES_MAX
- if (frame_count > TINYALSA_FRAMES_MAX)
- return -EINVAL;
-#endif
- if (frame_count > INT_MAX)
- return -EINVAL;
-
- x.buf = (void*)data;
- x.frames = frame_count;
- x.result = 0;
- for (;;) {
- if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_WRITEI_FRAMES, &x)) {
- if (errno == EPIPE) {
- /* we failed to make our window -- try to restart if we are
- * allowed to do so. Otherwise, simply allow the EPIPE error to
- * propagate up to the app level */
- pcm->underruns++;
- if (pcm->flags & PCM_NORESTART)
- return -EPIPE;
- if (pcm_prepare(pcm))
- return -EPIPE;
- continue;
- }
- return oops(pcm, errno, "cannot write stream data");
- }
- return x.result;
- }
-}
-
-/** Reads audio samples from PCM.
- * If the PCM has not been started, it is started in this function.
- * This function is only valid for PCMs opened with the @ref PCM_IN flag.
- * This function is not valid for PCMs opened with the @ref PCM_MMAP flag.
- * @param pcm A PCM handle.
- * @param data The audio sample array
- * @param frame_count The number of frames occupied by the sample array.
- * This value should not be greater than @ref TINYALSA_FRAMES_MAX
- * or INT_MAX.
- * @return On success, this function returns the number of frames written; otherwise, a negative number.
- * @ingroup libtinyalsa-pcm
- */
-int pcm_readi(struct pcm *pcm, void *data, unsigned int frame_count)
-{
- struct snd_xferi x;
-
- if (!(pcm->flags & PCM_IN))
- return -EINVAL;
-#if UINT_MAX > TINYALSA_FRAMES_MAX
- if (frame_count > TINYALSA_FRAMES_MAX)
- return -EINVAL;
-#endif
- if (frame_count > INT_MAX)
- return -EINVAL;
-
- x.buf = data;
- x.frames = frame_count;
- x.result = 0;
- for (;;) {
- if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_READI_FRAMES, &x)) {
- if (errno == EPIPE) {
- /* we failed to make our window -- try to restart */
- pcm->underruns++;
- if (pcm->flags & PCM_NORESTART)
- return -EPIPE;
- if (pcm_prepare(pcm))
- return -EPIPE;
- continue;
- }
- return oops(pcm, errno, "cannot read stream data");
- }
- return x.result;
- }
-}
-
-/** Writes audio samples to PCM.
- * If the PCM has not been started, it is started in this function.
- * This function is only valid for PCMs opened with the @ref PCM_OUT flag.
- * This function is not valid for PCMs opened with the @ref PCM_MMAP flag.
- * @param pcm A PCM handle.
- * @param data The audio sample array
- * @param count The number of bytes occupied by the sample array.
- * @return On success, this function returns zero; otherwise, a negative number.
- * @deprecated
- * @ingroup libtinyalsa-pcm
- */
-int pcm_write(struct pcm *pcm, const void *data, unsigned int count)
-{
- return pcm_writei(pcm, data, pcm_bytes_to_frames(pcm, count));
-}
-
-/** Reads audio samples from PCM.
- * If the PCM has not been started, it is started in this function.
- * This function is only valid for PCMs opened with the @ref PCM_IN flag.
- * This function is not valid for PCMs opened with the @ref PCM_MMAP flag.
- * @param pcm A PCM handle.
- * @param data The audio sample array
- * @param count The number of bytes occupied by the sample array.
- * @return On success, this function returns zero; otherwise, a negative number.
- * @deprecated
- * @ingroup libtinyalsa-pcm
- */
-int pcm_read(struct pcm *pcm, void *data, unsigned int count)
-{
- return pcm_readi(pcm, data, pcm_bytes_to_frames(pcm, count));
-}
-
static struct pcm bad_pcm = {
.fd = -1,
};
@@ -1481,6 +1357,128 @@ int pcm_mmap_read(struct pcm *pcm, void *data, unsigned int count)
return pcm_mmap_transfer(pcm, data, pcm_bytes_to_frames(pcm, count));
}
+/** Writes audio samples to PCM.
+ * If the PCM has not been started, it is started in this function.
+ * This function is only valid for PCMs opened with the @ref PCM_OUT flag.
+ * @param pcm A PCM handle.
+ * @param data The audio sample array
+ * @param frame_count The number of frames occupied by the sample array.
+ * This value should not be greater than @ref TINYALSA_FRAMES_MAX
+ * or INT_MAX.
+ * @return On success, this function returns the number of frames written; otherwise, a negative number.
+ * @ingroup libtinyalsa-pcm
+ */
+int pcm_writei(struct pcm *pcm, const void *data, unsigned int frame_count)
+{
+ struct snd_xferi x;
+
+ if (pcm->flags & PCM_IN)
+ return -EINVAL;
+#if UINT_MAX > TINYALSA_FRAMES_MAX
+ if (frame_count > TINYALSA_FRAMES_MAX)
+ return -EINVAL;
+#endif
+ if (frame_count > INT_MAX)
+ return -EINVAL;
+
+ x.buf = (void*)data;
+ x.frames = frame_count;
+ x.result = 0;
+ for (;;) {
+ if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_WRITEI_FRAMES, &x)) {
+ if (errno == EPIPE) {
+ /* we failed to make our window -- try to restart if we are
+ * allowed to do so. Otherwise, simply allow the EPIPE error to
+ * propagate up to the app level */
+ pcm->underruns++;
+ if (pcm->flags & PCM_NORESTART)
+ return -EPIPE;
+ if (pcm_prepare(pcm))
+ return -EPIPE;
+ continue;
+ }
+ return oops(pcm, errno, "cannot write stream data");
+ }
+ return x.result;
+ }
+}
+
+/** Reads audio samples from PCM.
+ * If the PCM has not been started, it is started in this function.
+ * This function is only valid for PCMs opened with the @ref PCM_IN flag.
+ * @param pcm A PCM handle.
+ * @param data The audio sample array
+ * @param frame_count The number of frames occupied by the sample array.
+ * This value should not be greater than @ref TINYALSA_FRAMES_MAX
+ * or INT_MAX.
+ * @return On success, this function returns the number of frames written; otherwise, a negative number.
+ * @ingroup libtinyalsa-pcm
+ */
+int pcm_readi(struct pcm *pcm, void *data, unsigned int frame_count)
+{
+ struct snd_xferi x;
+
+ if (!(pcm->flags & PCM_IN))
+ return -EINVAL;
+#if UINT_MAX > TINYALSA_FRAMES_MAX
+ if (frame_count > TINYALSA_FRAMES_MAX)
+ return -EINVAL;
+#endif
+ if (frame_count > INT_MAX)
+ return -EINVAL;
+
+ x.buf = data;
+ x.frames = frame_count;
+ x.result = 0;
+ for (;;) {
+ if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_READI_FRAMES, &x)) {
+ if (errno == EPIPE) {
+ /* we failed to make our window -- try to restart */
+ pcm->underruns++;
+ if (pcm->flags & PCM_NORESTART)
+ return -EPIPE;
+ if (pcm_prepare(pcm))
+ return -EPIPE;
+ continue;
+ }
+ return oops(pcm, errno, "cannot read stream data");
+ }
+ return x.result;
+ }
+}
+
+/** Writes audio samples to PCM.
+ * If the PCM has not been started, it is started in this function.
+ * This function is only valid for PCMs opened with the @ref PCM_OUT flag.
+ * This function is not valid for PCMs opened with the @ref PCM_MMAP flag.
+ * @param pcm A PCM handle.
+ * @param data The audio sample array
+ * @param count The number of bytes occupied by the sample array.
+ * @return On success, this function returns zero; otherwise, a negative number.
+ * @deprecated
+ * @ingroup libtinyalsa-pcm
+ */
+int pcm_write(struct pcm *pcm, const void *data, unsigned int count)
+{
+ return pcm_writei(pcm, data, pcm_bytes_to_frames(pcm, count));
+}
+
+/** Reads audio samples from PCM.
+ * If the PCM has not been started, it is started in this function.
+ * This function is only valid for PCMs opened with the @ref PCM_IN flag.
+ * This function is not valid for PCMs opened with the @ref PCM_MMAP flag.
+ * @param pcm A PCM handle.
+ * @param data The audio sample array
+ * @param count The number of bytes occupied by the sample array.
+ * @return On success, this function returns zero; otherwise, a negative number.
+ * @deprecated
+ * @ingroup libtinyalsa-pcm
+ */
+int pcm_read(struct pcm *pcm, void *data, unsigned int count)
+{
+ return pcm_readi(pcm, data, pcm_bytes_to_frames(pcm, count));
+}
+
/** Gets the delay of the PCM, in terms of frames.
* @param pcm A PCM handle.
* @returns On success, the delay of the PCM.