示例#1
0
文件: net.c 项目: doomglue/aleph
static const u8* onode_unpickle(const u8* src, onode_t* out) {
  u32 v32;

  // operator output index
  src = unpickle_32(src, &v32);
  out->opOutIdx = (u8)v32;
  // output target
  src = unpickle_32(src, &v32);
  out->target = (s16)v32;

  // index of parent op
  src = unpickle_32(src, &v32);
  out->opIdx = (s32)v32;

  // preset flag: 32 bits for alignment
  //  src = unpickle_32(src, &v32);
  //  out->preset = (u8)v32;

  print_dbg(" ; opIdx: ");
  print_dbg_ulong(out->opIdx);
  print_dbg(" ; opOutIdx: ");
  print_dbg_ulong(out->opOutIdx);
  print_dbg(" ; target: ");
  print_dbg_ulong(out->target);

  return src;
}
示例#2
0
文件: param.c 项目: doomglue/aleph
const u8* param_unpickle(pnode_t* pnode, const u8* src) {
  u32 val;
  // load idx-
  src = unpickle_32(src, &val);

  // print_dbg("\r\n unpickled param index: ");
  // print_dbg_ulong(val);

  pnode->idx = (u8)val;
  // load value
  
  src = unpickle_32(src, &val);
  pnode->data.value = (ParamValue)val;

  print_dbg(" , val: ");
  print_dbg_ulong(val);
  //  src = unpickle_32(src, &(pnode->data.value.asUint));

  // print_dbg("\r\n unpickled param value: ");
  // print_dbg_ulong(val);

  // load preset-inclusion 
  //  src = unpickle_32(src, &val);

  // print_dbg("\r\n unpickled param preset flag: ");
  // print_dbg_ulong(val);

  //  pnode->preset = (u8)val;
  // load descriptor
  src = pdesc_unpickle(&(pnode->desc), src);
  return src;
}
示例#3
0
文件: files.c 项目: Someone101/aleph
// search for named .dsc file and load into network param desc memory
extern u8 files_load_desc(const char* name) {
  char path[64] = DSP_PATH;
  void * fp;
  int nparams = -1;
  // word buffer for 4-byte unpickling
  u8 nbuf[4];
  // buffer for binary blob of single descriptor
  u8 dbuf[PARAM_DESC_PICKLE_BYTES];
  // unpacked descriptor
  ParamDesc desc;
  int i;
  u8 ret = 0;

  app_pause();

  strcat(path, name);
  strip_ext(path);
  strcat(path, ".dsc");

  print_dbg("\r\n  opening .dsc file at path: ");
  print_dbg(path);

  fp = fl_fopen(path, "r");
  if(fp == NULL) {
    print_dbg("... error opening .dsc file.");
    print_dbg(path);
    ret = 1;
  } else {

    // get number of parameters
    fake_fread(nbuf, 4, fp);
    unpickle_32(nbuf, (u32*)&nparams); 

    /// loop over params
    if(nparams > 0) {
      net_clear_params();
      //    net->numParams = nparams;

      for(i=0; i<nparams; i++) {
	//  FIXME: a little gross,
	// to be interleaving network and file manipulation like this...
	///....
	// read into desc buffer
	fake_fread(dbuf, PARAM_DESC_PICKLE_BYTES, fp);
	// unpickle directly into network descriptor memory
	pdesc_unpickle( &desc, dbuf );
	// copy descriptor to network and increment count
	net_add_param(i, (const ParamDesc*)(&desc));     
 
      }
    } else {
      print_dbg("\r\n error: crazy parameter count from descriptor file.");
      ret = 1;
    }
  }
  fl_fclose(fp);
  app_resume();
  return ret;
}
示例#4
0
文件: param.c 项目: Someone101/aleph
const u8* param_unpickle(pnode_t* pnode, const u8* src) {
  u32 val;
  // load idx 
  // TEST: keep as dummy for compatibility
  src = unpickle_32(src, &val);

  // print_dbg("\r\n unpickled param index: ");
  // print_dbg_ulong(val);


  ///// TEST: don't
  //  pnode->idx = (u8)val;
  ////



  // load value  
  src = unpickle_32(src, &val);
  pnode->data.value = (ParamValue)val;

  print_dbg("\r\n unpickling param, val: 0x"); 
  print_dbg_hex(val);

  //  print_dbg(" , val: ");
  //  print_dbg_ulong(val);
  //  src = unpickle_32(src, &(pnode->data.value.asUint));

  // print_dbg("\r\n unpickled param value: ");
  // print_dbg_ulong(val);

  // load play-inclusion 
  src = unpickle_32(src, &val);
  pnode->play = (u8)val;


  print_dbg(" , play: 0x"); 
  print_dbg_hex(val);


  // print_dbg("\r\n unpickled param preset flag: ");
  // print_dbg_ulong(val);

  // load descriptor
  src = pdesc_unpickle(&(pnode->desc), src);
  return src;
}
示例#5
0
文件: param.c 项目: Someone101/aleph
const u8* pdesc_unpickle(ParamDesc* pdesc, const u8* src) {
  u32 val;
  u32 i;

  print_dbg(", descriptor: ");

  // store label string
  for(i=0; i<PARAM_LABEL_LEN; ++i) {
    pdesc->label[i] = *src;
    ++src;
  }

  print_dbg(" , label: ");
  print_dbg(pdesc->label);

  // store type
  // pad for alignment
  src = unpickle_32(src, &val);
  pdesc->type = (u8)val;
  print_dbg(" \t, type: ");
  print_dbg_ulong(pdesc->type);
  
  // min
  src = unpickle_32(src, &val);
  pdesc->min = val;
  print_dbg(" \t, min: ");
  print_dbg_hex(pdesc->min);

  // max
  src = unpickle_32(src, &val);
  pdesc->max = val;
  print_dbg(" , max: ");
  print_dbg_ulong(pdesc->max);

  // store radix
  // pad for alignment
  src = unpickle_32(src, &val);
  pdesc->radix = (u8)val;

  print_dbg(" , radix: ");
  print_dbg_ulong(pdesc->radix);

  return src;
}
示例#6
0
文件: param.c 项目: doomglue/aleph
const u8* pdesc_unpickle(ParamDesc* pdesc, const u8* src) {
  u32 val;
  u8 i;
  // store label string
  for(i=0; i<PARAM_LABEL_LEN; ++i) {
    pdesc->label[i] = *src;
    ++src;
  }

  print_dbg(" , label: ");
  print_dbg(pdesc->label);

  // store type
  pdesc->type = *src;
  ++src;

  print_dbg(" , type: ");
  print_dbg_ulong(pdesc->type);

  
  // store min
  src = unpickle_32(src, &val);
  pdesc->min = val;

  print_dbg(" , min: ");
  print_dbg_ulong(pdesc->min);


  // store max
  src = unpickle_32(src, &val);
  pdesc->max = val;

  print_dbg(" , max: ");
  print_dbg_ulong(pdesc->max);

  // store radix
  src = unpickle_32(src, &val);
  pdesc->radix = val;

  print_dbg(" , radix: ");
  print_dbg_ulong(pdesc->radix);

  return src;
}
示例#7
0
文件: files.c 项目: bbnickell/aleph
// search for specified dsp file and load it
u8 files_load_dsp_name(const char* name) {
  // don't need .ldr, but we do need .dsc...
  char descname[128];
  u8 nbuf[4];
  // buffer for binary blob of single descriptor
  u8 dbuf[PARAM_DESC_PICKLE_BYTES];
  // unpacked descriptor
  ParamDesc desc;
  u32 nparams;
  u8 ret = 0;
  FILE* fp;
  int i;
  strcpy(descname, workingDir);
  strcat(descname, name);
  strip_ext(descname);
  strcat(descname, ".dsc");

  fp = fopen(descname, "r");
  
  if(fp == NULL) {
    printf("\r\n module descriptor not found; path: %s", descname);
    ret = 1;
    return ret;
  }
  
  // get count of params
  fread(nbuf, 1, 4, fp);
  unpickle_32(nbuf, (u32*)&nparams); 

  /// loop over params
  if(nparams > 0) {
    printf("\r\n loading param descriptor; count: %d", nparams);
    net_clear_params();
    for(i=0; i<nparams; i++) {
      // read into desc buffer
      fread(dbuf, 1, PARAM_DESC_PICKLE_BYTES, fp);
      // unpickle directly into network descriptor memory
      pdesc_unpickle( &desc, dbuf );
      // copy descriptor to network and increment count
      net_add_param(i, (const ParamDesc*)(&desc));     
    }
  } else {
    ret = 1;
  }

  fclose(fp);

  scene_set_module_name(name);
  return ret;
}
示例#8
0
文件: net.c 项目: catfact/aleph-old
static const u8* onode_unpickle(const u8* src, onode_t* out) {
  u32 v32;

  // output target
  src = unpickle_32(src, &v32);
  out->target = (s16)v32;


#ifdef PRINT_PICKLE
  print_dbg(" ; opIdx: ");
  print_dbg_ulong(out->opIdx);
  print_dbg(" ; opOutIdx: ");
  print_dbg_ulong(out->opOutIdx);
  print_dbg(" ; target: ");
  print_dbg_ulong(out->target);
#endif

  return src;
}
示例#9
0
文件: net.c 项目: bensteinberg/aleph
// unpickle the network!
u8* net_unpickle(const u8* src) {
  u32 i, count, val;
  op_id_t id;
  op_t* op;

  // reset operator count, param count, pool offset, etc
  // no system operators after this
  net_deinit();


  // get count of operators
  // (use 4 bytes for alignment)
  src = unpickle_32(src, &count);

  #ifdef PRINT_PICKLE
    print_dbg("\r\n count of ops: ");
    print_dbg_ulong(count);
  #endif

  // loop over operators
  for(i=0; i<count; ++i) {
    // get operator class id
    src = unpickle_32(src, &val);
    id = (op_id_t)val;

    #ifdef PRINT_PICKLE
        print_dbg("\r\n adding op, class id: ");
        print_dbg_ulong(id);
    #endif

    // add and initialize from class id
    /// .. this should update the operator count, inodes and onodes
    net_add_op(id);

    // unpickle operator state (if needed)
    op = net->ops[net->numOps - 1];

    if(op->unpickle != NULL)  {
      #ifdef PRINT_PICKLE
            print_dbg(" ... unpickling op .... ");
            print_dbg_ulong(id);
      #endif
      src = (*(op->unpickle))(op, src);
    }
  }

#if 1

  /// copy ALL i/o nodes, even unused!
  print_dbg("\r\n reading all input nodes ");
  
  for(i=0; i < (NET_INS_MAX); ++i) {
#ifdef PRINT_PICKLE
    print_dbg("\r\n unpickling input node, idx: ");
    print_dbg_ulong(i);
#endif

    src = inode_unpickle(src, &(net->ins[i]));
  }

#ifdef PRINT_PICKLE
  print_dbg("\r\n reading all output nodes");
#endif
  // read output nodes
  for(i=0; i < NET_OUTS_MAX; ++i) {
#ifdef PRINT_PICKLE
    print_dbg("\r\n unpickling output node, idx: ");
    print_dbg_ulong(i);
#endif 

    src = onode_unpickle(src, &(net->outs[i]));
    if(i < net->numOuts) {
      if(net->outs[i].target >= 0) {
	// reconnect so the parent operator knows what to do
	net_connect(i, net->outs[i].target);
      }
    }
  }

#else 
#error broken input node unserialization
/* /\* #ifdef PRINT_PICKLE *\/ */
/* /\*   print_dbg("\r\n reading input nodes, count: "); *\/ */
/* /\*   print_dbg_ulong(net->numIns); *\/ */
/* /\* #endif *\/ */
  
/*   for(i=0; i < (net->numIns); ++i) { */
/*     src = inode_unpickle(src, &(net->ins[i])); */
/*   } */

/* /\* #ifdef PRINT_PICKLE *\/ */
/* /\*   print_dbg("\r\n reading output nodes, count: "); *\/ */
/* /\*   print_dbg_ulong(net->numOuts); *\/ */
/* /\* #endif *\/ */

/*   // read output nodes */
/*   for(i=0; i < net->numOuts; ++i) { */
/*     src = onode_unpickle(src, &(net->outs[i])); */
/*     // reconnect so the parent operator knows what to do */
/*     net_connect(i, net->outs[i].target); */
/*   } */
#endif

  // get count of parameters
  src = unpickle_32(src, &val);
  net->numParams = (u16)val;

#ifdef PRINT_PICKLE
  print_dbg("\r\n reading params, count: ");
  print_dbg_ulong(net->numParams);
#endif

  // read parameter nodes (includes value and descriptor)
  for(i=0; i<(net->numParams); ++i) {
#ifdef PRINT_PICKLE
    print_dbg("\r\n unpickling param, idx: ");
    print_dbg_ulong(i);
#endif

    src = param_unpickle(&(net->params[i]), src);
  }
  
  return (u8*)src;
}
示例#10
0
// unpickle
const u8* presets_unpickle(const u8* src) {
  u32 i, j;
  u32 v32;
  for(i=0; i<NET_PRESETS_MAX; i++) {
    

    print_dbg("\r\n ... \r\n unpickling preset, idx: ");
    print_dbg_ulong(i);
    //    print_dbg("\r\n ...");

    
    // pickle inputs
    //    for(j=0; j<NET_INS_MAX; j++) {
    for(j=0; j < PRESET_INODES_COUNT; j++) {

    /* print_dbg("\r\n unpickling preset input, idx: "); */
    /* print_dbg_ulong(j); */

      // waste some space for 4-byte alignment
      src = unpickle_32(src, &v32);
      presets[i].ins[j].value = (io_t)v32;
      
      /* print_dbg(" ; val: "); */
      /* print_dbg_ulong(v32); */

      ///////////////
      /////////////////
      /// NOTE: not storing idx for now.
      /// this could change if we switch to conditional storage
      /* src = unpickle_32(src, &v32); */
      /* presets[i].ins[j].idx = v32; */

      /* print_dbg(" ; idx: "); */
      /* print_dbg_ulong(v32); */

      src = unpickle_32(src, &v32);
      presets[i].ins[j].enabled = v32;

      /* print_dbg(" ; enabled: "); */
      /* print_dbg_ulong(v32); */

    }
    // unpickle outputs
    for(j=0; j<NET_OUTS_MAX; j++) {

    /* print_dbg("\r\n unpickling preset output, idx: "); */
    /* print_dbg_ulong(j); */


      // waste some space for 4-byte alignment
      src = unpickle_32(src, &v32);
      presets[i].outs[j].target = (io_t)v32;

      /* print_dbg(" ; target: "); */
      /* print_dbg_ulong(v32); */


      ///////////////
      /////////////////
      /// NOTE: not storing idx for now.
      /// this could change if we switch to conditional storage

      /* src = unpickle_32(src, &v32); */
      /* presets[i].outs[j].outIdx = v32; */

      /* print_dbg(" ; outIdx: "); */
      /* print_dbg_ulong(v32); */


      src = unpickle_32(src, &v32);
      presets[i].outs[j].enabled = v32;


      /* print_dbg(" ; enabled: "); */
      /* print_dbg_ulong(v32); */

    }
    // unpickle params
    /* for(j=0; j<NET_PARAMS_MAX; j++) { */
    /*   // waste some space for 4-byte alignment */
    /*   src = unpickle_32(src, &v32); */
    /*   presets[i].params[j].value = (io_t)v32; */
    /*   src = unpickle_32(src, &v32); */
    /*   presets[i].params[j].idx = v32; */
    /*   src = unpickle_32(src, &v32); */
    /*   presets[i].params[j].enabled = v32; */
    /* } */
    // write name!
    for(j=0; j<PRESET_NAME_LEN; j++) {
      presets[i].name[j] = *src++;
    }

    print_dbg(" ; name: ");
    print_dbg(presets[i].name);

  }
  return src;
}
示例#11
0
文件: net.c 项目: doomglue/aleph
// unpickle the network!
u8* net_unpickle(const u8* src) {
  u32 i, count, val;
  op_id_t id;
  op_t* op;

  // reset operator count, param count, pool offset, etc
  // no system operators after this
  net_deinit();


  // get count of operators
  // (use 4 bytes for alignment)
  src = unpickle_32(src, &count);

  print_dbg("\r\n count of ops: ");
  print_dbg_ulong(count);

  // loop over operators
  for(i=0; i<count; ++i) {
    // get operator class id
    src = unpickle_32(src, &val);
    id = (op_id_t)val;

    // add and initialize from class id
    /// .. this should update the operator count, inodes and onodes
    print_dbg("\r\n adding op, class id: ");
    print_dbg_ulong(id);
  
    net_add_op(id);

    // unpickle operator state (if needed)
    op = net->ops[net->numOps - 1];

    if(op->unpickle != NULL) {
      print_dbg(" ... unpickling op .... ");
      print_dbg_ulong(id);
      src = (*(op->unpickle))(op, src);
    }
  }

  // read input nodes
  //  for(i=0; i < (net->numIns + net->numParams); ++i) {
  ///// FIXME: 
  /// tried adding the params to input list here, for play-mode flag
  /// but somehow, this breaks stuff.
#if 1
  /// copy ALL i/o nodes, even unused
  print_dbg("\r\n reading all input nodes ");
  
  for(i=0; i < (NET_INS_MAX); ++i) {
    print_dbg("\r\n unpickling input node, idx: ");
    print_dbg_ulong(i);

    src = inode_unpickle(src, &(net->ins[i]));
  }

  print_dbg("\r\n reading all output nodes");
  // read output nodes
  for(i=0; i < NET_OUTS_MAX; ++i) {
    print_dbg("\r\n unpickling output node, idx: ");
    print_dbg_ulong(i);

    src = onode_unpickle(src, &(net->outs[i]));
    if(i < net->numOuts) {
      if(net->outs[i].target >= 0) {
	// reconnect so the parent operator knows what to do
	net_connect(i, net->outs[i].target);
      }
    }
  }
#else
  print_dbg("\r\n reading input nodes, count: ");
  print_dbg_ulong(net->numIns);
  
  for(i=0; i < (net->numIns); ++i) {
    src = inode_unpickle(src, &(net->ins[i]));
  }

  print_dbg("\r\n reading output nodes, count: ");
  print_dbg_ulong(net->numOuts);

  // read output nodes
  for(i=0; i < net->numOuts; ++i) {
    src = onode_unpickle(src, &(net->outs[i]));
    // reconnect so the parent operator knows what to do
    net_connect(i, net->outs[i].target);
  }
#endif

  // get count of parameters
  src = unpickle_32(src, &val);
  net->numParams = (u16)val;

  print_dbg("\r\n reading params, count: ");
  print_dbg_ulong(net->numParams);

  // read parameter nodes (includes value and descriptor)
  for(i=0; i<(net->numParams); ++i) {
    print_dbg("\r\n unpickling param, idx: ");
    print_dbg_ulong(i);

    src = param_unpickle(&(net->params[i]), src);
  }
  
  return (u8*)src;
}