cplay: Always write frag * fragment_size
RFC PATCH 1/1 cplay: Always write frag * fragment_size
cplay first writes frag * fragment_size and then
it only writes one fragment at a time.
This means for example than if the user supplied a buffer_size it will only be used for the first write.
---
I noticed this while investigating why cplay prints buffer_size as 0 when not specified as command line argument to cplay.
I also noticed that cred always reads frag * frament_size, so I think this patch should be OK, but marking it as RFC to get your thoughts.
src/utils/cplay.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
src/utils/cplay.c +4 -4
@@ -435,15 +435,15 @@ void play_samples(char *name, unsigned int card, unsigned int device, };if (verbose)printf ("%s: Opened compress device\n" , __func__); - size = config.fragment_size; - buffer =malloc (size * config.fragments); + size = config.fragments * config.fragment_size; + buffer =malloc (size);if (!buffer) {fprintf (stderr,"Unable to allocate %d bytes\n" , size); goto COMP_EXIT; }/* we will write frag fragment_size and then start */ - num_read =fread (buffer,1 , size * config.fragments, file); + num_read =fread (buffer,1 , size, file);if (num_read >0 ) {if (verbose)printf ("%s: Doing first buffer write of %d\n" , __func__, num_read);
@@ -459,7 +459,7 @@ void play_samples(char *name, unsigned int card, unsigned int device, } }printf ("Playing file %s On Card %u device %u, with buffer of %lu bytes\n" , - name, card, device, buffer_size); + name, card, device, size);printf ("Format %u Channels %u, %u Hz, Bit Rate %d\n" , codec.id, codec.ch_in, codec.sample_rate, codec.bit_rate);
Signature · 1 line
2.7.4
Hi Vinod,
Just noticed that this patch is similar with this one for crecord
http://git.alsa-project.org/?p=tinycompress.git;a=commit;h=e8e36567438c16a5121943205a0cd8c63924d0d8
So, I think we can remove the RFC tag :).
thanks,
Daniel.
Quoted 51 lines · Daniel Baluta
cplay first writes frag *
fragment_sizeand then
it only writes one fragment at a time.This means for example than if the user supplied a
buffer_sizeit will only be used for the first write.Signed-off-by Daniel Baluta <[email protected]>---
I noticed this while investigating why cplay printsbuffer_sizeas 0 when not specified as command line argument to cplay.I also noticed that cred always reads frag *
frament_size, so I think this patch should be OK, but marking it as RFC to get your thoughts.src/utils/cplay.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)src/utils/cplay.c +2
-2@@ -435,15 +435,15 @@ void play_samples(char *name, unsigned int card, unsigned int device, }; if (verbose) printf("%s: Opened compress device\n", __func__); - size = config.fragment_size; - buffer =malloc (size * config.fragments); + size = config.fragments * config.fragment_size; + buffer =malloc (size); if (!buffer) { fprintf(stderr, "Unable to allocate %d bytes\n", size); goto COMP_EXIT; }
/* we will write fragfragment_sizeand then start */src/utils/cplay.c +1
-1- num_read =fread (buffer,1 , size * config.fragments, file); + num_read =fread (buffer,1 , size, file);if (
num_read> 0) {
if (verbose)
printf("%s: Doing first buffer write of %d\n", __func__, num_read);src/utils/cplay.c +0
-0@@ -459,7 +459,7 @@ void play_samples(char *name, unsigned int card, unsigned int device, } }printf("Playing file %s On Card %u device %u, with buffer of %lu bytes\n",
src/utils/cplay.c +1
-1- name, card, device, buffer_size); + name, card, device, size);
Quoted 4 lines
printf("Format %u Channels %u, %u Hz, Bit Rate %d\n", codec.id, codec.ch_in, codec.sample_rate, codec.bit_rate);
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Charles Keepax
Reviewed-byQuoted 4 lines · Daniel Baluta
Hi Vinod,
Just noticed that this patch is similar with this one for crecord
Quoted 22 lines
http://git.alsa-project.org/?p=tinycompress.git;a=commit;h=e8e36567438c
16a5121943205a0cd8c63924d0d8So, I think we can remove the RFC tag :).
thanks,
Daniel.Quoted 14 lines · Daniel Baluta
cplay first writes frag *
fragment_sizeand then
it only writes one fragment at a time.This means for example than if the user supplied a
buffer_sizeit will only be used for the first write.Signed-off-by Daniel Baluta <[email protected]>---
I noticed this while investigating why cplay printsbuffer_sizeas 0 when not specified as command line argument to cplay.I also noticed that cred always reads frag *
frament_size, so I think this patch should be OK, but marking it as RFC to get your thoughts.
Yeah looks good to me.
Thanks,
Charles
Quoted 22 lines · Daniel Baluta
cplay first writes frag *
fragment_sizeand then
it only writes one fragment at a time.This means for example than if the user supplied a
buffer_sizeit will only be used for the first write.Signed-off-by Daniel Baluta <[email protected]>---
I noticed this while investigating why cplay printsbuffer_sizeas 0 when not specified as command line argument to cplay.I also noticed that cred always reads frag *
frament_size, so I think this patch should be OK, but marking it as RFC to get your thoughts.src/utils/cplay.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)src/utils/cplay.c +0
-0
src/utils/cplay.c void play_samples(char *name, unsigned int card, unsigned int device, · line 439
Quoted 7 lines
src/utils/cplay.c +2
-2@@ -435,15 +435,15 @@ void play_samples(char *name, unsigned int card, unsigned int device, };if (verbose)printf ("%s: Opened compress device\n" , __func__); - size = config.fragment_size; - buffer =malloc (size * config.fragments); + size = config.fragments * config.fragment_size; + buffer =malloc (size);
net result of this change is no change. Leaving alone the variable names
from this discussion, we allocate memory for size of config.fragments * config.fragment_size
Quoted 12 lines
src/utils/cplay.c +1
-1if (!buffer) {fprintf (stderr,"Unable to allocate %d bytes\n" , size); goto COMP_EXIT; }/* we will write frag fragment_size and then start */ - num_read =fread (buffer,1 , size * config.fragments, file); + num_read =fread (buffer,1 , size, file);if (num_read >0 ) {if (verbose)printf ("%s: Doing first buffer write of %d\n" , __func__, num_read);
src/utils/cplay.c void play_samples(char *name, unsigned int card, unsigned int device, · line 462
Quoted 5 lines
src/utils/cplay.c +1
-1@@ -459,7 +459,7 @@ void play_samples(char *name, unsigned int card, unsigned int device, } }printf ("Playing file %s On Card %u device %u, with buffer of %lu bytes\n" , - name, card, device, buffer_size); + name, card, device, size);
I would prefer to fix the buffer_size when you dont specify in cmdline and we use driver defaults, in that case we calculate this, something like..
src/utils/cplay.c +5 -0
@@ -347,6 +347,11 @@ void play_samples(char *name, unsigned int card, unsigned int device, };if (verbose)printf ("%s: Opened compress device\n" , __func__); + +/* check if buffer_size is used (driver defaults being used */ +if (!buffer_size) + buffer_size = config.fragment_size * config.fragments; + size = config.fragment_size; buffer =malloc (size * config.fragments);if (!buffer) {
And of course, we need to optimize the size variable usage! This does not seem optimal :)
Signature · 1 line
~Vinod
Hi Vinod,
Thanks a lot for having a look at this. Please check my comments inline:
<snip>
Quoted 7 lines
Review
Quoted 4 lines
(quoted diff) +2
-2- size = config.fragment_size; - buffer = malloc(size * config.fragments); + size = config.fragments * config.fragment_size; + buffer = malloc(size);net result of this change is no change. Leaving alone the variable names
from this discussion, we allocate memory for size of config.fragments * config.fragment_size
Yes, you are right on this. There is no change here. But notice that we change the value of size to config.fragments * config.fragment_size;
Now, please take a look at the inner loop at:
https://github.com/alsa-project/tinycompress/blob/master/src/utils/cplay.c#L382
num_read = fread(buffer, 1, size, file);
So, now instead of reading config.fragment_size we read config.fragments * config.fragment_size
thus we fully utilize the buffer.
I'm pretty sure this is the correct fix. See also crecord fix from Charles:
http://git.alsa-project.org/?p=tinycompress.git;a=commit;h=e8e36567438c16a5121943205a0cd8c63924d0d8
thanks,
daniel.