Lines Matching full:tmr
21 static void snd_seq_timer_set_tick_resolution(struct snd_seq_timer *tmr) in snd_seq_timer_set_tick_resolution() argument
24 tmr->tempo_base == 1000 ? 1000000 : 10000; in snd_seq_timer_set_tick_resolution()
26 if (tmr->tempo < threshold) in snd_seq_timer_set_tick_resolution()
27 tmr->tick.resolution = (tmr->tempo * tmr->tempo_base) / tmr->ppq; in snd_seq_timer_set_tick_resolution()
31 s = tmr->tempo % tmr->ppq; in snd_seq_timer_set_tick_resolution()
32 s = (s * tmr->tempo_base) / tmr->ppq; in snd_seq_timer_set_tick_resolution()
33 tmr->tick.resolution = (tmr->tempo / tmr->ppq) * tmr->tempo_base; in snd_seq_timer_set_tick_resolution()
34 tmr->tick.resolution += s; in snd_seq_timer_set_tick_resolution()
36 if (tmr->tick.resolution <= 0) in snd_seq_timer_set_tick_resolution()
37 tmr->tick.resolution = 1; in snd_seq_timer_set_tick_resolution()
38 snd_seq_timer_update_tick(&tmr->tick, 0); in snd_seq_timer_set_tick_resolution()
44 struct snd_seq_timer *tmr; in snd_seq_timer_new() local
46 tmr = kzalloc(sizeof(*tmr), GFP_KERNEL); in snd_seq_timer_new()
47 if (!tmr) in snd_seq_timer_new()
49 spin_lock_init(&tmr->lock); in snd_seq_timer_new()
52 snd_seq_timer_defaults(tmr); in snd_seq_timer_new()
55 snd_seq_timer_reset(tmr); in snd_seq_timer_new()
57 return tmr; in snd_seq_timer_new()
61 void snd_seq_timer_delete(struct snd_seq_timer **tmr) in snd_seq_timer_delete() argument
63 struct snd_seq_timer *t = *tmr; in snd_seq_timer_delete()
64 *tmr = NULL; in snd_seq_timer_delete()
79 void snd_seq_timer_defaults(struct snd_seq_timer * tmr) in snd_seq_timer_defaults() argument
81 guard(spinlock_irqsave)(&tmr->lock); in snd_seq_timer_defaults()
83 tmr->ppq = 96; /* 96 PPQ */ in snd_seq_timer_defaults()
84 tmr->tempo = 500000; /* 120 BPM */ in snd_seq_timer_defaults()
85 tmr->tempo_base = 1000; /* 1us */ in snd_seq_timer_defaults()
86 snd_seq_timer_set_tick_resolution(tmr); in snd_seq_timer_defaults()
87 tmr->running = 0; in snd_seq_timer_defaults()
89 tmr->type = SNDRV_SEQ_TIMER_ALSA; in snd_seq_timer_defaults()
90 tmr->alsa_id.dev_class = seq_default_timer_class; in snd_seq_timer_defaults()
91 tmr->alsa_id.dev_sclass = seq_default_timer_sclass; in snd_seq_timer_defaults()
92 tmr->alsa_id.card = seq_default_timer_card; in snd_seq_timer_defaults()
93 tmr->alsa_id.device = seq_default_timer_device; in snd_seq_timer_defaults()
94 tmr->alsa_id.subdevice = seq_default_timer_subdevice; in snd_seq_timer_defaults()
95 tmr->preferred_resolution = seq_default_timer_resolution; in snd_seq_timer_defaults()
97 tmr->skew = tmr->skew_base = SKEW_BASE; in snd_seq_timer_defaults()
100 static void seq_timer_reset(struct snd_seq_timer *tmr) in seq_timer_reset() argument
103 tmr->cur_time.tv_sec = 0; in seq_timer_reset()
104 tmr->cur_time.tv_nsec = 0; in seq_timer_reset()
106 tmr->tick.cur_tick = 0; in seq_timer_reset()
107 tmr->tick.fraction = 0; in seq_timer_reset()
110 void snd_seq_timer_reset(struct snd_seq_timer *tmr) in snd_seq_timer_reset() argument
112 guard(spinlock_irqsave)(&tmr->lock); in snd_seq_timer_reset()
113 seq_timer_reset(tmr); in snd_seq_timer_reset()
123 struct snd_seq_timer *tmr; in snd_seq_timer_interrupt() local
127 tmr = q->timer; in snd_seq_timer_interrupt()
128 if (tmr == NULL) in snd_seq_timer_interrupt()
131 scoped_guard(spinlock_irqsave, &tmr->lock) { in snd_seq_timer_interrupt()
132 if (!tmr->running) in snd_seq_timer_interrupt()
136 if (tmr->skew != tmr->skew_base) { in snd_seq_timer_interrupt()
138 resolution = (resolution >> 16) * tmr->skew + in snd_seq_timer_interrupt()
139 (((resolution & 0xffff) * tmr->skew) >> 16); in snd_seq_timer_interrupt()
143 snd_seq_inc_time_nsec(&tmr->cur_time, resolution); in snd_seq_timer_interrupt()
146 snd_seq_timer_update_tick(&tmr->tick, resolution); in snd_seq_timer_interrupt()
149 ktime_get_ts64(&tmr->last_update); in snd_seq_timer_interrupt()
157 int snd_seq_timer_set_tempo(struct snd_seq_timer * tmr, int tempo) in snd_seq_timer_set_tempo() argument
159 if (snd_BUG_ON(!tmr)) in snd_seq_timer_set_tempo()
163 guard(spinlock_irqsave)(&tmr->lock); in snd_seq_timer_set_tempo()
164 if ((unsigned int)tempo != tmr->tempo) { in snd_seq_timer_set_tempo()
165 tmr->tempo = tempo; in snd_seq_timer_set_tempo()
166 snd_seq_timer_set_tick_resolution(tmr); in snd_seq_timer_set_tempo()
172 int snd_seq_timer_set_tempo_ppq(struct snd_seq_timer *tmr, int tempo, int ppq, in snd_seq_timer_set_tempo_ppq() argument
177 if (snd_BUG_ON(!tmr)) in snd_seq_timer_set_tempo_ppq()
184 guard(spinlock_irqsave)(&tmr->lock); in snd_seq_timer_set_tempo_ppq()
185 if (tmr->running && (ppq != tmr->ppq)) { in snd_seq_timer_set_tempo_ppq()
191 changed = (tempo != tmr->tempo) || (ppq != tmr->ppq); in snd_seq_timer_set_tempo_ppq()
192 tmr->tempo = tempo; in snd_seq_timer_set_tempo_ppq()
193 tmr->ppq = ppq; in snd_seq_timer_set_tempo_ppq()
194 tmr->tempo_base = tempo_base ? tempo_base : 1000; in snd_seq_timer_set_tempo_ppq()
196 snd_seq_timer_set_tick_resolution(tmr); in snd_seq_timer_set_tempo_ppq()
201 int snd_seq_timer_set_position_tick(struct snd_seq_timer *tmr, in snd_seq_timer_set_position_tick() argument
204 if (snd_BUG_ON(!tmr)) in snd_seq_timer_set_position_tick()
207 guard(spinlock_irqsave)(&tmr->lock); in snd_seq_timer_set_position_tick()
208 tmr->tick.cur_tick = position; in snd_seq_timer_set_position_tick()
209 tmr->tick.fraction = 0; in snd_seq_timer_set_position_tick()
214 int snd_seq_timer_set_position_time(struct snd_seq_timer *tmr, in snd_seq_timer_set_position_time() argument
217 if (snd_BUG_ON(!tmr)) in snd_seq_timer_set_position_time()
221 guard(spinlock_irqsave)(&tmr->lock); in snd_seq_timer_set_position_time()
222 tmr->cur_time = position; in snd_seq_timer_set_position_time()
227 int snd_seq_timer_set_skew(struct snd_seq_timer *tmr, unsigned int skew, in snd_seq_timer_set_skew() argument
230 if (snd_BUG_ON(!tmr)) in snd_seq_timer_set_skew()
238 guard(spinlock_irqsave)(&tmr->lock); in snd_seq_timer_set_skew()
239 tmr->skew = skew; in snd_seq_timer_set_skew()
246 struct snd_seq_timer *tmr; in snd_seq_timer_open() local
250 tmr = q->timer; in snd_seq_timer_open()
251 if (snd_BUG_ON(!tmr)) in snd_seq_timer_open()
253 if (tmr->timeri) in snd_seq_timer_open()
256 if (tmr->type != SNDRV_SEQ_TIMER_ALSA) /* standard ALSA timer */ in snd_seq_timer_open()
258 if (tmr->alsa_id.dev_class != SNDRV_TIMER_CLASS_SLAVE) in snd_seq_timer_open()
259 tmr->alsa_id.dev_sclass = SNDRV_TIMER_SCLASS_SEQUENCER; in snd_seq_timer_open()
266 err = snd_timer_open(t, &tmr->alsa_id, q->queue); in snd_seq_timer_open()
267 if (err < 0 && tmr->alsa_id.dev_class != SNDRV_TIMER_CLASS_SLAVE) { in snd_seq_timer_open()
268 if (tmr->alsa_id.dev_class != SNDRV_TIMER_CLASS_GLOBAL || in snd_seq_timer_open()
269 tmr->alsa_id.device != SNDRV_TIMER_GLOBAL_SYSTEM) { in snd_seq_timer_open()
284 scoped_guard(spinlock_irq, &tmr->lock) { in snd_seq_timer_open()
285 if (tmr->timeri) in snd_seq_timer_open()
288 tmr->timeri = t; in snd_seq_timer_open()
300 struct snd_seq_timer *tmr; in snd_seq_timer_close() local
303 tmr = q->timer; in snd_seq_timer_close()
304 if (snd_BUG_ON(!tmr)) in snd_seq_timer_close()
306 scoped_guard(spinlock_irq, &tmr->lock) { in snd_seq_timer_close()
307 t = tmr->timeri; in snd_seq_timer_close()
308 tmr->timeri = NULL; in snd_seq_timer_close()
317 static int seq_timer_stop(struct snd_seq_timer *tmr) in seq_timer_stop() argument
319 if (! tmr->timeri) in seq_timer_stop()
321 if (!tmr->running) in seq_timer_stop()
323 tmr->running = 0; in seq_timer_stop()
324 snd_timer_pause(tmr->timeri); in seq_timer_stop()
328 int snd_seq_timer_stop(struct snd_seq_timer *tmr) in snd_seq_timer_stop() argument
330 guard(spinlock_irqsave)(&tmr->lock); in snd_seq_timer_stop()
331 return seq_timer_stop(tmr); in snd_seq_timer_stop()
334 static int initialize_timer(struct snd_seq_timer *tmr) in initialize_timer() argument
339 t = tmr->timeri->timer; in initialize_timer()
343 freq = tmr->preferred_resolution; in initialize_timer()
351 tmr->ticks = 1; in initialize_timer()
353 unsigned long r = snd_timer_resolution(tmr->timeri); in initialize_timer()
355 tmr->ticks = (unsigned int)(1000000000uL / (r * freq)); in initialize_timer()
356 if (! tmr->ticks) in initialize_timer()
357 tmr->ticks = 1; in initialize_timer()
360 tmr->initialized = 1; in initialize_timer()
364 static int seq_timer_start(struct snd_seq_timer *tmr) in seq_timer_start() argument
366 if (! tmr->timeri) in seq_timer_start()
368 if (tmr->running) in seq_timer_start()
369 seq_timer_stop(tmr); in seq_timer_start()
370 seq_timer_reset(tmr); in seq_timer_start()
371 if (initialize_timer(tmr) < 0) in seq_timer_start()
373 snd_timer_start(tmr->timeri, tmr->ticks); in seq_timer_start()
374 tmr->running = 1; in seq_timer_start()
375 ktime_get_ts64(&tmr->last_update); in seq_timer_start()
379 int snd_seq_timer_start(struct snd_seq_timer *tmr) in snd_seq_timer_start() argument
381 guard(spinlock_irqsave)(&tmr->lock); in snd_seq_timer_start()
382 return seq_timer_start(tmr); in snd_seq_timer_start()
385 static int seq_timer_continue(struct snd_seq_timer *tmr) in seq_timer_continue() argument
387 if (! tmr->timeri) in seq_timer_continue()
389 if (tmr->running) in seq_timer_continue()
391 if (! tmr->initialized) { in seq_timer_continue()
392 seq_timer_reset(tmr); in seq_timer_continue()
393 if (initialize_timer(tmr) < 0) in seq_timer_continue()
396 snd_timer_start(tmr->timeri, tmr->ticks); in seq_timer_continue()
397 tmr->running = 1; in seq_timer_continue()
398 ktime_get_ts64(&tmr->last_update); in seq_timer_continue()
402 int snd_seq_timer_continue(struct snd_seq_timer *tmr) in snd_seq_timer_continue() argument
404 guard(spinlock_irqsave)(&tmr->lock); in snd_seq_timer_continue()
405 return seq_timer_continue(tmr); in snd_seq_timer_continue()
409 snd_seq_real_time_t snd_seq_timer_get_cur_time(struct snd_seq_timer *tmr, in snd_seq_timer_get_cur_time() argument
414 guard(spinlock_irqsave)(&tmr->lock); in snd_seq_timer_get_cur_time()
415 cur_time = tmr->cur_time; in snd_seq_timer_get_cur_time()
416 if (adjust_ktime && tmr->running) { in snd_seq_timer_get_cur_time()
420 tm = timespec64_sub(tm, tmr->last_update); in snd_seq_timer_get_cur_time()
430 snd_seq_tick_time_t snd_seq_timer_get_cur_tick(struct snd_seq_timer *tmr) in snd_seq_timer_get_cur_tick() argument
432 guard(spinlock_irqsave)(&tmr->lock); in snd_seq_timer_get_cur_tick()
433 return tmr->tick.cur_tick; in snd_seq_timer_get_cur_tick()
444 struct snd_seq_timer *tmr; in snd_seq_info_timer_read() local
453 tmr = q->timer; in snd_seq_info_timer_read()
454 if (!tmr) in snd_seq_info_timer_read()
456 ti = tmr->timeri; in snd_seq_info_timer_read()
460 resolution = snd_timer_resolution(ti) * tmr->ticks; in snd_seq_info_timer_read()
462 snd_iprintf(buffer, " Skew : %u / %u\n", tmr->skew, tmr->skew_base); in snd_seq_info_timer_read()