finish alsa driver implementation

Yes, it works now.
This commit is contained in:
Daniel Ribeiro 2011-01-22 12:21:04 -02:00
parent 6ea7e23526
commit 58330ab892
1 changed files with 43 additions and 14 deletions

View File

@ -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) static int receive_data(int fd, int revents, void *user_data)
{ {
struct sigrok_device_instance *sdi = user_data; struct sigrok_device_instance *sdi = user_data;
struct alsa *alsa = sdi->priv; struct alsa *alsa = sdi->priv;
struct datafeed_packet packet; struct datafeed_packet packet;
char buf[128]; struct analog_sample *sample;
int i, err; unsigned int sample_size = sizeof(struct analog_sample) +
(NUM_PROBES * sizeof(struct analog_probe));
char *outb;
char inb[4096];
int i, x, count;
g_warning("entered receive_data"); do {
memset(inb, 0, sizeof(inb));
for (i = 0; i < 10; i++) { count = snd_pcm_readi(alsa->capture_handle, inb,
if ((err = snd_pcm_readi(alsa->capture_handle, buf, 128)) != 128) { MIN(4096/4, alsa->limit_samples));
g_warning("read from audio interface failed (%s)\n", if (count < 1) {
snd_strerror(err)); g_warning("Failed to read samples");
return FALSE; return FALSE;
} }
g_warning("data read ok");
} 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;
}
}
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; return TRUE;
} }
@ -299,7 +328,7 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id)
} }
alsa->session_id = 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.type = DF_HEADER;
packet.length = sizeof(struct datafeed_header); packet.length = sizeof(struct datafeed_header);