Actually I want to perform sequential audio recordings with a fixed duration, compress the tracks and send them via ftp to a remote location. I want the minimum gap possible between successive tracks. I mean that when the first track ends, recording the second track has to be initiated almost immediately. Simply calling arecord on a periodical basis introduces some gaps between tracks because I suppose the audio device has to be opened and closed every time and configured with the recording parameters. If I make the period I call arecord equal to the recording period I receive errors from the audio device that indicate that it is not yet ready from the previous recording. So I thought of using a custom program like this, in which every x seconds I could create a wav file. At the same time, the contents of the buffer would be directly available for the new recording, minimizing losses. Regards, Konstantinos O/H Sergei Steshenko έγραψε: > > 18 июля 2011, 22:52 от kmpirkos@xxxxxxxxxxxxxx: > >> >> 18 июля 2011, 22:52 от kmpirkos@xxxxxxxxxxxxxx: >> >>> Hello all, >>> >>> I'm looking for a way to modify the alsa recording example found here >>> http://www.linuxjournal.com/article/6735?page=0,2 and shown below (or use any >>> other sample program you may suggest), in order to produce a wav file rather >>> than send the buffer contents to the standard output. I want to do something >>> very specific, so using the arecord utility is not an option for me. Any help? >>> >>> Thank you in advance >>> >>> #define ALSA_PCM_NEW_HW_PARAMS_API >>> >>> #include <alsa/asoundlib.h> >>> >>> int main() { >>> long loops; >>> int rc; >>> int size; >>> snd_pcm_t *handle; >>> snd_pcm_hw_params_t *params; >>> unsigned int val; >>> int dir; >>> snd_pcm_uframes_t frames; >>> char *buffer; >>> >>> /* Open PCM device for recording (capture). */ >>> rc = snd_pcm_open(&handle, "default", >>> SND_PCM_STREAM_CAPTURE, 0); >>> if (rc < 0) { >>> fprintf(stderr, >>> "unable to open pcm device: %s\n", >>> snd_strerror(rc)); >>> exit(1); >>> } >>> >>> /* Allocate a hardware parameters object. */ >>> snd_pcm_hw_params_alloca(¶ms); >>> >>> /* Fill it in with default values. */ >>> snd_pcm_hw_params_any(handle, params); >>> >>> /* Set the desired hardware parameters. */ >>> >>> /* Interleaved mode */ >>> snd_pcm_hw_params_set_access(handle, params, >>> SND_PCM_ACCESS_RW_INTERLEAVED); >>> >>> /* Signed 16-bit little-endian format */ >>> snd_pcm_hw_params_set_format(handle, params, >>> SND_PCM_FORMAT_S16_LE); >>> >>> /* Two channels (stereo) */ >>> snd_pcm_hw_params_set_channels(handle, params, 2); >>> >>> /* 44100 bits/second sampling rate (CD quality) */ >>> val = 44100; >>> snd_pcm_hw_params_set_rate_near(handle, params, >>> &val, &dir); >>> >>> /* Set period size to 32 frames. */ >>> frames = 32; >>> snd_pcm_hw_params_set_period_size_near(handle, >>> params, &frames, &dir); >>> >>> /* Write the parameters to the driver */ >>> rc = snd_pcm_hw_params(handle, params); >>> if (rc < 0) { >>> fprintf(stderr, >>> "unable to set hw parameters: %s\n", >>> snd_strerror(rc)); >>> exit(1); >>> } >>> >>> /* Use a buffer large enough to hold one period */ >>> snd_pcm_hw_params_get_period_size(params, >>> &frames, &dir); >>> size = frames * 4; /* 2 bytes/sample, 2 channels */ >>> buffer = (char *) malloc(size); >>> >>> /* We want to loop for 5 seconds */ >>> snd_pcm_hw_params_get_period_time(params, >>> &val, &dir); >>> loops = 5000000 / val; >>> >>> while (loops > 0) { >>> loops--; >>> rc = snd_pcm_readi(handle, buffer, frames); >>> if (rc == -EPIPE) { >>> /* EPIPE means overrun */ >>> fprintf(stderr, "overrun occurred\n"); >>> snd_pcm_prepare(handle); >>> } else if (rc < 0) { >>> fprintf(stderr, >>> "error from read: %s\n", >>> snd_strerror(rc)); >>> } else if (rc != (int)frames) { >>> fprintf(stderr, "short read, read %d frames\n", rc); >>> } >>> rc = write(1, buffer, size); >>> if (rc != size) >>> fprintf(stderr, >>> "short write: wrote %d bytes\n", rc); >>> } >>> >>> snd_pcm_drain(handle); >>> snd_pcm_close(handle); >>> free(buffer); >>> >>> return 0; >>> } >>> >>> ------------------------------------------------------------------------------ >>> > > > Study SoX: sox.sf.net . Or 'ecasound': http://www.eca.cx/ecasound/ . > > But better first explain what is wrong with 'arecord'. > > Regards, > Sergei. > > -- Konstantinos Birkos PhD Candidate Wireless Telecommunication Laboratory Department of Electrical and Computer Engineering University of Patras Patras, Greece Tel.: +30 2610 996465 ------------------------------------------------------------------------------ Magic Quadrant for Content-Aware Data Loss Prevention Research study explores the data loss prevention market. Includes in-depth analysis on the changes within the DLP market, and the criteria used to evaluate the strengths and weaknesses of these DLP solutions. http://www.accelacomm.com/jaw/sfnl/114/51385063/ _______________________________________________ Alsa-user mailing list Alsa-user@xxxxxxxxxxxxxxxxxxxxx https://lists.sourceforge.net/lists/listinfo/alsa-user