From 66cf20ebe1029a86560ff8c9ffc26a92def0f90c Mon Sep 17 00:00:00 2001
From: Jonathan Wilkes <jon.w.wilkes@gmail.com>
Date: Wed, 14 Jun 2017 23:21:14 -0400
Subject: [PATCH] port from Pd Vanilla: yet more fixing of aiff format in
 d_soundfile.c commit 420bd1fffa0336650309d4c158c6dd208d993310

---
 pd/src/d_soundfile.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/pd/src/d_soundfile.c b/pd/src/d_soundfile.c
index 6c7148842..0f0edfe6c 100644
--- a/pd/src/d_soundfile.c
+++ b/pd/src/d_soundfile.c
@@ -113,7 +113,7 @@ typedef struct _wavechunk           /* ... and the last two items */
 #define WAV_INT 1
 #define WAV_FLOAT 3
 
-/* the cd lib header.  I'm assuming AIFC is compatible but don't really know
+/* the AIFF header.  I'm assuming AIFC is compatible but don't really know
     that. */
 
 typedef struct _datachunk
@@ -377,7 +377,7 @@ int open_soundfile_via_fd(int fd, int headersize,
                         goto badheader;
                 headersize = seekto;
             }
-            bytelimit = swap4(((t_datachunk *)buf)->dc_size, swap);
+            bytelimit = swap4(((t_datachunk *)buf)->dc_size, swap) - 8;
             headersize += sizeof(t_datachunk);
         }
     }
@@ -799,7 +799,7 @@ static int create_soundfile(t_canvas *canvas, const char *filename,
         memcpy(&aiffhdr->a_nframeshi, &longtmp, 4);
         aiffhdr->a_bitspersamp = swap2(8 * bytespersamp, swap);
         memcpy(aiffhdr->a_samprate, dogdoo, sizeof(dogdoo));
-        longtmp = swap4(datasize, swap);
+        longtmp = swap4(datasize + 8, swap);
         memcpy(aiffhdr->a_samprate + sizeof(dogdoo), &longtmp, 4);
         memset(aiffhdr->a_samprate + sizeof(dogdoo) + 4, 0, 8);
         headersize = AIFFPLUS;
-- 
GitLab