Lines Matching refs:rec

171 static inline int emu8k_get_curpos(struct snd_emu8k_pcm *rec, int ch)
173 int val = EMU8000_CCCA_READ(rec->emu, ch) & 0xfffffff;
174 val -= rec->loop_start[ch] - 1;
185 struct snd_emu8k_pcm *rec = from_timer(rec, t, timer);
188 spin_lock(&rec->timer_lock);
190 ptr = emu8k_get_curpos(rec, 0);
191 if (ptr < rec->last_ptr)
192 delta = ptr + rec->buf_size - rec->last_ptr;
194 delta = ptr - rec->last_ptr;
195 rec->period_pos += delta;
196 rec->last_ptr = ptr;
199 mod_timer(&rec->timer, jiffies + 1);
202 if (rec->period_pos >= (int)rec->period_size) {
203 rec->period_pos %= rec->period_size;
204 spin_unlock(&rec->timer_lock);
205 snd_pcm_period_elapsed(rec->substream);
208 spin_unlock(&rec->timer_lock);
219 struct snd_emu8k_pcm *rec;
222 rec = kzalloc(sizeof(*rec), GFP_KERNEL);
223 if (! rec)
226 rec->emu = emu;
227 rec->substream = subs;
228 runtime->private_data = rec;
230 spin_lock_init(&rec->timer_lock);
231 timer_setup(&rec->timer, emu8k_pcm_timer_func, 0);
246 struct snd_emu8k_pcm *rec = subs->runtime->private_data;
247 kfree(rec);
269 static void setup_voice(struct snd_emu8k_pcm *rec, int ch)
271 struct snd_emu8000 *hw = rec->emu;
282 EMU8000_IP_WRITE(hw, ch, rec->pitch);
303 temp = rec->panning[ch];
304 temp = (temp <<24) | ((unsigned int)rec->loop_start[ch] - 1);
308 temp = (temp << 24) | ((unsigned int)rec->loop_start[ch] + rec->buf_size - 1);
312 temp = (temp << 28) | ((unsigned int)rec->loop_start[ch] - 1);
322 static void start_voice(struct snd_emu8k_pcm *rec, int ch)
325 struct snd_emu8000 *hw = rec->emu;
327 int pt = calc_pitch_target(rec->pitch);
337 if (rec->panning[ch] == 0)
340 aux = (-rec->panning[ch]) & 0xff;
346 spin_lock_irqsave(&rec->timer_lock, flags);
347 if (! rec->timer_running) {
348 mod_timer(&rec->timer, jiffies + 1);
349 rec->timer_running = 1;
351 spin_unlock_irqrestore(&rec->timer_lock, flags);
357 static void stop_voice(struct snd_emu8k_pcm *rec, int ch)
360 struct snd_emu8000 *hw = rec->emu;
365 spin_lock_irqsave(&rec->timer_lock, flags);
366 if (rec->timer_running) {
367 del_timer(&rec->timer);
368 rec->timer_running = 0;
370 spin_unlock_irqrestore(&rec->timer_lock, flags);
375 struct snd_emu8k_pcm *rec = subs->runtime->private_data;
380 for (ch = 0; ch < rec->voices; ch++)
381 start_voice(rec, ch);
382 rec->running = 1;
385 rec->running = 0;
386 for (ch = 0; ch < rec->voices; ch++)
387 stop_voice(rec, ch);
435 #define LOOP_WRITE(rec, offset, _buf, count, mode) \
437 struct snd_emu8000 *emu = (rec)->emu; \
455 struct snd_emu8k_pcm *rec = subs->runtime->private_data;
458 pos = (pos << 1) + rec->loop_start[voice];
460 LOOP_WRITE(rec, pos, src, count, COPY_USER);
468 struct snd_emu8k_pcm *rec = subs->runtime->private_data;
471 pos = (pos << 1) + rec->loop_start[voice];
473 LOOP_WRITE(rec, pos, src, count, COPY_KERNEL);
481 struct snd_emu8k_pcm *rec = subs->runtime->private_data;
484 pos = (pos << 1) + rec->loop_start[voice];
486 LOOP_WRITE(rec, pos, NULL, count, FILL_SILENCE);
492 #define LOOP_WRITE(rec, pos, _buf, count, mode) \
494 struct snd_emu8000 *emu = rec->emu; \
497 EMU8000_SMALW_WRITE(emu, pos + rec->loop_start[0]); \
498 if (rec->voices > 1) \
499 EMU8000_SMARW_WRITE(emu, pos + rec->loop_start[1]); \
505 if (rec->voices > 1) { \
523 struct snd_emu8k_pcm *rec = subs->runtime->private_data;
528 LOOP_WRITE(rec, pos, src, count, COPY_USER);
536 struct snd_emu8k_pcm *rec = subs->runtime->private_data;
541 LOOP_WRITE(rec, pos, src, count, COPY_KERNEL);
548 struct snd_emu8k_pcm *rec = subs->runtime->private_data;
553 LOOP_WRITE(rec, pos, NULL, count, FILL_SILENCE);
565 struct snd_emu8k_pcm *rec = subs->runtime->private_data;
567 if (rec->block) {
569 snd_util_mem_free(rec->emu->memhdr, rec->block);
570 rec->block = NULL;
573 rec->allocated_bytes = params_buffer_bytes(hw_params) + LOOP_BLANK_SIZE * 4;
574 rec->block = snd_util_mem_alloc(rec->emu->memhdr, rec->allocated_bytes);
575 if (! rec->block)
577 rec->offset = EMU8000_DRAM_OFFSET + (rec->block->offset >> 1); /* in word */
589 struct snd_emu8k_pcm *rec = subs->runtime->private_data;
591 if (rec->block) {
593 for (ch = 0; ch < rec->voices; ch++)
594 stop_voice(rec, ch); // to be sure
595 if (rec->dram_opened)
596 emu8k_close_dram(rec->emu);
597 snd_util_mem_free(rec->emu->memhdr, rec->block);
598 rec->block = NULL;
607 struct snd_emu8k_pcm *rec = subs->runtime->private_data;
609 rec->pitch = 0xe000 + calc_rate_offset(subs->runtime->rate);
610 rec->last_ptr = 0;
611 rec->period_pos = 0;
613 rec->buf_size = subs->runtime->buffer_size;
614 rec->period_size = subs->runtime->period_size;
615 rec->voices = subs->runtime->channels;
616 rec->loop_start[0] = rec->offset + LOOP_BLANK_SIZE;
617 if (rec->voices > 1)
618 rec->loop_start[1] = rec->loop_start[0] + rec->buf_size + LOOP_BLANK_SIZE;
619 if (rec->voices > 1) {
620 rec->panning[0] = 0xff;
621 rec->panning[1] = 0x00;
623 rec->panning[0] = 0x80;
625 if (! rec->dram_opened) {
628 snd_emux_terminate_all(rec->emu->emu);
629 if ((err = emu8k_open_dram_for_pcm(rec->emu, rec->voices)) != 0)
631 rec->dram_opened = 1;
634 snd_emu8000_write_wait(rec->emu, 0);
635 EMU8000_SMALW_WRITE(rec->emu, rec->offset);
637 EMU8000_SMLD_WRITE(rec->emu, 0);
638 for (ch = 0; ch < rec->voices; ch++) {
639 EMU8000_SMALW_WRITE(rec->emu, rec->loop_start[ch] + rec->buf_size);
641 EMU8000_SMLD_WRITE(rec->emu, 0);
645 setup_voice(rec, 0);
646 if (rec->voices > 1)
647 setup_voice(rec, 1);
653 struct snd_emu8k_pcm *rec = subs->runtime->private_data;
654 if (rec->running)
655 return emu8k_get_curpos(rec, 0);