~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/sound/core/seq/seq_timer.h

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0-or-later */
  2 /*
  3  *  ALSA sequencer Timer
  4  *  Copyright (c) 1998-1999 by Frank van de Pol <fvdpol@coil.demon.nl>
  5  */
  6 #ifndef __SND_SEQ_TIMER_H
  7 #define __SND_SEQ_TIMER_H
  8 
  9 #include <sound/timer.h>
 10 #include <sound/seq_kernel.h>
 11 
 12 struct snd_seq_timer_tick {
 13         snd_seq_tick_time_t     cur_tick;       /* current tick */
 14         unsigned long           resolution;     /* time per tick in nsec */
 15         unsigned long           fraction;       /* current time per tick in nsec */
 16 };
 17 
 18 struct snd_seq_timer {
 19         /* ... tempo / offset / running state */
 20 
 21         unsigned int            running:1,      /* running state of queue */    
 22                                 initialized:1;  /* timer is initialized */
 23 
 24         unsigned int            tempo;          /* current tempo, us/tick */
 25         int                     ppq;            /* time resolution, ticks/quarter */
 26 
 27         snd_seq_real_time_t     cur_time;       /* current time */
 28         struct snd_seq_timer_tick       tick;   /* current tick */
 29         int tick_updated;
 30         
 31         int                     type;           /* timer type */
 32         struct snd_timer_id     alsa_id;        /* ALSA's timer ID */
 33         struct snd_timer_instance       *timeri;        /* timer instance */
 34         unsigned int            ticks;
 35         unsigned long           preferred_resolution; /* timer resolution, ticks/sec */
 36 
 37         unsigned int skew;
 38         unsigned int skew_base;
 39         unsigned int tempo_base;
 40 
 41         struct timespec64       last_update;     /* time of last clock update, used for interpolation */
 42 
 43         spinlock_t lock;
 44 };
 45 
 46 
 47 /* create new timer (constructor) */
 48 struct snd_seq_timer *snd_seq_timer_new(void);
 49 
 50 /* delete timer (destructor) */
 51 void snd_seq_timer_delete(struct snd_seq_timer **tmr);
 52 
 53 /* */
 54 static inline void snd_seq_timer_update_tick(struct snd_seq_timer_tick *tick,
 55                                              unsigned long resolution)
 56 {
 57         if (tick->resolution > 0) {
 58                 tick->fraction += resolution;
 59                 tick->cur_tick += (unsigned int)(tick->fraction / tick->resolution);
 60                 tick->fraction %= tick->resolution;
 61         }
 62 }
 63 
 64 
 65 /* compare timestamp between events */
 66 /* return 1 if a >= b; otherwise return 0 */
 67 static inline int snd_seq_compare_tick_time(snd_seq_tick_time_t *a, snd_seq_tick_time_t *b)
 68 {
 69         /* compare ticks */
 70         return (*a >= *b);
 71 }
 72 
 73 static inline int snd_seq_compare_real_time(snd_seq_real_time_t *a, snd_seq_real_time_t *b)
 74 {
 75         /* compare real time */
 76         if (a->tv_sec > b->tv_sec)
 77                 return 1;
 78         if ((a->tv_sec == b->tv_sec) && (a->tv_nsec >= b->tv_nsec))
 79                 return 1;
 80         return 0;
 81 }
 82 
 83 
 84 static inline void snd_seq_sanity_real_time(snd_seq_real_time_t *tm)
 85 {
 86         while (tm->tv_nsec >= 1000000000) {
 87                 /* roll-over */
 88                 tm->tv_nsec -= 1000000000;
 89                 tm->tv_sec++;
 90         }
 91 }
 92 
 93 
 94 /* increment timestamp */
 95 static inline void snd_seq_inc_real_time(snd_seq_real_time_t *tm, snd_seq_real_time_t *inc)
 96 {
 97         tm->tv_sec  += inc->tv_sec;
 98         tm->tv_nsec += inc->tv_nsec;
 99         snd_seq_sanity_real_time(tm);
100 }
101 
102 static inline void snd_seq_inc_time_nsec(snd_seq_real_time_t *tm, unsigned long nsec)
103 {
104         tm->tv_nsec  += nsec;
105         snd_seq_sanity_real_time(tm);
106 }
107 
108 /* called by timer isr */
109 struct snd_seq_queue;
110 int snd_seq_timer_open(struct snd_seq_queue *q);
111 int snd_seq_timer_close(struct snd_seq_queue *q);
112 int snd_seq_timer_midi_open(struct snd_seq_queue *q);
113 int snd_seq_timer_midi_close(struct snd_seq_queue *q);
114 void snd_seq_timer_defaults(struct snd_seq_timer *tmr);
115 void snd_seq_timer_reset(struct snd_seq_timer *tmr);
116 int snd_seq_timer_stop(struct snd_seq_timer *tmr);
117 int snd_seq_timer_start(struct snd_seq_timer *tmr);
118 int snd_seq_timer_continue(struct snd_seq_timer *tmr);
119 int snd_seq_timer_set_tempo(struct snd_seq_timer *tmr, int tempo);
120 int snd_seq_timer_set_tempo_ppq(struct snd_seq_timer *tmr, int tempo, int ppq,
121                                 unsigned int tempo_base);
122 int snd_seq_timer_set_position_tick(struct snd_seq_timer *tmr, snd_seq_tick_time_t position);
123 int snd_seq_timer_set_position_time(struct snd_seq_timer *tmr, snd_seq_real_time_t position);
124 int snd_seq_timer_set_skew(struct snd_seq_timer *tmr, unsigned int skew, unsigned int base);
125 snd_seq_real_time_t snd_seq_timer_get_cur_time(struct snd_seq_timer *tmr,
126                                                bool adjust_ktime);
127 snd_seq_tick_time_t snd_seq_timer_get_cur_tick(struct snd_seq_timer *tmr);
128 
129 extern int seq_default_timer_class;
130 extern int seq_default_timer_sclass;
131 extern int seq_default_timer_card;
132 extern int seq_default_timer_device;
133 extern int seq_default_timer_subdevice;
134 extern int seq_default_timer_resolution;
135 
136 #endif
137 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php