Add support for monotonic timestamps
authorJaroslav Kysela <perex@perex.cz>
Wed, 9 Jan 2008 10:13:34 +0000 (11:13 +0100)
committerJaroslav Kysela <perex@perex.cz>
Wed, 9 Jan 2008 10:13:34 +0000 (11:13 +0100)
28 files changed:
configure.in
include/pcm_ioplug.h
src/pcm/pcm_adpcm.c
src/pcm/pcm_alaw.c
src/pcm/pcm_copy.c
src/pcm/pcm_direct.h
src/pcm/pcm_dmix.c
src/pcm/pcm_dshare.c
src/pcm/pcm_dsnoop.c
src/pcm/pcm_file.c
src/pcm/pcm_hooks.c
src/pcm/pcm_hw.c
src/pcm/pcm_iec958.c
src/pcm/pcm_ioplug.c
src/pcm/pcm_ladspa.c
src/pcm/pcm_lfloat.c
src/pcm/pcm_linear.c
src/pcm/pcm_local.h
src/pcm/pcm_meter.c
src/pcm/pcm_mmap_emul.c
src/pcm/pcm_mulaw.c
src/pcm/pcm_multi.c
src/pcm/pcm_null.c
src/pcm/pcm_plug.c
src/pcm/pcm_rate.c
src/pcm/pcm_route.c
src/pcm/pcm_share.c
src/pcm/pcm_softvol.c

index 7060805..8d674fd 100644 (file)
@@ -241,6 +241,22 @@ else
   AC_MSG_RESULT(no)
 fi
 
+dnl Check for librt
+AC_MSG_CHECKING(for librt)
+AC_ARG_WITH(librt,
+  AS_HELP_STRING([--with-librt], [Use librt for monotonic clock (default = yes)]),
+  [ have_librt="$withval" ], [ have_librt="yes" ])
+if test "$have_librt" = "yes"; then
+  AC_CHECK_LIB([rt], [clock_gettime], [HAVE_LIBRT="yes"])
+  if test "$HAVE_LIBRT" = "yes" ; then
+    ALSA_DEPLIBS="$ALSA_DEPLIBS -lrt"
+    AC_DEFINE([HAVE_LIBRT], 1, [Have librt])
+    AC_DEFINE([HAVE_CLOCK_GETTIME], 1, [Have clock gettime])
+  fi
+else
+  AC_MSG_RESULT(no)
+fi
+
 AC_SUBST(ALSA_DEPLIBS)
 
 dnl Check for architecture
index f740a19..b5968f1 100644 (file)
@@ -59,6 +59,7 @@ typedef struct snd_pcm_ioplug_callback snd_pcm_ioplug_callback_t;
  * bit flags for additional conditions
  */
 #define SND_PCM_IOPLUG_FLAG_LISTED     (1<<0)          /* list up this PCM */
+#define SND_PCM_IOPLUG_FLAG_MONOTONIC  (1<<1)          /* monotonic timestamps */
 
 /*
  * Protocol version
index 270c900..4f9c46b 100644 (file)
@@ -576,6 +576,7 @@ int snd_pcm_adpcm_open(snd_pcm_t **pcmp, const char *name, snd_pcm_format_t sfor
        pcm->private_data = adpcm;
        pcm->poll_fd = slave->poll_fd;
        pcm->poll_events = slave->poll_events;
+       pcm->monotonic = slave->monotonic;
        snd_pcm_set_hw_ptr(pcm, &adpcm->plug.hw_ptr, -1, 0);
        snd_pcm_set_appl_ptr(pcm, &adpcm->plug.appl_ptr, -1, 0);
        *pcmp = pcm;
index 767e69f..3814241 100644 (file)
@@ -450,6 +450,7 @@ int snd_pcm_alaw_open(snd_pcm_t **pcmp, const char *name, snd_pcm_format_t sform
        pcm->private_data = alaw;
        pcm->poll_fd = slave->poll_fd;
        pcm->poll_events = slave->poll_events;
+       pcm->monotonic = slave->monotonic;
        snd_pcm_set_hw_ptr(pcm, &alaw->plug.hw_ptr, -1, 0);
        snd_pcm_set_appl_ptr(pcm, &alaw->plug.appl_ptr, -1, 0);
        *pcmp = pcm;
index b1525bf..9d3eb38 100644 (file)
@@ -206,6 +206,7 @@ int snd_pcm_copy_open(snd_pcm_t **pcmp, const char *name, snd_pcm_t *slave, int
        pcm->private_data = copy;
        pcm->poll_fd = slave->poll_fd;
        pcm->poll_events = slave->poll_events;
+       pcm->monotonic = slave->monotonic;
        snd_pcm_set_hw_ptr(pcm, &copy->plug.hw_ptr, -1, 0);
        snd_pcm_set_appl_ptr(pcm, &copy->plug.appl_ptr, -1, 0);
        *pcmp = pcm;
index d5f60e5..803329e 100644 (file)
@@ -85,7 +85,7 @@ typedef struct {
                unsigned int period_size;
                unsigned int period_time;
                snd_interval_t periods;
-               unsigned int tick_time; /* not used */
+               unsigned int monotonic;
                snd_pcm_tstamp_t tstamp_mode;
                unsigned int period_step;
                unsigned int sleep_min; /* not used */
index b9fb1c7..9ea6e87 100644 (file)
@@ -333,7 +333,7 @@ static int snd_pcm_dmix_sync_ptr(snd_pcm_t *pcm)
                dmix->avail_max = avail;
        if (avail >= pcm->stop_threshold) {
                snd_timer_stop(dmix->timer);
-               gettimestamp(&dmix->trigger_tstamp);
+               gettimestamp(&dmix->trigger_tstamp, pcm->monotonic);
                if (dmix->state == SND_PCM_STATE_RUNNING) {
                        dmix->state = SND_PCM_STATE_XRUN;
                        return -EPIPE;
@@ -385,7 +385,7 @@ static int snd_pcm_dmix_status(snd_pcm_t *pcm, snd_pcm_status_t * status)
        if (pcm->tstamp_mode == SND_PCM_TSTAMP_MMAP)
                status->tstamp = snd_pcm_hw_fast_tstamp(dmix->spcm);
        else
-               gettimestamp(&status->tstamp);
+               gettimestamp(&status->tstamp, pcm->monotonic);
        status->avail = snd_pcm_mmap_playback_avail(pcm);
        status->avail_max = status->avail > dmix->avail_max ? status->avail : dmix->avail_max;
        dmix->avail_max = 0;
@@ -504,7 +504,7 @@ static int snd_pcm_dmix_start(snd_pcm_t *pcm)
                        return err;
                snd_pcm_dmix_sync_area(pcm);
        }
-       gettimestamp(&dmix->trigger_tstamp);
+       gettimestamp(&dmix->trigger_tstamp, pcm->monotonic);
        return 0;
 }
 
index 44417ea..301bc03 100644 (file)
@@ -195,7 +195,7 @@ static int snd_pcm_dshare_sync_ptr(snd_pcm_t *pcm)
                dshare->avail_max = avail;
        if (avail >= pcm->stop_threshold) {
                snd_timer_stop(dshare->timer);
-               gettimestamp(&dshare->trigger_tstamp);
+               gettimestamp(&dshare->trigger_tstamp, pcm->monotonic);
                if (dshare->state == SND_PCM_STATE_RUNNING) {
                        dshare->state = SND_PCM_STATE_XRUN;
                        return -EPIPE;
@@ -229,7 +229,7 @@ static int snd_pcm_dshare_status(snd_pcm_t *pcm, snd_pcm_status_t * status)
        if (pcm->tstamp_mode == SND_PCM_TSTAMP_MMAP)
                status->tstamp = snd_pcm_hw_fast_tstamp(dshare->spcm);
        else
-               gettimestamp(&status->tstamp);
+               gettimestamp(&status->tstamp, pcm->monotonic);
        status->avail = snd_pcm_mmap_playback_avail(pcm);
        status->avail_max = status->avail > dshare->avail_max ? status->avail : dshare->avail_max;
        dshare->avail_max = 0;
@@ -349,7 +349,7 @@ static int snd_pcm_dshare_start(snd_pcm_t *pcm)
                        return err;
                snd_pcm_dshare_sync_area(pcm);
        }
-       gettimestamp(&dshare->trigger_tstamp);
+       gettimestamp(&dshare->trigger_tstamp, pcm->monotonic);
        return 0;
 }
 
index b704165..6add132 100644 (file)
@@ -141,7 +141,7 @@ static int snd_pcm_dsnoop_sync_ptr(snd_pcm_t *pcm)
        if (pcm->stop_threshold >= pcm->boundary)       /* don't care */
                return 0;
        if ((avail = snd_pcm_mmap_capture_hw_avail(pcm)) >= pcm->stop_threshold) {
-               gettimestamp(&dsnoop->trigger_tstamp);
+               gettimestamp(&dsnoop->trigger_tstamp, pcm->monotonic);
                dsnoop->state = SND_PCM_STATE_XRUN;
                dsnoop->avail_max = avail;
                return -EPIPE;
@@ -175,7 +175,7 @@ static int snd_pcm_dsnoop_status(snd_pcm_t *pcm, snd_pcm_status_t * status)
        if (pcm->tstamp_mode == SND_PCM_TSTAMP_MMAP)
                status->tstamp = snd_pcm_hw_fast_tstamp(dsnoop->spcm);
        else
-               gettimestamp(&status->tstamp);
+               gettimestamp(&status->tstamp, pcm->monotonic);
        status->avail = snd_pcm_mmap_capture_avail(pcm);
        status->avail_max = status->avail > dsnoop->avail_max ? status->avail : dsnoop->avail_max;
        dsnoop->avail_max = 0;
@@ -274,7 +274,7 @@ static int snd_pcm_dsnoop_start(snd_pcm_t *pcm)
        if (err < 0)
                return err;
        dsnoop->state = SND_PCM_STATE_RUNNING;
-       gettimestamp(&dsnoop->trigger_tstamp);
+       gettimestamp(&dsnoop->trigger_tstamp, pcm->monotonic);
        return 0;
 }
 
index 9a53d53..89f8b75 100644 (file)
@@ -467,6 +467,7 @@ int snd_pcm_file_open(snd_pcm_t **pcmp, const char *name,
        pcm->poll_fd = slave->poll_fd;
        pcm->poll_events = slave->poll_events;
        pcm->mmap_shadow = 1;
+       pcm->monotonic = 1;
        snd_pcm_link_hw_ptr(pcm, slave);
        snd_pcm_link_appl_ptr(pcm, slave);
        *pcmp = pcm;
index 93827fa..99b3248 100644 (file)
@@ -201,6 +201,7 @@ int snd_pcm_hooks_open(snd_pcm_t **pcmp, const char *name, snd_pcm_t *slave, int
        pcm->poll_fd = slave->poll_fd;
        pcm->poll_events = slave->poll_events;
        pcm->mmap_shadow = 1;
+       pcm->monotonic = slave->monotonic;
        snd_pcm_link_hw_ptr(pcm, slave);
        snd_pcm_link_appl_ptr(pcm, slave);
        *pcmp = pcm;
index e7bb440..bcbdfd5 100644 (file)
@@ -923,9 +923,8 @@ int snd_pcm_hw_open_fd(snd_pcm_t **pcmp, const char *name,
                       int fd, int mmap_emulation ATTRIBUTE_UNUSED,
                       int sync_ptr_ioctl)
 {
-       int ver;
+       int ver, mode, monotonic = 0;
        long fmode;
-       int mode;
        snd_pcm_t *pcm = NULL;
        snd_pcm_hw_t *hw = NULL;
        snd_pcm_info_t info;
@@ -980,8 +979,19 @@ int snd_pcm_hw_open_fd(snd_pcm_t **pcmp, const char *name,
                        ret = -errno;
                        SNDMSG("TSTAMP failed\n");
                        return ret;
-               }                       
+               }
+       }
+#ifdef HAVE_CLOCK_GETTIME
+         else if (SNDRV_PROTOCOL_VERSION(2, 0, 9) >= ver) {
+               int on = SNDRV_PCM_TSTAMP_TYPE_MONOTONIC;
+               if (ioctl(fd, SNDRV_PCM_IOCTL_TTSTAMP, &on) < 0) {
+                       ret = -errno;
+                       SNDMSG("TTSTAMP failed\n");
+                       return ret;
+               }
+               monotonic = 1;
        }
+#endif
        
        hw = calloc(1, sizeof(snd_pcm_hw_t));
        if (!hw) {
@@ -1012,6 +1022,7 @@ int snd_pcm_hw_open_fd(snd_pcm_t **pcmp, const char *name,
        pcm->private_data = hw;
        pcm->poll_fd = fd;
        pcm->poll_events = info.stream == SND_PCM_STREAM_PLAYBACK ? POLLOUT : POLLIN;
+       pcm->monotonic = monotonic;
 
        ret = snd_pcm_hw_mmap_status(pcm);
        if (ret < 0) {
index 79d611d..f0990d2 100644 (file)
@@ -496,6 +496,7 @@ int snd_pcm_iec958_open(snd_pcm_t **pcmp, const char *name, snd_pcm_format_t sfo
        pcm->private_data = iec;
        pcm->poll_fd = slave->poll_fd;
        pcm->poll_events = slave->poll_events;
+       pcm->monotonic = slave->monotonic;
        snd_pcm_set_hw_ptr(pcm, &iec->plug.hw_ptr, -1, 0);
        snd_pcm_set_appl_ptr(pcm, &iec->plug.appl_ptr, -1, 0);
        *pcmp = pcm;
index 7bf19ca..19b97d1 100644 (file)
@@ -447,7 +447,7 @@ static int snd_pcm_ioplug_start(snd_pcm_t *pcm)
        if (err < 0)
                return err;
 
-       gettimestamp(&io->trigger_tstamp);
+       gettimestamp(&io->trigger_tstamp, pcm->monotonic);
        io->data->state = SND_PCM_STATE_RUNNING;
 
        return 0;
@@ -462,7 +462,7 @@ static int snd_pcm_ioplug_drop(snd_pcm_t *pcm)
 
        io->data->callback->stop(io->data);
 
-       gettimestamp(&io->trigger_tstamp);
+       gettimestamp(&io->trigger_tstamp, pcm->monotonic);
        io->data->state = SND_PCM_STATE_SETUP;
 
        return 0;
@@ -1021,6 +1021,7 @@ int snd_pcm_ioplug_reinit_status(snd_pcm_ioplug_t *ioplug)
 {
        ioplug->pcm->poll_fd = ioplug->poll_fd;
        ioplug->pcm->poll_events = ioplug->poll_events;
+       ioplug->pcm->monotonic = (ioplug->flags & SND_PCM_IOPLUG_FLAG_MONOTONIC) != 0;
        ioplug->pcm->mmap_rw = ioplug->mmap_rw;
        return 0;
 }
index 4cf8b8f..97bb901 100644 (file)
@@ -1634,6 +1634,7 @@ int snd_pcm_ladspa_open(snd_pcm_t **pcmp, const char *name,
        pcm->private_data = ladspa;
        pcm->poll_fd = slave->poll_fd;
        pcm->poll_events = slave->poll_events;
+       pcm->monotonic = slave->monotonic;
        snd_pcm_set_hw_ptr(pcm, &ladspa->plug.hw_ptr, -1, 0);
        snd_pcm_set_appl_ptr(pcm, &ladspa->plug.appl_ptr, -1, 0);
        *pcmp = pcm;
index 3180d4f..883fce9 100644 (file)
@@ -409,6 +409,7 @@ int snd_pcm_lfloat_open(snd_pcm_t **pcmp, const char *name, snd_pcm_format_t sfo
        pcm->private_data = lfloat;
        pcm->poll_fd = slave->poll_fd;
        pcm->poll_events = slave->poll_events;
+       pcm->monotonic = slave->monotonic;
        snd_pcm_set_hw_ptr(pcm, &lfloat->plug.hw_ptr, -1, 0);
        snd_pcm_set_appl_ptr(pcm, &lfloat->plug.appl_ptr, -1, 0);
        *pcmp = pcm;
index 6fc222c..e3aeac1 100644 (file)
@@ -466,6 +466,7 @@ int snd_pcm_linear_open(snd_pcm_t **pcmp, const char *name, snd_pcm_format_t sfo
        pcm->private_data = linear;
        pcm->poll_fd = slave->poll_fd;
        pcm->poll_events = slave->poll_events;
+       pcm->monotonic = slave->monotonic;
        snd_pcm_set_hw_ptr(pcm, &linear->plug.hw_ptr, -1, 0);
        snd_pcm_set_appl_ptr(pcm, &linear->plug.appl_ptr, -1, 0);
        *pcmp = pcm;
index 0b9c09b..0954aee 100644 (file)
@@ -177,7 +177,8 @@ struct _snd_pcm {
        int poll_fd_count;
        int poll_fd;
        unsigned short poll_events;
-       int setup;
+       int setup: 1,
+           monotonic: 1;
        snd_pcm_access_t access;        /* access mode */
        snd_pcm_format_t format;        /* SND_PCM_FORMAT_* */
        snd_pcm_subformat_t subformat;  /* subformat */
@@ -940,11 +941,15 @@ typedef union snd_tmp_double {
 } snd_tmp_double_t;
 
 /* get the current timestamp */
-static inline void gettimestamp(snd_htimestamp_t *tstamp)
+static inline void gettimestamp(snd_htimestamp_t *tstamp, int monotonic)
 {
-       struct timeval tv;
-
-       gettimeofday(&tv, 0);
-       tstamp->tv_sec = tv.tv_sec;
-       tstamp->tv_nsec = tv.tv_usec * 1000L;
+       if (monotonic) {
+               clock_gettime(CLOCK_MONOTONIC, tstamp);
+       } else {
+               struct timeval tv;
+
+               gettimeofday(&tv, 0);
+               tstamp->tv_sec = tv.tv_sec;
+               tstamp->tv_nsec = tv.tv_usec * 1000L;
+       }
 }
index 85ac7f8..24d08ac 100644 (file)
@@ -581,6 +581,7 @@ int snd_pcm_meter_open(snd_pcm_t **pcmp, const char *name, unsigned int frequenc
        pcm->private_data = meter;
        pcm->poll_fd = slave->poll_fd;
        pcm->poll_events = slave->poll_events;
+       pcm->monotonic = slave->monotonic;
        snd_pcm_link_hw_ptr(pcm, slave);
        snd_pcm_link_appl_ptr(pcm, slave);
        *pcmp = pcm;
index d3fe05e..29bbfa4 100644 (file)
@@ -399,6 +399,7 @@ static int snd_pcm_mmap_emul_open(snd_pcm_t **pcmp, const char *name,
        pcm->private_data = map;
        pcm->poll_fd = slave->poll_fd;
        pcm->poll_events = slave->poll_events;
+       pcm->monotonic = slave->monotonic;
        snd_pcm_set_hw_ptr(pcm, &map->hw_ptr, -1, 0);
        snd_pcm_set_appl_ptr(pcm, &map->appl_ptr, -1, 0);
        *pcmp = pcm;
index 389326b..d696c96 100644 (file)
@@ -465,6 +465,7 @@ int snd_pcm_mulaw_open(snd_pcm_t **pcmp, const char *name, snd_pcm_format_t sfor
        pcm->private_data = mulaw;
        pcm->poll_fd = slave->poll_fd;
        pcm->poll_events = slave->poll_events;
+       pcm->monotonic = slave->monotonic;
        snd_pcm_set_hw_ptr(pcm, &mulaw->plug.hw_ptr, -1, 0);
        snd_pcm_set_appl_ptr(pcm, &mulaw->plug.appl_ptr, -1, 0);
        *pcmp = pcm;
index dfd679c..c2db21e 100644 (file)
@@ -887,6 +887,7 @@ int snd_pcm_multi_open(snd_pcm_t **pcmp, const char *name,
        pcm->private_data = multi;
        pcm->poll_fd = multi->slaves[master_slave].pcm->poll_fd;
        pcm->poll_events = multi->slaves[master_slave].pcm->poll_events;
+       pcm->monotonic = multi->slaves[master_slave].pcm->monotonic;
        snd_pcm_link_hw_ptr(pcm, multi->slaves[master_slave].pcm);
        snd_pcm_link_appl_ptr(pcm, multi->slaves[master_slave].pcm);
        *pcmp = pcm;
index 742f231..5b48cb1 100644 (file)
@@ -85,7 +85,7 @@ static int snd_pcm_null_status(snd_pcm_t *pcm, snd_pcm_status_t * status)
        memset(status, 0, sizeof(*status));
        status->state = null->state;
        status->trigger_tstamp = null->trigger_tstamp;
-       gettimestamp(&status->tstamp);
+       gettimestamp(&status->tstamp, pcm->monotonic);
        status->avail = pcm->buffer_size;
        status->avail_max = status->avail;
        return 0;
index 87917c4..0c2ff6e 100644 (file)
@@ -1054,6 +1054,7 @@ int snd_pcm_plug_open(snd_pcm_t **pcmp,
        pcm->poll_fd = slave->poll_fd;
        pcm->poll_events = slave->poll_events;
        pcm->mmap_shadow = 1;
+       pcm->monotonic = slave->monotonic;
        snd_pcm_link_hw_ptr(pcm, slave);
        snd_pcm_link_appl_ptr(pcm, slave);
        *pcmp = pcm;
index c5bded4..2487bd1 100644 (file)
@@ -1093,7 +1093,7 @@ static int snd_pcm_rate_start(snd_pcm_t *pcm)
        if (snd_pcm_state(rate->gen.slave) != SND_PCM_STATE_PREPARED)
                return -EBADFD;
 
-       gettimestamp(&rate->trigger_tstamp);
+       gettimestamp(&rate->trigger_tstamp, pcm->monotonic);
 
        avail = snd_pcm_mmap_playback_hw_avail(rate->gen.slave);
        if (avail == 0) {
@@ -1366,6 +1366,7 @@ int snd_pcm_rate_open(snd_pcm_t **pcmp, const char *name,
        pcm->poll_fd = slave->poll_fd;
        pcm->poll_events = slave->poll_events;
        pcm->mmap_rw = 1;
+       pcm->monotonic = slave->monotonic;
        snd_pcm_set_hw_ptr(pcm, &rate->hw_ptr, -1, 0);
        snd_pcm_set_appl_ptr(pcm, &rate->appl_ptr, -1, 0);
        *pcmp = pcm;
index e49bdef..6991fb1 100644 (file)
@@ -886,6 +886,7 @@ int snd_pcm_route_open(snd_pcm_t **pcmp, const char *name,
        pcm->private_data = route;
        pcm->poll_fd = slave->poll_fd;
        pcm->poll_events = slave->poll_events;
+       pcm->monotonic = slave->monotonic;
        snd_pcm_set_hw_ptr(pcm, &route->plug.hw_ptr, -1, 0);
        snd_pcm_set_appl_ptr(pcm, &route->plug.appl_ptr, -1, 0);
        err = route_load_ttable(&route->params, pcm->stream, tt_ssize, ttable, tt_cused, tt_sused);
index 83a84cf..b4e0467 100644 (file)
@@ -962,7 +962,7 @@ static int snd_pcm_share_start(snd_pcm_t *pcm)
        }
        slave->running_count++;
        _snd_pcm_share_update(pcm);
-       gettimestamp(&share->trigger_tstamp);
+       gettimestamp(&share->trigger_tstamp, pcm->monotonic);
  _end:
        Pthread_mutex_unlock(&slave->mutex);
        return err;
@@ -1095,7 +1095,7 @@ static void _snd_pcm_share_stop(snd_pcm_t *pcm, snd_pcm_state_t state)
                return;
        }
 #endif
-       gettimestamp(&share->trigger_tstamp);
+       gettimestamp(&share->trigger_tstamp, pcm->monotonic);
        if (pcm->stream == SND_PCM_STREAM_CAPTURE) {
                snd_pcm_areas_copy(pcm->stopped_areas, 0,
                                   pcm->running_areas, 0,
@@ -1492,6 +1492,7 @@ int snd_pcm_share_open(snd_pcm_t **pcmp, const char *name, const char *sname,
        pcm->private_data = share;
        pcm->poll_fd = share->client_socket;
        pcm->poll_events = stream == SND_PCM_STREAM_PLAYBACK ? POLLOUT : POLLIN;
+       pcm->monotonic = pcm->monotonic;
        snd_pcm_set_hw_ptr(pcm, &share->hw_ptr, -1, 0);
        snd_pcm_set_appl_ptr(pcm, &share->appl_ptr, -1, 0);
 
index 45dae53..8f91204 100644 (file)
@@ -814,6 +814,7 @@ int snd_pcm_softvol_open(snd_pcm_t **pcmp, const char *name,
         * an extra buffer.
         */
        pcm->mmap_shadow = 1;
+       pcm->monotonic = slave->monotonic;
        snd_pcm_set_hw_ptr(pcm, &svol->plug.hw_ptr, -1, 0);
        snd_pcm_set_appl_ptr(pcm, &svol->plug.appl_ptr, -1, 0);
        *pcmp = pcm;