示例#1
0
Gal_Frame reinitialize(Gal_Frame f, void *server_data)
{
  char *audiofile = Gal_GetString(f, ":audiofile");
  Gal_Frame fr;
  char *broker_method = Gal_GetString(f, ":broker_method");
  int use_stream = Gal_GetInt(f, ":use_stream");

  if ((!broker_method) || !strcmp(broker_method, "original_env")) {
    BrokerMethod = BROKER_ORIGINAL_ENV;
  } else if (!strcmp(broker_method, "original_comm")) {
    BrokerMethod = BROKER_ORIGINAL_GCOMM;
  } else if (!strcmp(broker_method, "proxy_obj")) {
    BrokerMethod = BROKER_PROXY_OBJ;
  } else if (!strcmp(broker_method, "proxy_stream")) {
    BrokerMethod = BROKER_PROXY_STREAM;
  } else if (!strcmp(broker_method, "proxy_original")) {
    BrokerMethod = BROKER_PROXY_ORIGINAL;
  }
  
  if (audiofile) {
    /* Send a brokering message. */
    fr = prepare_audio_frame((GalSS_Environment *) server_data,
			     audiofile, use_stream);
    GalSS_EnvWriteFrame((GalSS_Environment *) server_data, fr, 0);
    Gal_FreeFrame(fr);
  }
  return (Gal_Frame) NULL;
}
示例#2
0
Gal_Frame reinitialize(Gal_Frame f, void *server_data)
{
  char *audiofile = Gal_GetString(f, ":audiofile");
  Gal_Frame fr;

  if (audiofile) {
    /* Send a brokering message. */
    fr = prepare_audio_frame(audiofile);
    GalSS_EnvWriteFrame((GalSS_Environment *) server_data, fr, 0);
    Gal_FreeFrame(fr);
  }
  return (Gal_Frame) NULL;
}
示例#3
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);
}
示例#4
0
Gal_Frame reinitialize(Gal_Frame f, void *server_data)
{
  GalSS_Environment *env = (GalSS_Environment *) server_data;
  GalIO_CommStruct *gcomm = GalSS_EnvComm(env);
  AudioPkg *p = (AudioPkg *) GalIO_GetCommServerData(gcomm);
  Gal_Frame session_f;
  
  GalSS_EnvMaintainInLocation(gcomm, GalSS_EnvGetSessionID(env), &(p->env));

  /* Create the session. */
  session_f = Gal_MakeFrame("OpenAudioSession", GAL_CLAUSE);
  GalSS_EnvWriteFrame(env, session_f, 0);
  Gal_FreeFrame(session_f);

  /* Don't enable the audio device yet - only after the greeting. */
  
  return (Gal_Frame) NULL;
}
示例#5
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);
}