X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Falsa%2Fprotocol.c;h=6975d2fb8843df6415af96cf61fd8b34b6346f51;hb=3b15586812e47e885ed69e3cd1188b1ccf25f807;hp=2dfce2d1dfcaaa801ef2619a86dc85fab2c3a976;hpb=52ba6e05d59d6b2199214aed14330f213e79a593;p=libsigrok.git diff --git a/hardware/alsa/protocol.c b/hardware/alsa/protocol.c index 2dfce2d1..6975d2fb 100644 --- a/hardware/alsa/protocol.c +++ b/hardware/alsa/protocol.c @@ -39,8 +39,10 @@ static const unsigned int rates[] = { 5512, 8000, 11025, + 12000, 16000, 22050, + 24000, 32000, 44100, 48000, @@ -49,7 +51,8 @@ static const unsigned int rates[] = { 96000, 176400, 192000, - 384000, /* Yes, there are sound cards that go this high. */ + 384000, + 768000, /* Yes, there are sound cards that go this high. */ }; static void alsa_scan_handle_dev(GSList **devices, @@ -60,7 +63,7 @@ static void alsa_scan_handle_dev(GSList **devices, struct drv_context *drvc = NULL; struct sr_dev_inst *sdi = NULL; struct dev_context *devc = NULL; - struct sr_probe *probe; + struct sr_channel *ch; int ret; unsigned int i, offset, channels, minrate, maxrate, rate; uint64_t hwrates[ARRAY_SIZE(rates)]; @@ -73,7 +76,7 @@ static void alsa_scan_handle_dev(GSList **devices, /* * Get hardware parameters: - * The number of channels, for example, are our sigrok probes. Getting + * The number of channels, for example, are our sigrok channels. Getting * this information needs a detour. We need to open the device, then * query it and/or test different parameters. A side-effect of is that * we create a snd_pcm_hw_params_t object. We take advantage of the @@ -146,19 +149,19 @@ static void alsa_scan_handle_dev(GSList **devices, } devc->hwdev = g_strdup(alsaname); - devc->num_probes = channels; + devc->num_channels = channels; devc->hw_params = hw_params; memcpy(devrates, hwrates, offset * sizeof(uint64_t)); - devc->supp_rates.list = devrates; + devc->samplerates = devrates; sdi->priv = devc; sdi->driver = di; - for (i = 0; i < devc->num_probes; i++) { + for (i = 0; i < devc->num_channels; i++) { snprintf(p_name, sizeof(p_name), "Ch_%d", i); - if (!(probe = sr_probe_new(0, SR_PROBE_ANALOG, TRUE, p_name))) + if (!(ch = sr_channel_new(i, SR_CHANNEL_ANALOG, TRUE, p_name))) goto scan_error_cleanup; - sdi->probes = g_slist_append(sdi->probes, probe); + sdi->channels = g_slist_append(sdi->channels, ch); } drvc->instances = g_slist_append(drvc->instances, sdi); @@ -199,8 +202,8 @@ scan_error_cleanup: * * We don't currently look at alsa subdevices. We only use subdevice 0. * Every input device will have its own channels (left, right, etc). Each of - * those channels gets mapped to a different sigrok probe. A device with 4 - * channels will have 4 probes from sigrok's perspective. + * those channels gets mapped to a different sigrok channel. A device with 4 + * channels will have 4 channels from sigrok's perspective. */ SR_PRIV GSList *alsa_scan(GSList *options, struct sr_dev_driver *di) { @@ -216,11 +219,11 @@ SR_PRIV GSList *alsa_scan(GSList *options, struct sr_dev_driver *di) (void)options; if ((ret = snd_ctl_card_info_malloc(&info)) < 0) { - sr_err("Failed to malloc card info: %s.", snd_strerror(ret)); + sr_dbg("Failed to malloc card info: %s.", snd_strerror(ret)); return NULL; } if ((ret = snd_pcm_info_malloc(&pcminfo) < 0)) { - sr_err("Cannot malloc pcm info: %s.", snd_strerror(ret)); + sr_dbg("Cannot malloc pcm info: %s.", snd_strerror(ret)); return NULL; } @@ -228,14 +231,14 @@ SR_PRIV GSList *alsa_scan(GSList *options, struct sr_dev_driver *di) while (snd_card_next(&card) >= 0 && card >= 0) { snprintf(hwcard, sizeof(hwcard), "hw:%d", card); if ((ret = snd_ctl_open(&handle, hwcard, 0)) < 0) { - sr_err("Cannot open (%d): %s.", card, snd_strerror(ret)); + sr_dbg("Cannot open (%d): %s.", card, snd_strerror(ret)); continue; } if ((ret = snd_ctl_card_info(handle, info)) < 0) { - sr_err("Cannot get hardware info (%d): %s.", + sr_dbg("Cannot get hardware info (%d): %s.", card, snd_strerror(ret)); if ((ret = snd_ctl_close(handle)) < 0) { - sr_err("Cannot close device (%d): %s.", + sr_dbg("Cannot close device (%d): %s.", card, snd_strerror(ret)); } continue; @@ -253,7 +256,7 @@ SR_PRIV GSList *alsa_scan(GSList *options, struct sr_dev_driver *di) snd_pcm_info_set_stream(pcminfo, SND_PCM_STREAM_CAPTURE); if ((ret = snd_ctl_pcm_info(handle, pcminfo)) < 0) { - sr_err("Cannot get device info (%s): %s.", + sr_dbg("Cannot get device info (%s): %s.", hwdev, snd_strerror(ret)); continue; } @@ -268,7 +271,7 @@ SR_PRIV GSList *alsa_scan(GSList *options, struct sr_dev_driver *di) di, pcminfo); } if ((ret = snd_ctl_close(handle)) < 0) { - sr_err("Cannot close device (%d): %s.", + sr_dbg("Cannot close device (%d): %s.", card, snd_strerror(ret)); } } @@ -279,22 +282,6 @@ SR_PRIV GSList *alsa_scan(GSList *options, struct sr_dev_driver *di) return devices; } -/* - * Helper to be used with g_slist_free_full(); for properly freeing an alsa - * dev instance. - */ -SR_PRIV void alsa_dev_inst_clear(struct sr_dev_inst *sdi) -{ - struct dev_context *devc; - - if (!(devc = sdi->priv)) - return; - - snd_pcm_hw_params_free(devc->hw_params); - g_free((void*)devc->supp_rates.list); - sr_dev_inst_free(sdi); -} - /** * Set the samplerate of the ALSA device. * @@ -323,14 +310,14 @@ SR_PRIV int alsa_set_samplerate(const struct sr_dev_inst *sdi, i = 0; do { - if (newrate == devc->supp_rates.list[i]) { + if (newrate == devc->samplerates[i]) { rate = newrate; break; } - } while (devc->supp_rates.list[i++] != 0); + } while (devc->samplerates[i++] != 0); if (!rate) { - sr_err("Sample rate " PRIu64 " not supported.", newrate); + sr_err("Sample rate %" PRIu64 " not supported.", newrate); return SR_ERR_ARG; } @@ -370,7 +357,7 @@ SR_PRIV int alsa_receive_data(int fd, int revents, void *cb_data) sr_spew("Only got %d/%d samples.", count, samples_to_get); } - analog.data = g_try_malloc0(count * sizeof(float) * devc->num_probes); + analog.data = g_try_malloc0(count * sizeof(float) * devc->num_channels); if (!analog.data) { sr_err("Failed to malloc sample buffer."); return FALSE; @@ -385,14 +372,15 @@ SR_PRIV int alsa_receive_data(int fd, int revents, void *cb_data) * audio data as a normalized float, and let the frontend or user worry * about the calibration. */ - for (i = 0; i < count; i += devc->num_probes) { - for (x = 0; x < devc->num_probes; x++) { + for (i = 0; i < count; i += devc->num_channels) { + for (x = 0; x < devc->num_channels; x++) { tmp16 = inbuf[i + x]; analog.data[offset++] = tmp16 * s16norm; } } /* Send a sample packet with the analog values. */ + analog.channels = sdi->channels; analog.num_samples = count; analog.mq = SR_MQ_VOLTAGE; /* FIXME */ analog.unit = SR_UNIT_VOLT; /* FIXME */