spek

Acoustic spectrum analyser
git clone http://git.hanabi.in/repos/spek.git
Log | Files | Refs | README

commit 96c209b37bd6f4d9e7ee872c2f378d2f4440850c
parent 389fed7a147070b32c736e5313236d56df7c624a
Author: Alexander Kojevnikov <alexander@kojevnikov.com>
Date:   Sun, 10 Feb 2013 22:21:15 -0800

Support planar sample formats (fixes #44)

Diffstat:
Msrc/spek-audio.cc | 21++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/src/spek-audio.cc b/src/spek-audio.cc @@ -175,13 +175,28 @@ int spek_audio_read(struct spek_audio_context *cx) { continue; } // We have data, return it and come back for more later. - int buffer_size = - cx->frame->nb_samples * cx->properties.channels * cx->properties.width; + int samples = cx->frame->nb_samples; + int channels = cx->properties.channels; + int width = cx->properties.width; + int buffer_size = samples * channels * width; if (buffer_size > cx->buffer_size) { cx->properties.buffer = (uint8_t*)av_realloc(cx->properties.buffer, buffer_size); cx->buffer_size = buffer_size; } - memcpy(cx->properties.buffer, cx->frame->data[0], buffer_size); + if (cx->is_planar) { + for (int channel = 0; channel < channels; ++channel) { + uint8_t *buffer = cx->properties.buffer + channel * width; + uint8_t *data = cx->frame->data[channel]; + for (int sample = 0; sample < samples; ++sample) { + for (int i = 0; i < width; ++i) { + *buffer++ = *data++; + } + buffer += (channels - 1) * width; + } + } + } else { + memcpy(cx->properties.buffer, cx->frame->data[0], buffer_size); + } return buffer_size; } if (cx->packet.data) {