commit 389fed7a147070b32c736e5313236d56df7c624a
parent b1b102044e625bad87c5664c1c8fe26ffddd71f0
Author: Alexander Kojevnikov <alexander@kojevnikov.com>
Date: Sun, 10 Feb 2013 20:48:53 -0800
Measure sample width in bytes
Diffstat:
2 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/src/spek-audio.cc b/src/spek-audio.cc
@@ -116,7 +116,7 @@ struct spek_audio_context * spek_audio_open(const char *path)
return cx;
}
cx->is_planar = av_sample_fmt_is_planar(cx->codec_context->sample_fmt);
- cx->properties.width = 8 * av_get_bytes_per_sample(cx->codec_context->sample_fmt);
+ cx->properties.width = av_get_bytes_per_sample(cx->codec_context->sample_fmt);
switch (cx->codec_context->sample_fmt) {
case AV_SAMPLE_FMT_S16:
case AV_SAMPLE_FMT_S16P:
@@ -176,8 +176,7 @@ int spek_audio_read(struct spek_audio_context *cx) {
}
// We have data, return it and come back for more later.
int buffer_size =
- cx->frame->nb_samples * cx->properties.channels *
- (cx->properties.width / 8);
+ cx->frame->nb_samples * cx->properties.channels * cx->properties.width;
if (buffer_size > cx->buffer_size) {
cx->properties.buffer = (uint8_t*)av_realloc(cx->properties.buffer, buffer_size);
cx->buffer_size = buffer_size;
diff --git a/src/spek-pipeline.cc b/src/spek-pipeline.cc
@@ -200,7 +200,7 @@ static void * reader_func(void *pp)
}
int pos = 0, prev_pos = 0;
- int block_size = p->properties->width * p->properties->channels / 8;
+ int block_size = p->properties->width * p->properties->channels;
int size;
while ((size = spek_audio_read(p->cx)) > 0) {
if (p->quit) break;
@@ -342,26 +342,26 @@ static float average_input(const struct spek_pipeline *p, void *buffer)
int channels = p->properties->channels;
float res = 0.0f;
if (p->properties->fp) {
- if (p->properties->width == 32) {
+ if (p->properties->width == 4) {
float *b = (float*)buffer;
for (int i = 0; i < channels; i++) {
res += b[i];
}
} else {
- assert(p->properties->width == 64);
+ assert(p->properties->width == 8);
double *b = (double*)buffer;
for (int i = 0; i < channels; i++) {
res += (float) b[i];
}
}
} else {
- if (p->properties->width == 16) {
+ if (p->properties->width == 2) {
int16_t *b = (int16_t*)buffer;
for (int i = 0; i < channels; i++) {
res += b[i] / (float) INT16_MAX;
}
} else {
- assert (p->properties->width == 32);
+ assert (p->properties->width == 4);
int32_t *b = (int32_t*)buffer;
for (int i = 0; i < channels; i++) {
res += b[i] / (float) INT32_MAX;