Lines Matching defs:tmr

21 static void snd_seq_timer_set_tick_resolution(struct snd_seq_timer *tmr)
23 if (tmr->tempo < 1000000)
24 tmr->tick.resolution = (tmr->tempo * 1000) / tmr->ppq;
28 s = tmr->tempo % tmr->ppq;
29 s = (s * 1000) / tmr->ppq;
30 tmr->tick.resolution = (tmr->tempo / tmr->ppq) * 1000;
31 tmr->tick.resolution += s;
33 if (tmr->tick.resolution <= 0)
34 tmr->tick.resolution = 1;
35 snd_seq_timer_update_tick(&tmr->tick, 0);
41 struct snd_seq_timer *tmr;
43 tmr = kzalloc(sizeof(*tmr), GFP_KERNEL);
44 if (!tmr)
46 spin_lock_init(&tmr->lock);
49 snd_seq_timer_defaults(tmr);
52 snd_seq_timer_reset(tmr);
54 return tmr;
58 void snd_seq_timer_delete(struct snd_seq_timer **tmr)
60 struct snd_seq_timer *t = *tmr;
61 *tmr = NULL;
76 void snd_seq_timer_defaults(struct snd_seq_timer * tmr)
78 guard(spinlock_irqsave)(&tmr->lock);
80 tmr->ppq = 96; /* 96 PPQ */
81 tmr->tempo = 500000; /* 120 BPM */
82 snd_seq_timer_set_tick_resolution(tmr);
83 tmr->running = 0;
85 tmr->type = SNDRV_SEQ_TIMER_ALSA;
86 tmr->alsa_id.dev_class = seq_default_timer_class;
87 tmr->alsa_id.dev_sclass = seq_default_timer_sclass;
88 tmr->alsa_id.card = seq_default_timer_card;
89 tmr->alsa_id.device = seq_default_timer_device;
90 tmr->alsa_id.subdevice = seq_default_timer_subdevice;
91 tmr->preferred_resolution = seq_default_timer_resolution;
93 tmr->skew = tmr->skew_base = SKEW_BASE;
96 static void seq_timer_reset(struct snd_seq_timer *tmr)
99 tmr->cur_time.tv_sec = 0;
100 tmr->cur_time.tv_nsec = 0;
102 tmr->tick.cur_tick = 0;
103 tmr->tick.fraction = 0;
106 void snd_seq_timer_reset(struct snd_seq_timer *tmr)
108 guard(spinlock_irqsave)(&tmr->lock);
109 seq_timer_reset(tmr);
119 struct snd_seq_timer *tmr;
123 tmr = q->timer;
124 if (tmr == NULL)
127 scoped_guard(spinlock_irqsave, &tmr->lock) {
128 if (!tmr->running)
132 if (tmr->skew != tmr->skew_base) {
134 resolution = (resolution >> 16) * tmr->skew +
135 (((resolution & 0xffff) * tmr->skew) >> 16);
139 snd_seq_inc_time_nsec(&tmr->cur_time, resolution);
142 snd_seq_timer_update_tick(&tmr->tick, resolution);
145 ktime_get_ts64(&tmr->last_update);
153 int snd_seq_timer_set_tempo(struct snd_seq_timer * tmr, int tempo)
155 if (snd_BUG_ON(!tmr))
159 guard(spinlock_irqsave)(&tmr->lock);
160 if ((unsigned int)tempo != tmr->tempo) {
161 tmr->tempo = tempo;
162 snd_seq_timer_set_tick_resolution(tmr);
168 int snd_seq_timer_set_tempo_ppq(struct snd_seq_timer *tmr, int tempo, int ppq)
172 if (snd_BUG_ON(!tmr))
176 guard(spinlock_irqsave)(&tmr->lock);
177 if (tmr->running && (ppq != tmr->ppq)) {
183 changed = (tempo != tmr->tempo) || (ppq != tmr->ppq);
184 tmr->tempo = tempo;
185 tmr->ppq = ppq;
187 snd_seq_timer_set_tick_resolution(tmr);
192 int snd_seq_timer_set_position_tick(struct snd_seq_timer *tmr,
195 if (snd_BUG_ON(!tmr))
198 guard(spinlock_irqsave)(&tmr->lock);
199 tmr->tick.cur_tick = position;
200 tmr->tick.fraction = 0;
205 int snd_seq_timer_set_position_time(struct snd_seq_timer *tmr,
208 if (snd_BUG_ON(!tmr))
212 guard(spinlock_irqsave)(&tmr->lock);
213 tmr->cur_time = position;
218 int snd_seq_timer_set_skew(struct snd_seq_timer *tmr, unsigned int skew,
221 if (snd_BUG_ON(!tmr))
229 guard(spinlock_irqsave)(&tmr->lock);
230 tmr->skew = skew;
237 struct snd_seq_timer *tmr;
241 tmr = q->timer;
242 if (snd_BUG_ON(!tmr))
244 if (tmr->timeri)
247 if (tmr->type != SNDRV_SEQ_TIMER_ALSA) /* standard ALSA timer */
249 if (tmr->alsa_id.dev_class != SNDRV_TIMER_CLASS_SLAVE)
250 tmr->alsa_id.dev_sclass = SNDRV_TIMER_SCLASS_SEQUENCER;
257 err = snd_timer_open(t, &tmr->alsa_id, q->queue);
258 if (err < 0 && tmr->alsa_id.dev_class != SNDRV_TIMER_CLASS_SLAVE) {
259 if (tmr->alsa_id.dev_class != SNDRV_TIMER_CLASS_GLOBAL ||
260 tmr->alsa_id.device != SNDRV_TIMER_GLOBAL_SYSTEM) {
275 scoped_guard(spinlock_irq, &tmr->lock) {
276 if (tmr->timeri)
279 tmr->timeri = t;
291 struct snd_seq_timer *tmr;
294 tmr = q->timer;
295 if (snd_BUG_ON(!tmr))
297 scoped_guard(spinlock_irq, &tmr->lock) {
298 t = tmr->timeri;
299 tmr->timeri = NULL;
308 static int seq_timer_stop(struct snd_seq_timer *tmr)
310 if (! tmr->timeri)
312 if (!tmr->running)
314 tmr->running = 0;
315 snd_timer_pause(tmr->timeri);
319 int snd_seq_timer_stop(struct snd_seq_timer *tmr)
321 guard(spinlock_irqsave)(&tmr->lock);
322 return seq_timer_stop(tmr);
325 static int initialize_timer(struct snd_seq_timer *tmr)
330 t = tmr->timeri->timer;
334 freq = tmr->preferred_resolution;
342 tmr->ticks = 1;
344 unsigned long r = snd_timer_resolution(tmr->timeri);
346 tmr->ticks = (unsigned int)(1000000000uL / (r * freq));
347 if (! tmr->ticks)
348 tmr->ticks = 1;
351 tmr->initialized = 1;
355 static int seq_timer_start(struct snd_seq_timer *tmr)
357 if (! tmr->timeri)
359 if (tmr->running)
360 seq_timer_stop(tmr);
361 seq_timer_reset(tmr);
362 if (initialize_timer(tmr) < 0)
364 snd_timer_start(tmr->timeri, tmr->ticks);
365 tmr->running = 1;
366 ktime_get_ts64(&tmr->last_update);
370 int snd_seq_timer_start(struct snd_seq_timer *tmr)
372 guard(spinlock_irqsave)(&tmr->lock);
373 return seq_timer_start(tmr);
376 static int seq_timer_continue(struct snd_seq_timer *tmr)
378 if (! tmr->timeri)
380 if (tmr->running)
382 if (! tmr->initialized) {
383 seq_timer_reset(tmr);
384 if (initialize_timer(tmr) < 0)
387 snd_timer_start(tmr->timeri, tmr->ticks);
388 tmr->running = 1;
389 ktime_get_ts64(&tmr->last_update);
393 int snd_seq_timer_continue(struct snd_seq_timer *tmr)
395 guard(spinlock_irqsave)(&tmr->lock);
396 return seq_timer_continue(tmr);
400 snd_seq_real_time_t snd_seq_timer_get_cur_time(struct snd_seq_timer *tmr,
405 guard(spinlock_irqsave)(&tmr->lock);
406 cur_time = tmr->cur_time;
407 if (adjust_ktime && tmr->running) {
411 tm = timespec64_sub(tm, tmr->last_update);
421 snd_seq_tick_time_t snd_seq_timer_get_cur_tick(struct snd_seq_timer *tmr)
423 guard(spinlock_irqsave)(&tmr->lock);
424 return tmr->tick.cur_tick;
435 struct snd_seq_timer *tmr;
444 tmr = q->timer;
445 if (!tmr)
447 ti = tmr->timeri;
451 resolution = snd_timer_resolution(ti) * tmr->ticks;
453 snd_iprintf(buffer, " Skew : %u / %u\n", tmr->skew, tmr->skew_base);