Exemplo n.º 1
0
static int read_file(struct ausrc_st *st)
{
	struct mbuf *mb;
	int err;

	for (;;) {

		mb = mbuf_alloc(4096);
		if (!mb)
			return ENOMEM;

		mb->end = mb->size;

		err = aufile_read(st->aufile, mb->buf, &mb->end);
		if (err)
			break;

		if (mb->end == 0) {
			info("aufile: end of file\n");
			break;
		}

		aubuf_append(st->aubuf, mb);

		mb = mem_deref(mb);
	}

	info("aufile: loaded %zu bytes\n", aubuf_cur_size(st->aubuf));

	mem_deref(mb);
	return err;
}
Exemplo n.º 2
0
static int read_file(struct ausrc_st *st)
{
	struct mbuf *mb;
	int err;

	for (;;) {
		uint16_t *sampv;
		size_t i;

		mb = mbuf_alloc(4096);
		if (!mb)
			return ENOMEM;

		mb->end = mb->size;

		err = aufile_read(st->aufile, mb->buf, &mb->end);
		if (err)
			break;

		if (mb->end == 0) {
			info("aufile: end of file\n");
			break;
		}

		/* convert from Little-Endian to Native-Endian */
		sampv = (void *)mb->buf;
		for (i=0; i<mb->end/2; i++) {
			sampv[i] = sys_ltohs(sampv[i]);
		}

		aubuf_append(st->aubuf, mb);

		mb = mem_deref(mb);
	}

	info("aufile: loaded %zu bytes\n", aubuf_cur_size(st->aubuf));

	mem_deref(mb);
	return err;
}
Exemplo n.º 3
0
static inline int decode(struct ausrc_st *st)
{
	int err, ch, encoding;
	struct mbuf *mb;
	long srate;

	mb = mbuf_alloc(4096);
	if (!mb)
		return ENOMEM;

	err = mpg123_read(st->mp3, mb->buf, mb->size, &mb->end);

	switch (err) {

	case MPG123_NEW_FORMAT:
		mpg123_getformat(st->mp3, &srate, &ch, &encoding);
		info("rst: new format: %i hz, %i ch, encoding 0x%04x\n",
		     srate, ch, encoding);
		/*@fallthrough@*/

	case MPG123_OK:
	case MPG123_NEED_MORE:
		if (mb->end == 0)
			break;
		aubuf_append(st->aubuf, mb);
		break;

	default:
		warning("rst: mpg123_read error: %s\n",
			mpg123_plain_strerror(err));
		break;
	}

	mem_deref(mb);

	return err;
}