src/io/source_apple_audio.c: simplify _do, downmixing
authorPaul Brossier <piem@piem.org>
Sat, 16 Mar 2013 14:43:37 +0000 (09:43 -0500)
committerPaul Brossier <piem@piem.org>
Sat, 16 Mar 2013 14:43:37 +0000 (09:43 -0500)
src/io/source_apple_audio.c

index 415a71bfa0de7fb60961d52045767693cbb8a0b5..71f90aa9a09384506050f18c40290b6580f09469 100644 (file)
@@ -145,23 +145,24 @@ void aubio_source_apple_audio_do(aubio_source_apple_audio_t *s, fvec_t * read_to
   OSStatus err = ExtAudioFileRead(s->audioFile, &loadedPackets, &s->bufferList);
   if (err) { AUBIO_ERROR("error in ExtAudioFileRead, %d\n", (int)err); goto beach;}
 
-  smpl_t *buf = read_to->data;
-
   short *data = (short*)s->bufferList.mBuffers[0].mData;
 
-  if (buf) {
-      for (c = 0; c < s->channels; c++) {
-          for (v = 0; v < s->block_size; v++) {
-              if (v < loadedPackets) {
-                  buf[v * s->channels + c] =
-                      SHORT_TO_FLOAT(data[ v * s->channels + c]);
-              } else {
-                  buf[v * s->channels + c] = 0.f;
-              }
-          }
-      }
+  smpl_t *buf = read_to->data;
+
+  for (v = 0; v < loadedPackets; v++) {
+    buf[v] = 0.;
+    for (c = 0; c < s->channels; c++) {
+      buf[v] += SHORT_TO_FLOAT(data[ v * s->channels + c]);
+    }
+    buf[v] /= (smpl_t)s->channels;
+  }
+  // short read, fill with zeros
+  if (loadedPackets < s->block_size) {
+    for (v = loadedPackets; v < s->block_size; v++) {
+      buf[v] = 0.;
+    }
   }
-  //if (loadedPackets < s->block_size) return EOF;
+
   *read = (uint_t)loadedPackets;
   return;
 beach: