refactor pcm reader framework
[fdkaac.git] / src / pcm_readhelper.c
index 5a2b037b49a5cc2c71319e44b220518aa737e2a8..dad92ee8b2b149a181b61dd4f7ce77983af68b55 100644 (file)
 #include "m4af_endian.h"
 #include "catypes.h"
 
+int pcm_read_frames(pcm_reader_t *r, void *data, unsigned nframes)
+{
+    int n;
+    unsigned count = 0;
+    uint8_t *bp = data;
+    unsigned bpf = pcm_get_format(r)->bytes_per_frame;
+
+    do {
+        n = r->vtbl->read_frames(r, bp, nframes - count);
+        if (n > 0) {
+            count += n;
+            bp += n * bpf;
+        }
+    } while (n > 0 && count < nframes);
+    return count;
+}
+
 int pcm_read(pcm_io_context_t *io, void *buffer, uint32_t size)
 {
     int rc;
     uint32_t count = 0;
+    uint8_t *bp = buffer;
 
     do {
-        rc = io->vtbl->read(io->cookie, buffer, size - count);
-        if (rc > 0)
+        rc = io->vtbl->read(io->cookie, bp, size - count);
+        if (rc > 0) {
             count += rc;
+            bp += rc;
+        }
     } while (rc > 0 && count < size);
     return count > 0 ? count : rc;
 }
@@ -204,7 +224,7 @@ int apple_chan_chunk(pcm_io_context_t *io, uint32_t chunk_size,
 
     switch (mChannelLayoutTag) {
     case kAudioChannelLayoutTag_UseChannelBitmap:
-        ENSURE(bitcount(mask) == nchannels);
+        ENSURE(bitcount(mChannelBitmap) == nchannels);
         TRY_IO(pcm_skip(io, chunk_size - 12));
         fmt->channel_mask = mChannelBitmap;
         for (i = 0; i < nchannels; ++i)
This page took 0.009563 seconds and 4 git commands to generate.