source: roaraudio/roard/driver_sysclock.c @ 4897:31fd5ff981e1

Last change on this file since 4897:31fd5ff981e1 was 4897:31fd5ff981e1, checked in by phi, 13 years ago

work around SYNC warning

File size: 3.1 KB
RevLine 
[4668]1//driver_sysclock.c:
[2208]2
3/*
[4708]4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2011
[2208]5 *
6 *  This file is part of roard a part of RoarAudio,
7 *  a cross-platform sound system for both, home and professional use.
8 *  See README for details.
9 *
10 *  This file is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License version 3
12 *  as published by the Free Software Foundation.
13 *
14 *  RoarAudio is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU General Public License for more details.
18 *
19 *  You should have received a copy of the GNU General Public License
20 *  along with this software; see the file COPYING.  If not, write to
[3517]21 *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
[2208]23 *
24 */
25
26#include "roard.h"
27
[2209]28#ifdef ROAR_HAVE_DRIVER_SYSCLOCK
[2367]29int driver_sysclock_open_vio(struct roar_vio_calls * inst, char * device, struct roar_audio_info * info, int fh, struct roar_stream_server * sstream) {
[2212]30 struct driver_sysclock * self = malloc(sizeof(struct driver_sysclock));
31
32 if ( self == NULL )
33  return -1;
[2208]34
35 if ( device != NULL ) {
36  return -1;
37 }
38
[2212]39 memset(self, 0, sizeof(struct driver_sysclock));
40 memset(inst, 0, sizeof(struct roar_vio_calls));
41
[4897]42 inst->inst     = self;
43 inst->close    = driver_sysclock_close;
44 inst->nonblock = driver_sysclock_nonblock;
45 inst->write    = driver_sysclock_write;
[2212]46
[4897]47 self->bps      = (info->bits / 8) * info->channels * info->rate;
[2212]48
[2213]49 if (!self->bps) {
[2212]50  free(self);
51  return -1;
52 }
53
54 switch (info->codec) {
55  case ROAR_CODEC_PCM_S_LE:
56  case ROAR_CODEC_PCM_S_BE:
57  case ROAR_CODEC_PCM_S_PDP:
58  case ROAR_CODEC_PCM_U_LE:
59  case ROAR_CODEC_PCM_U_BE:
60  case ROAR_CODEC_PCM_U_PDP:
61   break;
62  case ROAR_CODEC_ALAW:
63  case ROAR_CODEC_MULAW:
64    // one byte per sample
[2213]65    self->bps *= 8;
66    self->bps /= info->bits;
[2212]67   break;
68  default:
69    free(self);
70    return -1;
71   break;
72 }
73
74 gettimeofday(&(self->lasttime), NULL);
75
[2422]76 self->last_wanted = 0;
77
[2212]78 return 0;
79}
80
81int     driver_sysclock_close   (struct roar_vio_calls * vio) {
82 struct driver_sysclock * self = vio->inst;
83
84 if ( self == NULL )
85  return -1;
86
87 free(self);
88
89 return 0;
90}
91
[4897]92int driver_sysclock_nonblock(struct roar_vio_calls * vio, int state) {
93 if ( state == ROAR_SOCKET_BLOCK )
94  return 0;
95 return -1;
96}
97
[2212]98ssize_t driver_sysclock_write   (struct roar_vio_calls * vio, void *buf, size_t count) {
99 struct driver_sysclock * self = vio->inst;
[2213]100 struct timeval now;
[2911]101 long long diff = (1000000LL * count / (long long)self->bps);
[2422]102 long long ago;
[2213]103
104 gettimeofday(&now, NULL);
105
106 ago  = now.tv_usec - self->lasttime.tv_usec;
107 ago += 1000000*(now.tv_sec - self->lasttime.tv_sec);
108
[2422]109 ago -= self->last_wanted;
110
[2213]111 memcpy(&(self->lasttime), &now, sizeof(now));
112
113 ROAR_DBG("driver_sysclock_write(*): count=%u, bps=%u, diff=%llu, ago=%llu", count, self->bps, diff, ago);
114
115 diff -= ago;
116
[2422]117 self->last_wanted = diff;
118
[2911]119 ROAR_DBG("driver_sysclock_write(*): diff=%lli", diff);
120
[2422]121 if ( diff > 0 )
[4896]122  roar_usleep(diff);
[2213]123
124 return count;
[2208]125}
[2212]126
[2209]127#endif
[2208]128
129//ll
Note: See TracBrowser for help on using the repository browser.