From: Daniel Ribeiro Date: Sat, 22 Jan 2011 14:21:04 +0000 (-0200) Subject: finish alsa driver implementation X-Git-Tag: libsigrok-0.1.0~382 X-Git-Url: https://sigrok.org/gitweb/?a=commitdiff_plain;h=58330ab892c64461a73471a197fd8816630944a9;p=libsigrok.git finish alsa driver implementation Yes, it works now. --- diff --git a/hardware/alsa/alsa.c b/hardware/alsa/alsa.c index 68faa5db..b41d8ed3 100644 --- a/hardware/alsa/alsa.c +++ b/hardware/alsa/alsa.c @@ -199,27 +199,56 @@ static int hw_set_configuration(int device_index, int capability, void *value) } } -/* - * FIXME: This is incomplete, i couldn't get poll() to work with alsa fds yet. - */ static int receive_data(int fd, int revents, void *user_data) { struct sigrok_device_instance *sdi = user_data; struct alsa *alsa = sdi->priv; struct datafeed_packet packet; - char buf[128]; - int i, err; - - g_warning("entered receive_data"); + struct analog_sample *sample; + unsigned int sample_size = sizeof(struct analog_sample) + + (NUM_PROBES * sizeof(struct analog_probe)); + char *outb; + char inb[4096]; + int i, x, count; + + do { + memset(inb, 0, sizeof(inb)); + count = snd_pcm_readi(alsa->capture_handle, inb, + MIN(4096/4, alsa->limit_samples)); + if (count < 1) { + g_warning("Failed to read samples"); + return FALSE; + } - for (i = 0; i < 10; i++) { - if ((err = snd_pcm_readi(alsa->capture_handle, buf, 128)) != 128) { - g_warning("read from audio interface failed (%s)\n", - snd_strerror(err)); + outb = malloc(sample_size * count); + if (!outb) return FALSE; + + for (i = 0; i < count; i++) { + sample = (struct analog_sample *) + (outb + (i * sample_size)); + sample->num_probes = NUM_PROBES; + + for (x = 0; x < NUM_PROBES; x++) { + sample->probes[x].val = + *(uint16_t *) (inb + (i * 4) + (x * 2)); + sample->probes[x].val &= ((1 << 16) - 1); + sample->probes[x].res = 16; + } } - g_warning("data read ok"); - } + + packet.type = DF_ANALOG; + packet.length = count * sample_size; + packet.unitsize = sample_size; + packet.payload = outb; + session_bus(user_data, &packet); + free(outb); + alsa->limit_samples -= count; + + } while (alsa->limit_samples > 0); + + packet.type = DF_END; + session_bus(user_data, &packet); return TRUE; } @@ -299,7 +328,7 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id) } alsa->session_id = session_device_id; - source_add(ufds[0].fd, ufds[0].revents, -1, receive_data, sdi); + source_add(ufds[0].fd, ufds[0].events, 10, receive_data, sdi); packet.type = DF_HEADER; packet.length = sizeof(struct datafeed_header);