Lines Matching refs:tmr

21 static void snd_seq_timer_set_tick_resolution(struct snd_seq_timer *tmr)  in snd_seq_timer_set_tick_resolution()  argument
23 if (tmr->tempo < 1000000) in snd_seq_timer_set_tick_resolution()
24 tmr->tick.resolution = (tmr->tempo * 1000) / tmr->ppq; in snd_seq_timer_set_tick_resolution()
28 s = tmr->tempo % tmr->ppq; in snd_seq_timer_set_tick_resolution()
29 s = (s * 1000) / tmr->ppq; in snd_seq_timer_set_tick_resolution()
30 tmr->tick.resolution = (tmr->tempo / tmr->ppq) * 1000; in snd_seq_timer_set_tick_resolution()
31 tmr->tick.resolution += s; in snd_seq_timer_set_tick_resolution()
33 if (tmr->tick.resolution <= 0) in snd_seq_timer_set_tick_resolution()
34 tmr->tick.resolution = 1; in snd_seq_timer_set_tick_resolution()
35 snd_seq_timer_update_tick(&tmr->tick, 0); in snd_seq_timer_set_tick_resolution()
41 struct snd_seq_timer *tmr; in snd_seq_timer_new() local
43 tmr = kzalloc(sizeof(*tmr), GFP_KERNEL); in snd_seq_timer_new()
44 if (!tmr) in snd_seq_timer_new()
46 spin_lock_init(&tmr->lock); in snd_seq_timer_new()
49 snd_seq_timer_defaults(tmr); in snd_seq_timer_new()
52 snd_seq_timer_reset(tmr); in snd_seq_timer_new()
54 return tmr; in snd_seq_timer_new()
58 void snd_seq_timer_delete(struct snd_seq_timer **tmr) in snd_seq_timer_delete() argument
60 struct snd_seq_timer *t = *tmr; in snd_seq_timer_delete()
61 *tmr = NULL; in snd_seq_timer_delete()
76 void snd_seq_timer_defaults(struct snd_seq_timer * tmr) in snd_seq_timer_defaults() argument
80 spin_lock_irqsave(&tmr->lock, flags); in snd_seq_timer_defaults()
82 tmr->ppq = 96; /* 96 PPQ */ in snd_seq_timer_defaults()
83 tmr->tempo = 500000; /* 120 BPM */ in snd_seq_timer_defaults()
84 snd_seq_timer_set_tick_resolution(tmr); in snd_seq_timer_defaults()
85 tmr->running = 0; in snd_seq_timer_defaults()
87 tmr->type = SNDRV_SEQ_TIMER_ALSA; in snd_seq_timer_defaults()
88 tmr->alsa_id.dev_class = seq_default_timer_class; in snd_seq_timer_defaults()
89 tmr->alsa_id.dev_sclass = seq_default_timer_sclass; in snd_seq_timer_defaults()
90 tmr->alsa_id.card = seq_default_timer_card; in snd_seq_timer_defaults()
91 tmr->alsa_id.device = seq_default_timer_device; in snd_seq_timer_defaults()
92 tmr->alsa_id.subdevice = seq_default_timer_subdevice; in snd_seq_timer_defaults()
93 tmr->preferred_resolution = seq_default_timer_resolution; in snd_seq_timer_defaults()
95 tmr->skew = tmr->skew_base = SKEW_BASE; in snd_seq_timer_defaults()
96 spin_unlock_irqrestore(&tmr->lock, flags); in snd_seq_timer_defaults()
99 static void seq_timer_reset(struct snd_seq_timer *tmr) in seq_timer_reset() argument
102 tmr->cur_time.tv_sec = 0; in seq_timer_reset()
103 tmr->cur_time.tv_nsec = 0; in seq_timer_reset()
105 tmr->tick.cur_tick = 0; in seq_timer_reset()
106 tmr->tick.fraction = 0; in seq_timer_reset()
109 void snd_seq_timer_reset(struct snd_seq_timer *tmr) in snd_seq_timer_reset() argument
113 spin_lock_irqsave(&tmr->lock, flags); in snd_seq_timer_reset()
114 seq_timer_reset(tmr); in snd_seq_timer_reset()
115 spin_unlock_irqrestore(&tmr->lock, flags); in snd_seq_timer_reset()
126 struct snd_seq_timer *tmr; in snd_seq_timer_interrupt() local
130 tmr = q->timer; in snd_seq_timer_interrupt()
131 if (tmr == NULL) in snd_seq_timer_interrupt()
133 spin_lock_irqsave(&tmr->lock, flags); in snd_seq_timer_interrupt()
134 if (!tmr->running) { in snd_seq_timer_interrupt()
135 spin_unlock_irqrestore(&tmr->lock, flags); in snd_seq_timer_interrupt()
140 if (tmr->skew != tmr->skew_base) { in snd_seq_timer_interrupt()
142 resolution = (resolution >> 16) * tmr->skew + in snd_seq_timer_interrupt()
143 (((resolution & 0xffff) * tmr->skew) >> 16); in snd_seq_timer_interrupt()
147 snd_seq_inc_time_nsec(&tmr->cur_time, resolution); in snd_seq_timer_interrupt()
150 snd_seq_timer_update_tick(&tmr->tick, resolution); in snd_seq_timer_interrupt()
153 ktime_get_ts64(&tmr->last_update); in snd_seq_timer_interrupt()
155 spin_unlock_irqrestore(&tmr->lock, flags); in snd_seq_timer_interrupt()
162 int snd_seq_timer_set_tempo(struct snd_seq_timer * tmr, int tempo) in snd_seq_timer_set_tempo() argument
166 if (snd_BUG_ON(!tmr)) in snd_seq_timer_set_tempo()
170 spin_lock_irqsave(&tmr->lock, flags); in snd_seq_timer_set_tempo()
171 if ((unsigned int)tempo != tmr->tempo) { in snd_seq_timer_set_tempo()
172 tmr->tempo = tempo; in snd_seq_timer_set_tempo()
173 snd_seq_timer_set_tick_resolution(tmr); in snd_seq_timer_set_tempo()
175 spin_unlock_irqrestore(&tmr->lock, flags); in snd_seq_timer_set_tempo()
180 int snd_seq_timer_set_tempo_ppq(struct snd_seq_timer *tmr, int tempo, int ppq) in snd_seq_timer_set_tempo_ppq() argument
185 if (snd_BUG_ON(!tmr)) in snd_seq_timer_set_tempo_ppq()
189 spin_lock_irqsave(&tmr->lock, flags); in snd_seq_timer_set_tempo_ppq()
190 if (tmr->running && (ppq != tmr->ppq)) { in snd_seq_timer_set_tempo_ppq()
193 spin_unlock_irqrestore(&tmr->lock, flags); in snd_seq_timer_set_tempo_ppq()
197 changed = (tempo != tmr->tempo) || (ppq != tmr->ppq); in snd_seq_timer_set_tempo_ppq()
198 tmr->tempo = tempo; in snd_seq_timer_set_tempo_ppq()
199 tmr->ppq = ppq; in snd_seq_timer_set_tempo_ppq()
201 snd_seq_timer_set_tick_resolution(tmr); in snd_seq_timer_set_tempo_ppq()
202 spin_unlock_irqrestore(&tmr->lock, flags); in snd_seq_timer_set_tempo_ppq()
207 int snd_seq_timer_set_position_tick(struct snd_seq_timer *tmr, in snd_seq_timer_set_position_tick() argument
212 if (snd_BUG_ON(!tmr)) in snd_seq_timer_set_position_tick()
215 spin_lock_irqsave(&tmr->lock, flags); in snd_seq_timer_set_position_tick()
216 tmr->tick.cur_tick = position; in snd_seq_timer_set_position_tick()
217 tmr->tick.fraction = 0; in snd_seq_timer_set_position_tick()
218 spin_unlock_irqrestore(&tmr->lock, flags); in snd_seq_timer_set_position_tick()
223 int snd_seq_timer_set_position_time(struct snd_seq_timer *tmr, in snd_seq_timer_set_position_time() argument
228 if (snd_BUG_ON(!tmr)) in snd_seq_timer_set_position_time()
232 spin_lock_irqsave(&tmr->lock, flags); in snd_seq_timer_set_position_time()
233 tmr->cur_time = position; in snd_seq_timer_set_position_time()
234 spin_unlock_irqrestore(&tmr->lock, flags); in snd_seq_timer_set_position_time()
239 int snd_seq_timer_set_skew(struct snd_seq_timer *tmr, unsigned int skew, in snd_seq_timer_set_skew() argument
244 if (snd_BUG_ON(!tmr)) in snd_seq_timer_set_skew()
252 spin_lock_irqsave(&tmr->lock, flags); in snd_seq_timer_set_skew()
253 tmr->skew = skew; in snd_seq_timer_set_skew()
254 spin_unlock_irqrestore(&tmr->lock, flags); in snd_seq_timer_set_skew()
261 struct snd_seq_timer *tmr; in snd_seq_timer_open() local
265 tmr = q->timer; in snd_seq_timer_open()
266 if (snd_BUG_ON(!tmr)) in snd_seq_timer_open()
268 if (tmr->timeri) in snd_seq_timer_open()
271 if (tmr->type != SNDRV_SEQ_TIMER_ALSA) /* standard ALSA timer */ in snd_seq_timer_open()
273 if (tmr->alsa_id.dev_class != SNDRV_TIMER_CLASS_SLAVE) in snd_seq_timer_open()
274 tmr->alsa_id.dev_sclass = SNDRV_TIMER_SCLASS_SEQUENCER; in snd_seq_timer_open()
281 err = snd_timer_open(t, &tmr->alsa_id, q->queue); in snd_seq_timer_open()
282 if (err < 0 && tmr->alsa_id.dev_class != SNDRV_TIMER_CLASS_SLAVE) { in snd_seq_timer_open()
283 if (tmr->alsa_id.dev_class != SNDRV_TIMER_CLASS_GLOBAL || in snd_seq_timer_open()
284 tmr->alsa_id.device != SNDRV_TIMER_GLOBAL_SYSTEM) { in snd_seq_timer_open()
299 spin_lock_irq(&tmr->lock); in snd_seq_timer_open()
300 if (tmr->timeri) in snd_seq_timer_open()
303 tmr->timeri = t; in snd_seq_timer_open()
304 spin_unlock_irq(&tmr->lock); in snd_seq_timer_open()
315 struct snd_seq_timer *tmr; in snd_seq_timer_close() local
318 tmr = q->timer; in snd_seq_timer_close()
319 if (snd_BUG_ON(!tmr)) in snd_seq_timer_close()
321 spin_lock_irq(&tmr->lock); in snd_seq_timer_close()
322 t = tmr->timeri; in snd_seq_timer_close()
323 tmr->timeri = NULL; in snd_seq_timer_close()
324 spin_unlock_irq(&tmr->lock); in snd_seq_timer_close()
332 static int seq_timer_stop(struct snd_seq_timer *tmr) in seq_timer_stop() argument
334 if (! tmr->timeri) in seq_timer_stop()
336 if (!tmr->running) in seq_timer_stop()
338 tmr->running = 0; in seq_timer_stop()
339 snd_timer_pause(tmr->timeri); in seq_timer_stop()
343 int snd_seq_timer_stop(struct snd_seq_timer *tmr) in snd_seq_timer_stop() argument
348 spin_lock_irqsave(&tmr->lock, flags); in snd_seq_timer_stop()
349 err = seq_timer_stop(tmr); in snd_seq_timer_stop()
350 spin_unlock_irqrestore(&tmr->lock, flags); in snd_seq_timer_stop()
354 static int initialize_timer(struct snd_seq_timer *tmr) in initialize_timer() argument
359 t = tmr->timeri->timer; in initialize_timer()
363 freq = tmr->preferred_resolution; in initialize_timer()
371 tmr->ticks = 1; in initialize_timer()
373 unsigned long r = snd_timer_resolution(tmr->timeri); in initialize_timer()
375 tmr->ticks = (unsigned int)(1000000000uL / (r * freq)); in initialize_timer()
376 if (! tmr->ticks) in initialize_timer()
377 tmr->ticks = 1; in initialize_timer()
380 tmr->initialized = 1; in initialize_timer()
384 static int seq_timer_start(struct snd_seq_timer *tmr) in seq_timer_start() argument
386 if (! tmr->timeri) in seq_timer_start()
388 if (tmr->running) in seq_timer_start()
389 seq_timer_stop(tmr); in seq_timer_start()
390 seq_timer_reset(tmr); in seq_timer_start()
391 if (initialize_timer(tmr) < 0) in seq_timer_start()
393 snd_timer_start(tmr->timeri, tmr->ticks); in seq_timer_start()
394 tmr->running = 1; in seq_timer_start()
395 ktime_get_ts64(&tmr->last_update); in seq_timer_start()
399 int snd_seq_timer_start(struct snd_seq_timer *tmr) in snd_seq_timer_start() argument
404 spin_lock_irqsave(&tmr->lock, flags); in snd_seq_timer_start()
405 err = seq_timer_start(tmr); in snd_seq_timer_start()
406 spin_unlock_irqrestore(&tmr->lock, flags); in snd_seq_timer_start()
410 static int seq_timer_continue(struct snd_seq_timer *tmr) in seq_timer_continue() argument
412 if (! tmr->timeri) in seq_timer_continue()
414 if (tmr->running) in seq_timer_continue()
416 if (! tmr->initialized) { in seq_timer_continue()
417 seq_timer_reset(tmr); in seq_timer_continue()
418 if (initialize_timer(tmr) < 0) in seq_timer_continue()
421 snd_timer_start(tmr->timeri, tmr->ticks); in seq_timer_continue()
422 tmr->running = 1; in seq_timer_continue()
423 ktime_get_ts64(&tmr->last_update); in seq_timer_continue()
427 int snd_seq_timer_continue(struct snd_seq_timer *tmr) in snd_seq_timer_continue() argument
432 spin_lock_irqsave(&tmr->lock, flags); in snd_seq_timer_continue()
433 err = seq_timer_continue(tmr); in snd_seq_timer_continue()
434 spin_unlock_irqrestore(&tmr->lock, flags); in snd_seq_timer_continue()
439 snd_seq_real_time_t snd_seq_timer_get_cur_time(struct snd_seq_timer *tmr, in snd_seq_timer_get_cur_time() argument
445 spin_lock_irqsave(&tmr->lock, flags); in snd_seq_timer_get_cur_time()
446 cur_time = tmr->cur_time; in snd_seq_timer_get_cur_time()
447 if (adjust_ktime && tmr->running) { in snd_seq_timer_get_cur_time()
451 tm = timespec64_sub(tm, tmr->last_update); in snd_seq_timer_get_cur_time()
456 spin_unlock_irqrestore(&tmr->lock, flags); in snd_seq_timer_get_cur_time()
462 snd_seq_tick_time_t snd_seq_timer_get_cur_tick(struct snd_seq_timer *tmr) in snd_seq_timer_get_cur_tick() argument
467 spin_lock_irqsave(&tmr->lock, flags); in snd_seq_timer_get_cur_tick()
468 cur_tick = tmr->tick.cur_tick; in snd_seq_timer_get_cur_tick()
469 spin_unlock_irqrestore(&tmr->lock, flags); in snd_seq_timer_get_cur_tick()
481 struct snd_seq_timer *tmr; in snd_seq_info_timer_read() local
490 tmr = q->timer; in snd_seq_info_timer_read()
491 if (!tmr) in snd_seq_info_timer_read()
493 ti = tmr->timeri; in snd_seq_info_timer_read()
497 resolution = snd_timer_resolution(ti) * tmr->ticks; in snd_seq_info_timer_read()
499 snd_iprintf(buffer, " Skew : %u / %u\n", tmr->skew, tmr->skew_base); in snd_seq_info_timer_read()