Esempio n. 1
0
void
on_data (shmdata_any_reader_t * reader,
	 void *shmbuf,
	 void *data,
	 int data_size,
	 unsigned long long timestamp,
	 const char *type_description, void *user_data)
{
  if (VERBOSE == yes)
    {
      printf ("data %p, data size %d, timestamp %llu, type descr %s\n",
	      data, data_size, timestamp, type_description);
      printf ("user_data: %s\n", (const char *) user_data);
    }

  if (strcmp (data, message) == 0)
    {
      if (VERBOSE == yes)
	printf ("The two strings match! Success!\n");
      success = yes;
    }
  //free the data, can also be called later
  shmdata_any_reader_free (shmbuf);
  keep_going = no;
}
Esempio n. 2
0
static void 
shmsrc_tilde_audio_buffer_free (t_shmsrc_tilde_buf *buf)
{
  if (buf->free_audio_data) //because of a malloc when converting from 16 bits  
    g_free (buf->audio_data);  
  shmdata_any_reader_free (buf->shm_buf);
  g_free (buf);
}
Esempio n. 3
0
void
on_data (shmdata_any_reader_t * reader,
	 void *shmbuf,
	 void *data,
	 int data_size,
	 unsigned long long timestamp,
	 const char *type_description, 
	 void *user_data)
{
  printf ("data %p, data size %d, timestamp %llu, type descr %s\n",
	  data, data_size, timestamp, type_description);
  printf ("user_data: %s\n", (const char *) user_data);

  //free the data, can also be called later
  shmdata_any_reader_free (shmbuf);
}
Esempio n. 4
0
void 
shmsrc_tilde_on_data (shmdata_any_reader_t *reader,
		      void *shmbuf,
		      void *data,
		      int data_size,
		      unsigned long long timestamp,
		      const char *type_description, 
		      void *user_data)
{
  t_shmsrc_tilde *x = (t_shmsrc_tilde *) user_data;
  
  //do not buffer audio if dsp is off FIXME should be optionnal
  if (!canvas_dspstate)
    {
      shmdata_any_reader_free (shmbuf);
      return;
    }

  /* printf ("data %p, data size %d, timestamp %llu, type descr %s\n",   */
  /* 	  data, data_size, timestamp, type_description);   */
  GstStructure *meta_data = gst_structure_from_string (type_description, NULL);
  if (meta_data == NULL) 
    { 
      shmdata_any_reader_free (shmbuf);
      //post ("metadata is NULL\n"); 
      return; 
    } 
  if (!g_str_has_prefix (gst_structure_get_name (meta_data), "audio/")) 
    { 
      shmdata_any_reader_free (shmbuf);
      //post ("not an audio stream\n"); 
      return; 
    } //should be "audio/... 

  t_shmsrc_tilde_buf *audio_buf = g_malloc0 (sizeof (t_shmsrc_tilde_buf));

  int channels = -1; 
  int samplerate = -1; 
  int width = -1; 
  gst_structure_get (meta_data,  
   		     "rate", G_TYPE_INT, &samplerate,  
   		     "channels", G_TYPE_INT, &channels,  
   		     "width", G_TYPE_INT, &width,  
   		     NULL); 

  gst_structure_free(meta_data);

  audio_buf->num_channels_in_buf = channels; 
  if (channels > x->x_num_outlets)
    audio_buf->num_channels_to_output = x->x_num_outlets;
  else if (channels < 0)
    audio_buf->num_channels_to_output = 0;
  else 
    audio_buf->num_channels_to_output = channels;
  
  audio_buf->num_unused_channels = channels - x->x_num_outlets;
  if (audio_buf->num_unused_channels < 0)
    audio_buf->num_unused_channels = 0;

  audio_buf->sample_rate = samplerate;
  //audio_buf->sample_size = width;
  audio_buf->remaining_samples = data_size / ((width/8) * channels);
  /* g_print ("data_size %d, width %d, channels %d, samplerate %d, remaining  samples %d, cur logicial date %f \n",   */
  /* 	   data_size,    */
  /* 	   width,    */
  /* 	   channels,    */
  /* 	   samplerate,  */
  /* 	   audio_buf->remaining_samples, */
  /* 	   clock_getlogicaltime());     */
   //g_print ("on data queue size %d\n", g_async_queue_length (x->x_audio_queue));
  double audio_buf_sample_duration =  (1.0 / samplerate) * (32.*441000.); //see TIMEUNITPERSEC in m_sched.c
  audio_buf->shm_buf = shmbuf;

  //double cur_date = clock_getlogicaltime();
  /* if (x->x_stream_data_date == -1.0) */
  /*   x->x_stream_data_date = clock_getlogicaltime(); */
  if (x->x_stream_sample_duration == -1.0)
    x->x_stream_sample_duration = audio_buf_sample_duration;

  /* else */
  /* 	{ */
  /* 	  double cur_stream_dur = (cur_date - x->x_stream_data_date) / audio_buf->remaining_samples; */
  /* 	  double max_deriv = 0.001;  //FIXME make this a param */
  /* 	  if (cur_stream_dur > audio_buf_sample_duration * (1.0 + max_deriv)) */
  /* 	    cur_stream_dur = audio_buf_sample_duration * (1.0 + max_deriv); */
  /* 	  else if (cur_stream_dur < audio_buf_sample_duration * (1.0 - max_deriv)) */
  /* 	    cur_stream_dur = audio_buf_sample_duration * (1.0 - max_deriv); */

  /* 	  x->x_stream_sample_duration = audio_buf_sample_duration; */
  /* 	} */
  /*     x->x_stream_sample_duration = ceil (x->x_stream_sample_duration); */
  /*     x->x_stream_data_date = cur_date; */

  /* g_print ("rate %d, channels %d, width %d num sample=%d\n", */
  /* 	    samplerate,  */
  /* 	    channels,  */
  /* 	    width,  */
  /* 	    data_size / ((width/8) *channels));  */

  //converting to float
  audio_buf->free_audio_data = FALSE;
  audio_buf->audio_data = (t_float *)data;
  if (width == 16)
    {
      //g_print ("converting\n");
      audio_buf->free_audio_data = TRUE;
      t_float *audio_converted =  g_malloc0 (sizeof (t_float) 
					     * audio_buf->num_channels_in_buf 
					     * audio_buf->remaining_samples);
      audio_buf->audio_data = audio_converted;
      
      int n = channels *  audio_buf->remaining_samples;
      while (n--)
	{
	  *audio_converted++ = (t_float)(*(gint16 *)data * 3.051850e-05);
	  data += sizeof(gint16); 
	}
    }
  else if (width == 8)
    {
      post ("8 bit audio not supported yet");
      shmdata_any_reader_free (shmbuf);
      return;
    }
  
  audio_buf->current_pos = audio_buf->audio_data;
  g_async_queue_push (x->x_audio_queue, audio_buf);
}