remove debug output
[ardour.git] / libs / ptformat / ptfformat.cc
index 048c17491829e76a907cd33d3dd4117ccaee8f96..1dba1ac31a6e7a11726e1640ce34f141a4f5398f 100644 (file)
 
 */
 
-#include "ptfformat.h"
-
 #include <stdio.h>
+#include <stdlib.h>
 #include <string>
 #include <string.h>
 #include <assert.h>
 
+#include <glib/gstdio.h>
+
+#include "ptfformat.h"
+
 using namespace std;
 
 static const uint32_t baselut[16] = {
@@ -113,8 +116,9 @@ PTFFormat::load(std::string path, int64_t targetsr) {
        uint64_t i;
        uint64_t j;
        int inv;
+       int err;
 
-       if (! (fp = fopen(path.c_str(), "rb"))) {
+       if (! (fp = g_fopen(path.c_str(), "rb"))) {
                return -1;
        }
 
@@ -230,6 +234,12 @@ PTFFormat::load(std::string path, int64_t targetsr) {
                unxor10();
        }
 
+       // Special case when ptx is exported to ptf in PT
+       if (v == 3) {
+               version = 11;
+               unxor_ptx_to_ptf();
+       }
+
        if (version == 0 || version == 5 || version == 7) {
                /* Haven't detected version yet so decipher */
                j = 0;
@@ -257,8 +267,12 @@ PTFFormat::load(std::string path, int64_t targetsr) {
                }
        }
 
+       if (version < 5 || version > 12)
+               return -1;
        targetrate = targetsr;
-       parse();
+       err = parse();
+       if (err)
+               return -1;
        return 0;
 }
 
@@ -299,35 +313,69 @@ PTFFormat::unxor10(void)
 }
 
 void
+PTFFormat::unxor_ptx_to_ptf(void)
+{
+       unsigned char keyy[16] = {      0x00,0x10,0x20,0x30,0x40,0x50,0x60,0x70,
+                                       0x80,0x90,0xa0,0xb0,0xc0,0xd0,0xe0,0xf0
+       };
+       uint64_t j;
+       uint8_t i;
+
+       for (i = 0, j = 0x10; j < len; j++,i++) {
+               ptfunxored[j] ^= keyy[i];
+               if ((j % 16) == 0) {
+                       i = 0;
+                       if (ptfunxored[j] % 2 == 0) {
+                               ptfunxored[j]++;
+                       } else {
+                               ptfunxored[j]--;
+                       }
+               }
+       }
+}
+
+int
 PTFFormat::parse(void) {
        if (version == 5) {
                parse5header();
                setrates();
+               if (sessionrate < 44100 || sessionrate > 192000)
+                 return -1;
                parseaudio5();
                parserest5();
        } else if (version == 7) {
                parse7header();
                setrates();
+               if (sessionrate < 44100 || sessionrate > 192000)
+                 return -1;
                parseaudio();
                parserest89();
        } else if (version == 8) {
                parse8header();
                setrates();
+               if (sessionrate < 44100 || sessionrate > 192000)
+                 return -1;
                parseaudio();
                parserest89();
        } else if (version == 9) {
                parse9header();
                setrates();
+               if (sessionrate < 44100 || sessionrate > 192000)
+                 return -1;
                parseaudio();
                parserest89();
        } else if (version == 10 || version == 11 || version == 12) {
                parse10header();
                setrates();
+               if (sessionrate < 44100 || sessionrate > 192000)
+                 return -1;
                parseaudio();
                parserest10();
        } else {
                // Should not occur
+               return -1;
        }
+       return 0;
 }
 
 void