All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vinod Koul <vinod.koul@intel.com>
To: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Cc: alsa-devel@alsa-project.org, patches@opensource.wolfsonmicro.com,
	vinod.koul@linux.jf.intel.com
Subject: Re: [TINYCOMPRESS PATCH 1/2] crec: Initial version of a compressed capture utility
Date: Wed, 27 Nov 2013 13:38:24 +0530	[thread overview]
Message-ID: <20131127080824.GL8834@intel.com> (raw)
In-Reply-To: <1384879579-7790-1-git-send-email-ckeepax@opensource.wolfsonmicro.com>

On Tue, Nov 19, 2013 at 04:46:18PM +0000, Charles Keepax wrote:
> This version only supports capture of PCM streams over a compressed
> device and saves these as WAV files.
Thanks for posting this :) I was about to ping you ad get these done if you were
busy...


> +static void usage(void)
> +{
> +	fprintf(stderr, "usage: crec [OPTIONS] filename\n"
> +		"-c\tcard number\n"
> +		"-d\tdevice node\n"
> +		"-b\tbuffer size\n"
> +		"-f\tfragments\n"
> +		"-v\tverbose mode\n"
> +		"-l\tlength of record in seconds\n"
perhaps it would be more intutive for time. We cant use d here :(

> +		"-h\tPrints this help list\n\n"
> +		"-C\tSpecify the number of channels (default %u)\n"
> +		"-R\tSpecify the sample rate (default %u)\n"
can these be lower case?

> +		"-F\tSpecify the format: S16_LE, S32_LE (default S16_LE)\n\n"
> +		"Example:\n"
> +		"\tcrec -c 1 -d 2 test.wav\n"
> +		"\tcrec -f 5 test.wav\n",
> +		DEFAULT_CHANNELS, DEFAULT_RATE);
> +
> +	exit(EXIT_FAILURE);
> +}
> +
> +static int print_time(struct compress *compress)
> +{
> +	unsigned int avail;
> +	struct timespec tstamp;
> +
> +	if (compress_get_hpointer(compress, &avail, &tstamp) != 0) {
> +		fprintf(stderr, "Error querying timestamp\n");
> +		fprintf(stderr, "ERR: %s\n", compress_get_error(compress));
> +		return -1;
> +	} else {
> +		printf("DSP recorded %jd.%jd\n",
> +		       (intmax_t)tstamp.tv_sec, (intmax_t)tstamp.tv_nsec*1000);
> +	}
> +	return 0;
> +}
> +
> +void capture_samples(char *name, unsigned int card, unsigned int device,
> +		     unsigned long buffer_size, unsigned int frag,
> +		     unsigned int length, unsigned int rate,
> +		     unsigned int channels, unsigned int format)
> +{
> +	struct compr_config config;
> +	struct snd_codec codec;
> +	struct compress *compress;
> +	struct wave_header header;
> +	FILE *file;
> +	char *buffer;
> +	size_t written;
> +	int read, ret;
> +	unsigned int size, total_read = 0;
> +	unsigned int samplebits;
> +
> +	switch (format) {
> +	case SNDRV_PCM_FORMAT_S32_LE:
> +		samplebits = 32;
> +		break;
> +	default:
> +		samplebits = 16;
> +		break;
> +	}
> +
> +	/* Convert length from seconds to bytes */
> +	length = length * rate * (samplebits / 8) * channels;
> +
> +	if (verbose)
> +		printf("%s: entry, reading %u bytes\n", __func__, length);
> +
> +	file = fopen(name, "w+b");
why w+?

> +	if (!file) {
> +		fprintf(stderr, "Unable to open file '%s'\n", name);
> +		exit(EXIT_FAILURE);
> +	}
> +
> +	/* Write a header, will update with size once record is complete */
> +	init_wave_header(&header, channels, rate, samplebits);
> +	written = fwrite(&header, sizeof(header), 1, file);
> +	if (written != 1) {
> +		fprintf(stderr, "Error writing output file header: %d\n",
> +			ferror(file));
> +		goto file_exit;
> +	}
> +
> +	codec.id = SND_AUDIOCODEC_PCM;
> +	codec.ch_in = channels;
> +	codec.ch_out = channels;
> +	codec.sample_rate = compress_get_alsa_rate(rate);
> +	if (!codec.sample_rate) {
> +		fprintf(stderr, "invalid sample rate %d\n", rate);
> +		goto file_exit;
> +	}
> +	codec.bit_rate = 0;
> +	codec.rate_control = 0;
> +	codec.profile = 0;
> +	codec.level = 0;
> +	codec.ch_mode = 0;
> +	codec.format = format;
why not do memset of the codec and configure only what we need...


rest looks okay to me

--
~Vinod

  parent reply	other threads:[~2013-11-27  9:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-19 16:46 [TINYCOMPRESS PATCH 1/2] crec: Initial version of a compressed capture utility Charles Keepax
2013-11-19 16:46 ` [TINYCOMPRESS PATCH 2/2] crec: Add primitive exception handling Charles Keepax
2013-11-27  8:08 ` Vinod Koul [this message]
2013-12-03 16:09   ` [TINYCOMPRESS PATCH 1/2] crec: Initial version of a compressed capture utility Charles Keepax

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20131127080824.GL8834@intel.com \
    --to=vinod.koul@intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=ckeepax@opensource.wolfsonmicro.com \
    --cc=patches@opensource.wolfsonmicro.com \
    --cc=vinod.koul@linux.jf.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.