[alsa-devel] PCM parameters in file plugin
Hello,
I am working on a file plugin patch to allow adding PCM parameters (rate, format) to the name of the file created (plus the ability to run an external command via popen, such as upsampling with sox). I got stuck in trying to obtain these parameters in pcm_file.c:_snd_pcm_file_open(). Is it actually possible or the information is not available at the time of opening the file (and the whole patch is thus nonsense)?
Thanks a lot for help.
Pavel.
Pavel Hofman napsal(a):
Hello,
I am working on a file plugin patch to allow adding PCM parameters (rate, format) to the name of the file created (plus the ability to run an external command via popen, such as upsampling with sox). I got stuck in trying to obtain these parameters in pcm_file.c:_snd_pcm_file_open(). Is it actually possible or the information is not available at the time of opening the file (and the whole patch is thus nonsense)?
Thanks a lot for help.
I am now opening the output file in pcm_file.c:snd_pcm_file_write_bytes. Surprisingly it seems to work fine. Could such hack be accepted as a patch to the plugin (if coded properly)? Is there a better place to open the file?
Thanks,
Pavel.
On Tue, 6 Jan 2009, Pavel Hofman wrote:
Pavel Hofman napsal(a):
Hello,
I am working on a file plugin patch to allow adding PCM parameters (rate, format) to the name of the file created (plus the ability to run an external command via popen, such as upsampling with sox). I got stuck in trying to obtain these parameters in pcm_file.c:_snd_pcm_file_open(). Is it actually possible or the information is not available at the time of opening the file (and the whole patch is thus nonsense)?
Thanks a lot for help.
I am now opening the output file in pcm_file.c:snd_pcm_file_write_bytes. Surprisingly it seems to work fine. Could such hack be accepted as a patch to the plugin (if coded properly)? Is there a better place to open the file?
The file should be opened in the hw_params callback (all PCM parameters are known in this time). Also, extending filename with PCM parameters should be optional (configurable). But the idea looks nice.
Jaroslav
----- Jaroslav Kysela perex@perex.cz Linux Kernel Sound Maintainer ALSA Project, Red Hat, Inc.
Jaroslav Kysela wrote:
On Tue, 6 Jan 2009, Pavel Hofman wrote:
Pavel Hofman napsal(a):
Hello,
I am working on a file plugin patch to allow adding PCM parameters (rate, format) to the name of the file created (plus the ability to run an external command via popen, such as upsampling with sox). I got stuck in trying to obtain these parameters in pcm_file.c:_snd_pcm_file_open(). Is it actually possible or the information is not available at the time of opening the file (and the whole patch is thus nonsense)?
Thanks a lot for help.
I am now opening the output file in pcm_file.c:snd_pcm_file_write_bytes. Surprisingly it seems to work fine. Could such hack be accepted as a patch to the plugin (if coded properly)? Is there a better place to open the file?
The file should be opened in the hw_params callback (all PCM parameters are known in this time). Also, extending filename with PCM parameters should be optional (configurable). But the idea looks nice.
Jaroslav
Hi,
Thanks a lot for your hint. Here is a preliminary version of the patch for review (no docs updated, no clean formatting).
The changes are moving the opening of output file to hw_params callback, support for replacement codes in the file parameter, and support for piping to external commands when the file parameter starts with |.
This is a working ".asoundrc on steroids" (upsampling to 96kHz using the quality algorithm of sox)
pcm.raw { type file slave { pcm null } format "raw" file "| sox -V -c %c -%b -r %r -s -t raw - -t raw -4 - rate -v -s 96000 | aplay -v -t raw -r 96000 -c %c -f S32_LE -Dhw:0" }
Thanks a lot for comments.
Regards,
Pavel.
Pavel Hofman wrote:
Jaroslav Kysela wrote:
On Tue, 6 Jan 2009, Pavel Hofman wrote:
Pavel Hofman napsal(a):
Hello,
I am working on a file plugin patch to allow adding PCM parameters (rate, format) to the name of the file created (plus the ability to run an external command via popen, such as upsampling with sox). I got stuck in trying to obtain these parameters in pcm_file.c:_snd_pcm_file_open(). Is it actually possible or the information is not available at the time of opening the file (and the whole patch is thus nonsense)?
Thanks a lot for help.
I am now opening the output file in pcm_file.c:snd_pcm_file_write_bytes. Surprisingly it seems to work fine. Could such hack be accepted as a patch to the plugin (if coded properly)? Is there a better place to open the file?
The file should be opened in the hw_params callback (all PCM parameters are known in this time). Also, extending filename with PCM parameters should be optional (configurable). But the idea looks nice.
Jaroslav
Hello,
please find enclosed a patch for the file plugin. The checkpatch.pl script throws 5 bogus errors in doxygen comments.
Signed-off-by: Pavel Hofman pavel.hofman@insite.cz
* added support for including pcm stream params in the output filename * added support for piping the stream to a shell command if the filename string starts with a pipe char
Thanks a lot,
Pavel.
Pavel Hofman wrote:
Pavel Hofman wrote:
Jaroslav Kysela wrote:
On Tue, 6 Jan 2009, Pavel Hofman wrote:
Pavel Hofman napsal(a):
Hello,
I am working on a file plugin patch to allow adding PCM parameters (rate, format) to the name of the file created (plus the ability to run an external command via popen, such as upsampling with sox). I got stuck in trying to obtain these parameters in pcm_file.c:_snd_pcm_file_open(). Is it actually possible or the information is not available at the time of opening the file (and the whole patch is thus nonsense)?
Thanks a lot for help.
I am now opening the output file in pcm_file.c:snd_pcm_file_write_bytes. Surprisingly it seems to work fine. Could such hack be accepted as a patch to the plugin (if coded properly)? Is there a better place to open the file?
The file should be opened in the hw_params callback (all PCM parameters are known in this time). Also, extending filename with PCM parameters should be optional (configurable). But the idea looks nice.
Jaroslav
Hello,
please find enclosed a patch for the file plugin. The checkpatch.pl script throws 5 bogus errors in doxygen comments.
Signed-off-by: Pavel Hofman pavel.hofman@insite.cz
- added support for including pcm stream params in the output filename
- added support for piping the stream to a shell command if the filename
string starts with a pipe char
Thanks a lot,
Pavel.
Hi,
Please let me know if there some areas to work on before the patch can be accepted for merge.
Thanks a lot,
Pavel.
At Mon, 19 Jan 2009 23:20:49 +0100, Pavel Hofman wrote:
@@ -84,6 +106,211 @@ typedef struct { #define TO_LE16(x) bswap_16(x) #endif
+/* old_string MUST contain the key! */ +int snd_pcm_file_replace_key(char *old_string, char *key, char *value,
char **newstring_p)
Make this static.
+{
- int str_index, newstr_index, key_index, end, new_len, old_len, cpy_len,
first_key_index;
- char *c, *first_c, *newstring;
- int keys_count;
- first_c = c = (char *) strstr(old_string, key);
I guess this parser doesn't handle '%%' properly like printf()?
+int snd_pcm_file_replace_fname(snd_pcm_file_t *file, char **new_fname_p)
Make it static.
+int snd_pcm_file_has_keys(char *string)
Ditto.
+int snd_pcm_file_open_output_file(snd_pcm_file_t *file)
Ditto.
- if (file->final_fname[0] == '|') {
/* pipe mode */
FILE *pipe;
/* clearing */
file->final_fname[0] = ' ';
pipe = popen(file->final_fname, "w");
Pass "file->final_fname + 1", and you don't have to replace the pipe with a space.
thanks,
Takashi
Takashi Iwai wrote:
At Mon, 19 Jan 2009 23:20:49 +0100, Pavel Hofman wrote:
@@ -84,6 +106,211 @@ typedef struct { #define TO_LE16(x) bswap_16(x) #endif
+/* old_string MUST contain the key! */ +int snd_pcm_file_replace_key(char *old_string, char *key, char *value,
char **newstring_p)
Make this static.
+{
- int str_index, newstr_index, key_index, end, new_len, old_len, cpy_len,
first_key_index;
- char *c, *first_c, *newstring;
- int keys_count;
- first_c = c = (char *) strstr(old_string, key);
I guess this parser doesn't handle '%%' properly like printf()?
+int snd_pcm_file_replace_fname(snd_pcm_file_t *file, char **new_fname_p)
Make it static.
+int snd_pcm_file_has_keys(char *string)
Ditto.
+int snd_pcm_file_open_output_file(snd_pcm_file_t *file)
Ditto.
- if (file->final_fname[0] == '|') {
/* pipe mode */
FILE *pipe;
/* clearing */
file->final_fname[0] = ' ';
pipe = popen(file->final_fname, "w");
Pass "file->final_fname + 1", and you don't have to replace the pipe with a space.
thanks,
Takashi
Hi Takashi,
Thanks a lot for your comments.
Please find enclosed a reworked patch which reflects your requests including the %% functionality.
Thanks,
Pavel.
At Thu, 29 Jan 2009 00:00:08 +0100, Pavel Hofman wrote:
Takashi Iwai wrote:
At Mon, 19 Jan 2009 23:20:49 +0100, Pavel Hofman wrote:
@@ -84,6 +106,211 @@ typedef struct { #define TO_LE16(x) bswap_16(x) #endif
+/* old_string MUST contain the key! */ +int snd_pcm_file_replace_key(char *old_string, char *key, char *value,
char **newstring_p)
Make this static.
+{
- int str_index, newstr_index, key_index, end, new_len, old_len, cpy_len,
first_key_index;
- char *c, *first_c, *newstring;
- int keys_count;
- first_c = c = (char *) strstr(old_string, key);
I guess this parser doesn't handle '%%' properly like printf()?
+int snd_pcm_file_replace_fname(snd_pcm_file_t *file, char **new_fname_p)
Make it static.
+int snd_pcm_file_has_keys(char *string)
Ditto.
+int snd_pcm_file_open_output_file(snd_pcm_file_t *file)
Ditto.
- if (file->final_fname[0] == '|') {
/* pipe mode */
FILE *pipe;
/* clearing */
file->final_fname[0] = ' ';
pipe = popen(file->final_fname, "w");
Pass "file->final_fname + 1", and you don't have to replace the pipe with a space.
thanks,
Takashi
Hi Takashi,
Thanks a lot for your comments.
Please find enclosed a reworked patch which reflects your requests including the %% functionality.
Thanks, it gets better now.
+static int snd_pcm_file_replace_key(char format, const void *value_p,
char **string_p, char **index_ch_p, int *len_p)
I think it could be easier to make value_str in the caller side. That is,
static int snd_pcm_file_replace_key(char **string_p, char **index_ch_p, int *len_p, const char *value_str) { char *value_str, *string, *index_ch; int index, len, value_len; /* input pointer values */ len = *(len_p); string = *(string_p); index_ch = *(index_ch_p);
/* reallocation to accommodate the value */ index = index_ch - string; value_len = strlen(value_str); len += value_len; string = realloc(string, len + 1); if (!string) return -ENOMEM; index_ch = string + index; /* concatenating the new value */ strcpy(index_ch, value_str); index_ch += value_len; /* return values */ *(len_p) = len; *(string_p) = string; *(index_ch_p) = index_ch; return 0; }
static int snd_pcm_file_replace_fname(snd_pcm_file_t *file, char **new_fname_p) { char value[64]; ... while (old_index_ch <= old_last_ch) { ... /* is %, skipping and checking next letter */ switch (*(++old_index_ch)) { case RATE_KEY: snprintf(value, sizeof(value), "%d', pcm->rate); err = snd_pcm_file_replace_key(&new_fname, &new_index_ch, &new_len, value); if (err < 0) return err; break;
case CHANNELS_KEY: snprintf(value, sizeof(value), "%d', pcm->channels); err = snd_pcm_file_replace_key(&new_fname, &new_index_ch, &new_len, value); if (err < 0) return err; break; .... case FORMAT_KEY: err = snd_pcm_file_replace_key(&new_fname, &new_index_ch, &new_len, snd_pcm_format_name(pcm->format)); if (err < 0) return err; break; ...
Takashi
Takashi Iwai wrote:
Thanks, it gets better now.
+static int snd_pcm_file_replace_key(char format, const void *value_p,
char **string_p, char **index_ch_p, int *len_p)
I think it could be easier to make value_str in the caller side. That is, ........
Hi Takashi,
Thanks for your valuable comments. I am enclosing a fixed and tested version.
Regards,
Pavel.
Signed-off-by: Pavel Hofman pavel.hofman@insite.cz
* added support for including pcm stream params in the output filename * added support for piping the stream to a shell command if the filename string starts with a pipe char
At Thu, 29 Jan 2009 11:54:18 +0100, Pavel Hofman wrote:
Takashi Iwai wrote:
Thanks, it gets better now.
+static int snd_pcm_file_replace_key(char format, const void *value_p,
char **string_p, char **index_ch_p, int *len_p)
I think it could be easier to make value_str in the caller side. That is, ........
Hi Takashi,
Thanks for your valuable comments. I am enclosing a fixed and tested version.
Thanks for a quick fix! Now I applied your patch to GIT tree. For further improvements / optimizations, please submit a patch against it.
Takashi
participants (3)
-
Jaroslav Kysela
-
Pavel Hofman
-
Takashi Iwai