aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTaylor Holberton <taylorcholbrcholberton@gmail.com>2020-06-03 21:31:48 -0400
committerTaylor Holberton <taylorcholbrcholberton@gmail.com>2020-06-03 21:31:48 -0400
commit9c9b2a51fb0ec23b7e648fb942c133f0c52cbc1c (patch)
tree29ea7c72da7a13ed9c184c559c5d94dde0bba06f
parent0c601a3c65d87343f4cb12339f90ffb612069000 (diff)
Simplified tinywavinfo
-rw-r--r--utils/tinywavinfo.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/utils/tinywavinfo.c b/utils/tinywavinfo.c
index c316060..a6d6200 100644
--- a/utils/tinywavinfo.c
+++ b/utils/tinywavinfo.c
@@ -141,21 +141,22 @@ void analyse_sample(FILE *file, unsigned int channels, unsigned int bits,
int i;
unsigned int ch;
int frame_size = 1024;
- unsigned int byte_align = 0;
+ unsigned int bytes_per_sample = 0;
float *power;
int total_sample_per_channel;
float normalization_factor;
if (bits == 32)
- byte_align = 4;
+ bytes_per_sample = 4;
else if (bits == 16)
- byte_align = 2;
+ bytes_per_sample = 2;
normalization_factor = (float)pow(2.0, (bits-1));
- size = channels * byte_align * frame_size;
+ size = channels * bytes_per_sample * frame_size;
- if (posix_memalign(&buffer, byte_align, size)) {
+ buffer = malloc(size);
+ if (!buffer) {
fprintf(stderr, "Unable to allocate %d bytes\n", size);
free(buffer);
return;
@@ -163,7 +164,7 @@ void analyse_sample(FILE *file, unsigned int channels, unsigned int bits,
power = (float *) calloc(channels, sizeof(float));
- total_sample_per_channel = data_chunk_size / (channels * byte_align);
+ total_sample_per_channel = data_chunk_size / (channels * bytes_per_sample);
/* catch ctrl-c to shutdown cleanly */
signal(SIGINT, stream_close);
@@ -171,7 +172,7 @@ void analyse_sample(FILE *file, unsigned int channels, unsigned int bits,
do {
num_read = fread(buffer, 1, size, file);
if (num_read > 0) {
- if (2 == byte_align) {
+ if (2 == bytes_per_sample) {
short *buffer_ptr = (short *)buffer;
for (i = 0; i < num_read; i += channels) {
for (ch = 0; ch < channels; ch++) {
@@ -182,7 +183,7 @@ void analyse_sample(FILE *file, unsigned int channels, unsigned int bits,
}
}
}
- if (4 == byte_align) {
+ if (4 == bytes_per_sample) {
int *buffer_ptr = (int *)buffer;
for (i = 0; i < num_read; i += channels) {
for (ch = 0; ch < channels; ch++) {