Beispiel #1
0
/*-----------------------------------------------------------------------*
 * Main routine which takes a string as input and returns a parse string * 
 *-----------------------------------------------------------------------*/
Gal_Frame send_to_parse(Gal_Frame f, void *server_data)
{
   int i, path_score;
   char *in_string, *out_string, *sysid;
   Gal_Frame f_new = Gal_MakeFrame("main", GAL_CLAUSE);

   /* get the input string to parse from the key's value */
   in_string  = Gal_GetString(f, ":input_string");
   sysid      = Gal_GetString(f, ":sysid");
   path_score = Gal_GetInt(f, ":path_score");

   if (in_string == NULL)
      in_string = Gal_GetString(f, ":parse_input");

   /* strip out punctuation, comments, etc, to uppercase */
   strip_line(in_string);

   /* Call Phoenix Parse function */
   parse(in_string, gram);

   /* print parses to buffer */
   if( num_parses > MaxParses ) num_parses= MaxParses;
   if( num_parses < 1 ) { strcpy(outbuf, "No Parse"); }
   else {
	out_string= outbuf;
	for(i= 0; i < num_parses; i++ ) {
	    sprintf(out_string, "PARSE_%d:\n", i);
	    out_string += strlen(out_string);
	    print_parse(i, out_string, extract, gram);
	    out_string += strlen(out_string);
	    sprintf(out_string, "END_PARSE\n");
	    out_string += strlen(out_string);
	}
	sprintf(out_string, "\n");
	out_string= outbuf;
   }

   /* clear parser temps */
   reset(num_nets);

   /*  create a new frame containing the parse */ 
   Gal_SetProp(f_new, ":parse_input", Gal_StringObject(in_string));
   Gal_SetProp(f_new, ":parse_output", Gal_StringObject(outbuf));
   if (sysid != NULL) Gal_SetProp(f_new, ":sysid", Gal_StringObject(sysid));
   if (path_score != 0) Gal_SetProp(f_new, ":path_score", Gal_IntObject(path_score));

   /* write parse output frame to HUB */
   GalSS_EnvWriteFrame((GalSS_Environment *) server_data, f_new, 0);

   return(f);
}
Beispiel #2
0
static void __AudioPoll(AudioDevice *a, void *data, int num_samples)
{
  AudioPkg *p = (AudioPkg *) a->client_data;
  Gal_Frame output_f;

  printf("[Previous device state is %s.]\n[Current device state is %s.]\n",
	 AudioDeviceStateName(a->previous_device_state),
	 AudioDeviceStateName(a->current_device_state));
  fflush(stdout);
  
  switch (a->current_device_state) {
  case AUDIO_IDLE:
    switch (a->previous_device_state) {
    case AUDIO_RECORDING:
      /* We have data and this is the last chunk. */
      if (!p->out_proxy) {
	GalUtil_Warn("No out proxy to send audio");
      } else {
	GalSS_ProxyArrayAdd(p->out_proxy, data, num_samples);
	printf("[Audio data from user (%d samples).]\n", num_samples);
	fflush(stdout);
	GalSS_ProxyDone(p->out_proxy);
	GalSS_FreeBrokerProxy(p->out_proxy);
	p->out_proxy = (GalSS_BrokerProxy *) NULL;
	printf("[Audio data from user done.]\n");
	fflush(stdout);
      }
      break;
    }
    break;
  case AUDIO_RECORDING:
    switch (a->previous_device_state) {
    case AUDIO_IDLE:
      /* We have data and this is the first chunk. */
      if (p->out_proxy) {
	GalUtil_Warn("Out proxy already exists");
      } else {
	output_f = Gal_MakeFrame("FromAudio", GAL_CLAUSE);	
	/* Set up the outgoing broker connection. */
	p->out_proxy = GalSS_ProxifyObjectType(p->env, GAL_INT_16, 0, 10);
	
	if (p->out_proxy) {
	  /* Send the first chunk. */
	  GalSS_ProxyArrayAdd(p->out_proxy, data, num_samples);
	  printf("[Audio data from user (%d samples).]\n", num_samples);
	  fflush(stdout);
	  /* Notify the Hub that data is coming. */
	  Gal_SetProp(output_f, ":sample_rate",
		      Gal_IntObject(a->sample_rate));
	  Gal_SetProp(output_f, ":encoding_format",
		      Gal_StringObject(a->encoding_format));
	  Gal_SetProp(output_f, ":proxy",
		      Gal_CreateProxyObject(p->out_proxy, 0));
	  GalSS_EnvWriteFrame(p->env, output_f, 0);	  
	}
	Gal_FreeFrame(output_f);
      }
      break;
    case AUDIO_RECORDING:
      /* We have data and this is an intermediate chunk. */
      if (!p->out_proxy) {
	GalUtil_Warn("No out proxy to send audio");
      } else {
	GalSS_ProxyArrayAdd(p->out_proxy, data, num_samples);
	printf("[Audio data from user (%d samples).]\n", num_samples);
	fflush(stdout);
      }
      break;
    }
    break;
  case AUDIO_PLAYING:
    break;
  case AUDIO_UNAVAILABLE:
    /* The device shut down. End the session and exit. */
    /* We ran out of inputs. Disconnect. */
    printf("Audio no longer available. Disconnecting.\n");
    fflush(stdout);

    /* First, end the session. */
    output_f = Gal_MakeFrame("Builtin.end_session", GAL_CLAUSE);
    GalSS_EnvWriteFrame(p->env, output_f, 0);
    Gal_FreeFrame(output_f);
      
    /* Next, shut down the connection. This ought
       to reset the poll. */      
    GalIO_SetCommDone(GalSS_EnvComm(p->env));
    /* DON'T DESTROY THE CONNECTION. In batch mode,
       we'll be inside a poll for that connection, and
       all sorts of bad things will happen. It's enough
       to set it to be done; that will force it to be
       destroyed when the current poll is finished. */
    break;
  }
  if (data)
    free(data);
}
Beispiel #3
0
static void __ACLBrokerReaderCallback(GalIO_BrokerStruct *broker_struct,
				      void *data, Gal_ObjectType data_type,
				      int n_samples)
{
  ACLCallbackStruct *cb = (ACLCallbackStruct *) GalIO_GetBrokerData(broker_struct);
  /* This is for the argument pointers. */
  int arg_pointers[2];
  Gal_Object o = (Gal_Object) NULL;
  
  /* I want to get the pointers from f and env and pass them in.
     I "just happen to know" the names of the types; SWIG doesn't
     seem yet to "publish" them at all. */
  switch (data_type) {    
  case GAL_INT_16:
    o = Gal_CreateInt16Object(data, n_samples, 1);
    break;
  case GAL_INT_32:    
    o = Gal_CreateInt32Object(data, n_samples, 1);
    break;
  case GAL_FLOAT_32:    
    o = Gal_CreateFloat32Object(data, n_samples, 1);
    break;    
  case GAL_FLOAT_64:
    o = Gal_CreateFloat64Object(data, n_samples, 1);
    break;
  case GAL_BINARY:    
    o = Gal_CreateBinaryObject(data, n_samples, 1);
    break;
  case GAL_STRING:
    o = Gal_CreateStringObject((char *) data, 1);
    break;
  case GAL_SYMBOL:
    o = Gal_SymbolObject(sym_name((Gal_Symbol) data));
    break;
  case GAL_INT:
    o = Gal_IntObject((int) data);
    break;
  case GAL_FLOAT:
    o = Gal_FloatObject(*((float *) data));
    free(data);
    break;
  case GAL_LIST:
    /* In this special case, I need to build a list object,
       because that's pretty much the only way Python can
       deal with this (uncode it, for instance). */
    o = Gal_ListObject((Gal_Object *) data, n_samples);
    break;
  case GAL_FRAME:
    o = Gal_FrameObject((Gal_Frame) data);
    break;
  case GAL_PROXY:
    o = Gal_ProxyObject((GalSS_BrokerProxy *) data);
    break;
  default:
    break;
  }

  arg_pointers[0] = (int) data_type;
  arg_pointers[1] = (int) o;
  ACLGal_FuncallLisp(cb, arg_pointers, 2);
  if (o) Gal_FreeObject(o);
}