static int write_audio (GUSState *s, int samples) { int net = 0; int pos = s->pos; while (samples) { int nbytes, wbytes, wsampl; nbytes = samples << s->shift; wbytes = AUD_write ( s->voice, s->mixbuf + (pos << (s->shift - 1)), nbytes ); if (wbytes) { wsampl = wbytes >> s->shift; samples -= wsampl; pos = (pos + wsampl) % s->samples; net += wsampl; } else { break; } }
static void hda_audio_output_cb(void *opaque, int avail) { HDAAudioStream *st = opaque; int sent = 0; int len; bool rc; while (avail - sent >= sizeof(st->buf)) { if (st->bpos == sizeof(st->buf)) { rc = hda_codec_xfer(&st->state->hda, st->stream, true, st->buf, sizeof(st->buf)); if (!rc) { break; } st->bpos = 0; } len = AUD_write(st->voice.out, st->buf + st->bpos, sizeof(st->buf) - st->bpos); st->bpos += len; sent += len; if (st->bpos != sizeof(st->buf)) { break; } } }
static int cs_write_audio (CSState *s, int nchan, int dma_pos, int dma_len, int len) { int temp, net; uint8_t tmpbuf[4096]; temp = len; net = 0; while (temp) { int left = dma_len - dma_pos; int copied; size_t to_copy; to_copy = audio_MIN (temp, left); if (to_copy > sizeof (tmpbuf)) { to_copy = sizeof (tmpbuf); } copied = DMA_read_memory (nchan, tmpbuf, dma_pos, to_copy); if (s->tab) { int i; int16_t linbuf[4096]; for (i = 0; i < copied; ++i) linbuf[i] = s->tab[tmpbuf[i]]; copied = AUD_write (s->voice, linbuf, copied << 1); copied >>= 1; } else {
static int virtio_audio_fill(VirtIOAudioStream *stream, int offset, int total_len) { uint8_t *p; int to_write; int written; int size; int n; struct iovec *iov; int iov_len; if (stream->in_voice) { iov_len = stream->elem.in_num; iov = stream->elem.in_sg; } else if (stream->out_voice) { iov_len = stream->elem.out_num; iov = stream->elem.out_sg; } else { DPRINTF("No voice selected skipping block\n"); return 0; } written = 0; for (n = 0; total_len > 0 && n < iov_len; n++) { p = iov[n].iov_base; to_write = iov[n].iov_len; if (offset) { if (offset >= to_write) { offset -= to_write; continue; } p += offset; to_write -= offset; offset = 0; } if (to_write > total_len) to_write = total_len; while (to_write) { if (stream->in_voice) { size = AUD_read(stream->in_voice, p, to_write); } else if (stream->out_voice) { size = AUD_write(stream->out_voice, p, to_write); } else { size = 0; } DPRINTF("Copied %d/%d\n", size, to_write); if (size == 0) { total_len = 0; break; } to_write -= size; total_len -= size; written += size; } } return written; }
static int goldfish_audio_buff_send( struct goldfish_audio_buff* b, int free, struct goldfish_audio_state* s ) { int ret, write = b->length; if (write > free) write = free; ret = AUD_write(s->voice, b->data + b->offset, write); b->offset += ret; b->length -= ret; return ret; }
static void output_callback(void *opaque, int avail) { USBAudioState *s = opaque; uint8_t *data; for (;;) { if (avail < USBAUDIO_PACKET_SIZE) { return; } data = streambuf_get(&s->out.buf); if (!data) { return; } AUD_write(s->out.voice, data, USBAUDIO_PACKET_SIZE); avail -= USBAUDIO_PACKET_SIZE; } }
static void ac97_out_cb(void *opaque, int free_b) { MilkymistAC97State *s = opaque; uint8_t buf[4096]; uint32_t remaining = s->regs[R_D_REMAINING]; int temp = audio_MIN(remaining, free_b); uint32_t addr = s->regs[R_D_ADDR]; int transferred = 0; trace_milkymist_ac97_out_cb(free_b, remaining); /* prevent from raising an IRQ */ if (temp == 0) { return; } while (temp) { int copied, to_copy; to_copy = audio_MIN(temp, sizeof(buf)); cpu_physical_memory_read(addr, buf, to_copy); copied = AUD_write(s->voice_out, buf, to_copy); if (!copied) { break; } temp -= copied; addr += copied; transferred += copied; } trace_milkymist_ac97_out_cb_transferred(transferred); s->regs[R_D_ADDR] = addr; s->regs[R_D_REMAINING] -= transferred; if ((s->regs[R_D_CTRL] & CTRL_EN) && (s->regs[R_D_REMAINING] == 0)) { trace_milkymist_ac97_pulse_irq_dmar(); qemu_irq_pulse(s->dmar_irq); } }
if (to_copy > sizeof (tmpbuf)) { to_copy = sizeof (tmpbuf); } copied = DMA_read_memory (nchan, tmpbuf, dma_pos, to_copy); if (s->tab) { int i; int16_t linbuf[4096]; for (i = 0; i < copied; ++i) linbuf[i] = s->tab[tmpbuf[i]]; copied = AUD_write (s->voice, linbuf, copied << 1); copied >>= 1; } else { copied = AUD_write (s->voice, tmpbuf, copied); } temp -= copied; dma_pos = (dma_pos + copied) % dma_len; net += copied; if (!copied) { break; } } return net; } static int cs_dma_read (void *opaque, int nchan, int dma_pos, int dma_len)