Exemple #1
0
/* --- dcache handle --- */
static void
dcache_handle_destroy (GslDataHandle *data_handle)
{
  DCacheHandle *dhandle = (DCacheHandle*) data_handle;
  
  gsl_data_cache_unref (dhandle->dcache);
  
  gsl_data_handle_common_free (data_handle);
  gsl_delete_struct (DCacheHandle, dhandle);
}
Exemple #2
0
static void
qsampler_set_handle (BstQSampler   *qsampler,
		     GslDataHandle *handle)
{
  GslDataCache *dcache = gsl_data_cache_new (handle, 1);
  
  gsl_data_cache_open (dcache);
  bst_qsampler_set_source (qsampler, gsl_data_handle_length (dcache->dhandle),
			   qsampler_dcache_filler, dcache, (GDestroyNotify) gsl_data_cache_close);
  gsl_data_cache_unref (dcache);
}
Exemple #3
0
void
gsl_data_cache_close (GslDataCache *dcache)
{
  gboolean need_unref;

  g_return_if_fail (dcache != NULL);
  g_return_if_fail (dcache->ref_count > 0);
  g_return_if_fail (dcache->open_count > 0);

  GSL_SPIN_LOCK (&dcache->mutex);
  dcache->open_count--;
  need_unref = !dcache->open_count;
  if (!dcache->open_count)
    {
      dcache->high_persistency = FALSE;
      gsl_data_handle_close (dcache->dhandle);
    }
  GSL_SPIN_UNLOCK (&dcache->mutex);
  if (need_unref)
    gsl_data_cache_unref (dcache);
}
Exemple #4
0
static void
findx ()
{
  GslDataCache *dcache = gsl_data_cache_new (global_handle, 1);
  GslDataHandle *shandle = gsl_data_handle_new_dcached (dcache);
  GslLong length = gsl_data_handle_length (shandle);
  GslLong l, start = 0, end = 0, lsize = gsl_data_handle_length (shandle) / 2;
  gdouble score = 0, least = GSL_MAXLONG;
  
  gsl_data_cache_unref (dcache);
  gsl_data_handle_open (shandle);
  
  while (lsize)
    {
      for (l = 0; l < length - lsize; l++)
	{
	  GslDataHandle *dhandle = gsl_data_handle_new_looped (shandle, l, l + lsize);
	  
	  gsl_data_handle_open (dhandle);
	  score = score_loop (shandle, dhandle);
	  gsl_data_handle_close (dhandle);
	  gsl_data_handle_unref (dhandle);
	  if (score < least)
	    {
	      start = l;
	      end = l + lsize;
	      g_print ("\nimproved: %f < %f: [0x%lx..0x%lx] (%lu)\n", score, least, start, end, lsize);
	      least = score;
	    }
	  g_print ("\rprocessed: %lu / %lu\r", l, length - lsize);
	}
      lsize -= 1;
    }
  gsl_data_handle_close (shandle);
  gsl_data_handle_unref (shandle);
}
Exemple #5
0
static SfiTokenType
bse_wave_restore_private (BseObject  *object,
			  BseStorage *storage,
                          GScanner   *scanner)
{
  BseWave *wave = BSE_WAVE (object);
  GTokenType expected_token;
  GQuark quark;

  /* chain parent class' handler */
  if (g_scanner_peek_next_token (scanner) != G_TOKEN_IDENTIFIER)
    return BSE_OBJECT_CLASS (parent_class)->restore_private (object, storage, scanner);

  /* parse storage commands */
  quark = g_quark_try_string (scanner->next_value.v_identifier);
  if (quark == quark_xinfos)
    {
      g_scanner_get_next_token (scanner); /* eat identifier */
      gchar **xinfos = NULL;
      GTokenType token = bse_storage_parse_xinfos (storage, &xinfos);
      if (token != G_TOKEN_NONE)
        return token;
      guint i = 0;
      for (i = 0; xinfos && xinfos[i]; i++)
        wave->xinfos = bse_xinfos_parse_assignment (wave->xinfos, xinfos[i]);
      g_strfreev (xinfos);
      parse_or_return (scanner, ')');
      expected_token = G_TOKEN_NONE; /* got ')' */
    }
  else if (quark == quark_load_wave)
    {
      BseFreqArray *skip_list, *load_list, *array;
      gchar *file_name, *wave_name;
      BseErrorType error;
      
      g_scanner_get_next_token (scanner); /* eat quark identifier */
      parse_or_return (scanner, G_TOKEN_STRING);
      file_name = g_strdup (scanner->value.v_string);
      if (g_scanner_get_next_token (scanner) != G_TOKEN_STRING)
	{
	  g_free (file_name);
	  return G_TOKEN_STRING;
	}
      wave_name = g_strdup (scanner->value.v_string);
      skip_list = bse_freq_array_new (1024);
      load_list = bse_freq_array_new (1024);
      if (BSE_STORAGE_COMPAT (storage, 0, 6, 4))
        while (g_scanner_get_next_token (scanner) != ')')
          {
            if (scanner->token == G_TOKEN_IDENTIFIER)
              {
                if (strcmp (scanner->value.v_identifier, "list") == 0)
                  array = load_list;
                else if (strcmp (scanner->value.v_identifier, "skip") == 0)
                  array = skip_list;
                else
                  {
                    expected_token = G_TOKEN_IDENTIFIER; /* want _valid_ identifier */
                    goto out_of_load_wave;
                  }
                g_scanner_peek_next_token (scanner);
                if (scanner->next_token != G_TOKEN_INT && scanner->next_token != G_TOKEN_FLOAT)
                  {
                    g_scanner_get_next_token (scanner); /* eat invalid token */
                    expected_token = G_TOKEN_FLOAT;
                    goto out_of_load_wave;
                  }
                while (g_scanner_peek_next_token (scanner) == G_TOKEN_INT ||
                       g_scanner_peek_next_token (scanner) == G_TOKEN_FLOAT)
                  {
                    g_scanner_get_next_token (scanner); /* int or float */
                    bse_freq_array_append (array, scanner->token == G_TOKEN_FLOAT ? scanner->value.v_float : scanner->value.v_int64);
                  }
              }
            else
              {
                expected_token = ')';
                goto out_of_load_wave;
              }
          }
      else
        parse_or_return (scanner, ')');
      error = bse_wave_load_wave_file (wave, file_name, wave_name,
                                       bse_freq_array_n_values (load_list) ? load_list : 0, skip_list,
                                       FALSE);
      if (error)
	bse_storage_warn (storage, "failed to load wave \"%s\" from \"%s\": %s",
			  wave_name, file_name, bse_error_blurb (error));
      expected_token = G_TOKEN_NONE; /* got ')' */
    out_of_load_wave:
      g_free (file_name);
      g_free (wave_name);
      bse_freq_array_free (skip_list);
      bse_freq_array_free (load_list);
    }
  else if (BSE_STORAGE_COMPAT (storage, 0, 6, 4) && quark == quark_set_locator)
    {
      g_scanner_get_next_token (scanner); /* eat quark identifier */
      parse_or_return (scanner, G_TOKEN_STRING);
      gchar *file_name = g_strdup (scanner->value.v_string);
      if (g_scanner_get_next_token (scanner) != G_TOKEN_STRING)
	{
	  g_free (file_name);
	  return G_TOKEN_STRING;
	}
      gchar *wave_name = g_strdup (scanner->value.v_string);
      if (g_scanner_get_next_token (scanner) != ')')
	{
	  g_free (file_name);
	  g_free (wave_name);
	  return ')';
	}
      // g_print ("set-locator \"%s\" \"%s\"\n", file_name, wave_name);
      bse_wave_set_locator (wave, file_name, wave_name);
      expected_token = G_TOKEN_NONE; /* got ')' */
    }
  else if (quark == quark_wave_chunk)
    {
      ParsedWaveChunk parsed_wchunk = { NULL, NULL, 0, 0, 0 };

      g_scanner_get_next_token (scanner); /* eat quark identifier */
      g_scanner_peek_next_token (scanner);
      bse_storage_compat_dhreset (storage); /* VERSION-FIXME: needed for <= 0.5.1 */
      if (scanner->next_token == G_TOKEN_FLOAT || scanner->next_token == G_TOKEN_INT)
        {
          g_scanner_get_next_token (scanner);
          bse_storage_compat_dhoscf (storage, /* VERSION-FIXME: needed for <= 0.5.1 */
                                     (scanner->token == G_TOKEN_INT ?
                                      scanner->value.v_int64 : scanner->value.v_float));
          g_scanner_peek_next_token (scanner);

          if (scanner->next_token == G_TOKEN_FLOAT || scanner->next_token == G_TOKEN_INT)
            {
              g_scanner_get_next_token (scanner);
              bse_storage_compat_dhmixf (storage, /* VERSION-FIXME: needed for <= 0.5.1 */
                                         (scanner->token == G_TOKEN_INT ?
                                          scanner->value.v_int64 : scanner->value.v_float));
            }
        }

      expected_token = bse_storage_parse_rest (storage, wave,
					       (BseTryStatement) parse_wave_chunk,
                                               &parsed_wchunk);
      bse_storage_compat_dhreset (storage); /* VERSION-FIXME: needed for <= 0.5.1 */

      if (expected_token == G_TOKEN_NONE && parsed_wchunk.data_handle)
	{
	  if (0)
	    g_printerr ("restore-wave-chunk: nch=%u of=%f mf=%f dh=%p\n",
                        parsed_wchunk.wh_n_channels,
                        parsed_wchunk.wh_osc_freq, parsed_wchunk.wh_mix_freq,
                        parsed_wchunk.data_handle);
          if (parsed_wchunk.data_handle && parsed_wchunk.xinfos)
            {
              GslDataHandle *tmp_handle = parsed_wchunk.data_handle;
              parsed_wchunk.data_handle = gsl_data_handle_new_add_xinfos (parsed_wchunk.data_handle, parsed_wchunk.xinfos);
              gsl_data_handle_unref (tmp_handle);
            }
	  GslDataCache *dcache = gsl_data_cache_from_dhandle (parsed_wchunk.data_handle,
                                                              BSE_CONFIG (wave_chunk_padding) * parsed_wchunk.wh_n_channels);
          const gchar *ltype = bse_xinfos_get_value (parsed_wchunk.xinfos, "loop-type");
          GslWaveLoopType loop_type = ltype ? gsl_wave_loop_type_from_string (ltype) : GSL_WAVE_LOOP_NONE;
          SfiNum loop_start = bse_xinfos_get_num (parsed_wchunk.xinfos, "loop-start");
          SfiNum loop_end = bse_xinfos_get_num (parsed_wchunk.xinfos, "loop-end");
          SfiNum loop_count = bse_xinfos_get_num (parsed_wchunk.xinfos, "loop-count");
          if (loop_end <= loop_start)
            {
              loop_start = loop_end = 0;
              loop_type = GSL_WAVE_LOOP_NONE;
              loop_count = 0;
            }
          GslWaveChunk *wchunk = gsl_wave_chunk_new (dcache, parsed_wchunk.wh_mix_freq, parsed_wchunk.wh_osc_freq,
                                                     loop_type, loop_start, loop_end, loop_count);
	  gsl_data_cache_unref (dcache);
          /* we need to keep inlined data handles open to protect against storage (.bse file) overwriting */
          BseErrorType error = bse_wave_add_inlined_wave_chunk (wave, wchunk);
          if (!error)
            bse_wave_add_chunk (wave, wchunk);
          else
            {
              bse_storage_error (storage, "failed to reopen inlined data handle (%s): %s",
                                 gsl_data_handle_name (wchunk->dcache->dhandle), bse_error_blurb (error));
              gsl_wave_chunk_unref (wchunk);
            }
	}
      if (parsed_wchunk.data_handle)
	gsl_data_handle_unref (parsed_wchunk.data_handle);
      g_strfreev (parsed_wchunk.xinfos);
    }
  else /* chain parent class' handler */
    expected_token = BSE_OBJECT_CLASS (parent_class)->restore_private (object, storage, scanner);
  
  return expected_token;
}