int main() { clear_screen(); copy_file(INPUT_FILE, OUTPUT_FILE); write2console(OUTPUT_FILE); write2printer(OUTPUT_FILE); write2serial(OUTPUT_FILE); truncate_file(OUTPUT_FILE); write_midi(); wait_enter(); return 0; }
static void snd_echo_midi_output_write(unsigned long data) { struct echoaudio *chip = (struct echoaudio *)data; unsigned long flags; int bytes, sent, time; unsigned char buf[MIDI_OUT_BUFFER_SIZE - 1]; DE_MID(("snd_echo_midi_output_write\n")); /* No interrupts are involved: we have to check at regular intervals if the card's output buffer has room for new data. */ sent = bytes = 0; spin_lock_irqsave(&chip->lock, flags); chip->midi_full = 0; if (!snd_rawmidi_transmit_empty(chip->midi_out)) { bytes = snd_rawmidi_transmit_peek(chip->midi_out, buf, MIDI_OUT_BUFFER_SIZE - 1); DE_MID(("Try to send %d bytes...\n", bytes)); sent = write_midi(chip, buf, bytes); if (sent < 0) { dev_err(chip->card->dev, "write_midi() error %d\n", sent); /* retry later */ sent = 9000; chip->midi_full = 1; } else if (sent > 0) { DE_MID(("%d bytes sent\n", sent)); snd_rawmidi_transmit_ack(chip->midi_out, sent); } else { /* Buffer is full. DSP's internal buffer is 64 (128 ?) bytes long. Let's wait until half of them are sent */ DE_MID(("Full\n")); sent = 32; chip->midi_full = 1; } } /* We restart the timer only if there is some data left to send */ if (!snd_rawmidi_transmit_empty(chip->midi_out) && chip->tinuse) { /* The timer will expire slightly after the data has been sent */ time = (sent << 3) / 25 + 1; /* 8/25=0.32ms to send a byte */ mod_timer(&chip->timer, jiffies + (time * HZ + 999) / 1000); DE_MID(("Timer armed(%d)\n", ((time * HZ + 999) / 1000))); } spin_unlock_irqrestore(&chip->lock, flags); }