~alextee/zrythm

e81a8b3958a65d0b4dd58b1effbc4295785c3360 — Alexandros Theodotou 3 years ago 272cd3c export_samplerate
add sample rate to export dialog
M inc/audio/exporter.h => inc/audio/exporter.h +43 -0
@@ 66,6 66,34 @@ typedef enum ExportTimeRange
  TIME_RANGE_CUSTOM,
} ExportTimeRange;

typedef enum ExportSampleRate
{
  EXPORT_SAMPLE_RATE_8000,
  EXPORT_SAMPLE_RATE_11025,
  EXPORT_SAMPLE_RATE_12000,
  EXPORT_SAMPLE_RATE_16000,
  EXPORT_SAMPLE_RATE_22050,
  EXPORT_SAMPLE_RATE_24000,
  EXPORT_SAMPLE_RATE_32000,
  EXPORT_SAMPLE_RATE_37800,
  EXPORT_SAMPLE_RATE_44056,
  EXPORT_SAMPLE_RATE_44100,
  EXPORT_SAMPLE_RATE_47250,
  EXPORT_SAMPLE_RATE_48000,
  EXPORT_SAMPLE_RATE_50000,
  EXPORT_SAMPLE_RATE_50400,
  EXPORT_SAMPLE_RATE_64000,
  EXPORT_SAMPLE_RATE_88200,
  EXPORT_SAMPLE_RATE_96000,
  EXPORT_SAMPLE_RATE_176400,
  EXPORT_SAMPLE_RATE_192000,
  EXPORT_SAMPLE_RATE_352800,
  EXPORT_SAMPLE_RATE_2822400,
  EXPORT_SAMPLE_RATE_5644800,
  EXPORT_SAMPLE_RATE_11289600,
  EXPORT_SAMPLE_RATE_22579200,
} ExportSampleRate;

/**
 * Export mode.
 *


@@ 99,6 127,9 @@ typedef struct ExportSettings

  /** Bit depth (16/24/64). */
  BitDepth          depth;

  int               sample_rate;

  ExportTimeRange   time_range;

  /** Export mode. */


@@ 201,6 232,18 @@ exporter_create_audio_track_after_bounce (
  ExportSettings * settings,
  const Position * pos);

const char *
exporter_stringize_bit_depth (
  BitDepth depth);

const char *
exporter_stringize_sample_rate (
  ExportSampleRate sample_rate);

int
exporter_sample_rate_to_int (
  ExportSampleRate sample_rate);

/**
 * Returns the audio format as string.
 *

M inc/gui/widgets/dialogs/export_dialog.h => inc/gui/widgets/dialogs/export_dialog.h +2 -1
@@ 1,5 1,5 @@
/*
 * Copyright (C) 2018-2019 Alexandros Theodotou <alex at zrythm dot org>
 * Copyright (C) 2018-2021 Alexandros Theodotou <alex at zrythm dot org>
 *
 * This file is part of Zrythm
 *


@@ 64,6 64,7 @@ typedef struct _ExportDialogWidget
  GtkToggleButton *    time_range_custom;
  GtkComboBox *        format;
  GtkComboBox *        bit_depth;
  GtkComboBox *        sample_rate;
  GtkCheckButton *     dither;
  GtkLabel *           output_label;


M resources/ui/export_dialog.ui => resources/ui/export_dialog.ui +31 -0
@@ 401,6 401,37 @@ in the directory:
                  </packing>
                </child>
                <child>
                  <object class="GtkLabel" id="label6">
                    <property name="visible">True</property>
                    <property name="can_focus">False</property>
                    <property name="margin_left">2</property>
                    <property name="margin_right">2</property>
                    <property name="margin_start">2</property>
                    <property name="margin_end">2</property>
                    <property name="label" translatable="yes">Sample rate</property>
                  </object>
                  <packing>
                    <property name="left_attach">2</property>
                    <property name="top_attach">4</property>
                  </packing>
                </child>
                <child>
                  <object class="GtkComboBox" id="sample_rate">
                    <property name="visible">True</property>
                    <property name="can_focus">False</property>
                  </object>
                  <packing>
                    <property name="left_attach">3</property>
                    <property name="top_attach">4</property>
                  </packing>
                </child>
                <child>
                  <placeholder/>
                </child>
                <child>
                  <placeholder/>
                </child>
                <child>
                  <placeholder/>
                </child>
                <child>

M scripts/gen-gschema.scm => scripts/gen-gschema.scm +13 -0
@@ 277,6 277,14 @@ Args:
           "export-bit-depth"
           '("16" "24" "32"))
         (print-enum
           "export-sample-rate"
           '("8000" "11025" "12000" "16000" "22050"
             "24000" "32000" "37800" "44056" "44100"
             "47250" "48000" "50000" "50400" "64000"
             "88200" "96000" "176400" "192000"
             "352800" "2822400" "5644800" "11289600"
             "22579200"))
         (print-enum
           "export-filename-pattern"
           '("append-format"
             "prepend-date-append-format"))


@@ 572,6 580,11 @@ Args:
                 "export-bit-depth" "24"
                 "Bit depth"
                 "Bit depth to use when exporting")
               (make-schema-key-with-enum
                 "sample-rate"
                 "export-sample-rate" "44100"
                 "Sample rate"
                 "Sample rate to use when exporting.")
             ))) ;; export

         (schema-print

M src/audio/exporter.c => src/audio/exporter.c +112 -12
@@ 52,6 52,113 @@

#define  AMPLITUDE  (1.0 * 0x7F000000)

static const char * bit_depth_strings[] =
{
  __("16 bit"),
  __("24 bit"),
  __("32 bit"),
};

const char *
exporter_stringize_bit_depth (
  BitDepth depth)
{
  return bit_depth_strings[depth];
}

static const char * sample_rate_strings[] =
{
  "8,000",
  "11,025",
  "12,000",
  "16,000",
  "22,050",
  "24,000",
  "32,000",
  "37,800",
  "44,056",
  "44,100",
  "47,250",
  "48,000",
  "50,000",
  "50,400",
  "64,000",
  "88,200",
  "96,000",
  "176,400",
  "192,000",
  "352,800",
  "2,822,400",
  "5,644,800",
  "11,289,600",
  "22,579,200",
};

const char *
exporter_stringize_sample_rate (
  ExportSampleRate sample_rate)
{
  return sample_rate_strings[sample_rate];
}

int
exporter_sample_rate_to_int (
  ExportSampleRate sample_rate)
{
  switch (sample_rate)
    {
    case EXPORT_SAMPLE_RATE_8000:
      return 8000;
    case EXPORT_SAMPLE_RATE_11025:
      return 11025;
    case EXPORT_SAMPLE_RATE_12000:
      return 12000;
    case EXPORT_SAMPLE_RATE_16000:
      return 16000;
    case EXPORT_SAMPLE_RATE_22050:
      return 22050;
    case EXPORT_SAMPLE_RATE_24000:
      return 24000;
    case EXPORT_SAMPLE_RATE_32000:
      return 32000;
    case EXPORT_SAMPLE_RATE_37800:
      return 37800;
    case EXPORT_SAMPLE_RATE_44056:
      return 44056;
    case EXPORT_SAMPLE_RATE_44100:
      return 44100;
    case EXPORT_SAMPLE_RATE_47250:
      return 47250;
    case EXPORT_SAMPLE_RATE_48000:
      return 48000;
    case EXPORT_SAMPLE_RATE_50000:
      return 50000;
    case EXPORT_SAMPLE_RATE_50400:
      return 50400;
    case EXPORT_SAMPLE_RATE_64000:
      return 64000;
    case EXPORT_SAMPLE_RATE_88200:
      return 88200;
    case EXPORT_SAMPLE_RATE_96000:
      return 96000;
    case EXPORT_SAMPLE_RATE_176400:
      return 176400;
    case EXPORT_SAMPLE_RATE_192000:
      return 192000;
    case EXPORT_SAMPLE_RATE_352800:
      return 352800;
    case EXPORT_SAMPLE_RATE_2822400:
      return 2822400;
    case EXPORT_SAMPLE_RATE_5644800:
      return 5644800;
    case EXPORT_SAMPLE_RATE_11289600:
      return 11289600;
    case EXPORT_SAMPLE_RATE_22579200:
      return 22579200;
    }
  g_return_val_if_reached (-1);
}

/**
 * Returns the audio format as string.
 *


@@ 211,18 318,9 @@ export_audio (
    }

  /* set samplerate */
  if (info->format == AUDIO_FORMAT_OGG_OPUS)
    {
      /* Opus only supports sample rates of 8000,
       * 12000, 16000, 24000 and 48000 */
      /* TODO add option */
      sfinfo.samplerate = 48000;
    }
  else
    {
      sfinfo.samplerate =
        (int) AUDIO_ENGINE->sample_rate;
    }
  sfinfo.samplerate = info->sample_rate;
  g_message (
    "using sample rate %d", info->sample_rate);

  sfinfo.channels = EXPORT_CHANNELS;



@@ 581,6 679,8 @@ export_settings_set_bounce_defaults (
  self->time_range = TIME_RANGE_CUSTOM;
  self->cancelled = false;
  self->has_error = false;
  self->sample_rate =
    (int) AUDIO_ENGINE->sample_rate;
  switch (self->mode)
    {
    case EXPORT_MODE_REGIONS:

M src/gui/widgets/dialogs/export_dialog.c => src/gui/widgets/dialogs/export_dialog.c +69 -18
@@ 586,25 586,16 @@ create_bit_depth_store ()
  GtkTreeIter iter;
  GtkTreeStore *store;

  store =
    gtk_tree_store_new (1,
                        G_TYPE_STRING);
  store = gtk_tree_store_new (1, G_TYPE_STRING);

  gtk_tree_store_append (store, &iter, NULL);
  gtk_tree_store_set (
    store, &iter,
    0, "16 bit",
    -1);
  gtk_tree_store_append (store, &iter, NULL);
  gtk_tree_store_set (
    store, &iter,
    0, "24 bit",
    -1);
  gtk_tree_store_append (store, &iter, NULL);
  gtk_tree_store_set (
    store, &iter,
    0, "32 bit",
    -1);
  for (BitDepth i = BIT_DEPTH_16;
       i <= BIT_DEPTH_32; i++)
    {
      gtk_tree_store_append (store, &iter, NULL);
      gtk_tree_store_set (
        store, &iter, 0,
        _(exporter_stringize_bit_depth (i)), -1);
    }

  return GTK_TREE_MODEL (store);
}


@@ 638,6 629,53 @@ setup_bit_depth_combo_box (
}

/**
 * Creates the combo box model for bit depth.
 */
static GtkTreeModel *
create_sample_rate_store ()
{
  GtkTreeIter iter;
  GtkTreeStore *store;

  store = gtk_tree_store_new (1, G_TYPE_STRING);

  for (ExportSampleRate i =
         EXPORT_SAMPLE_RATE_8000;
       i <= EXPORT_SAMPLE_RATE_22579200; i++)
    {
      gtk_tree_store_append (store, &iter, NULL);
      gtk_tree_store_set (
        store, &iter, 0,
        _(exporter_stringize_sample_rate (i)), -1);
    }

  return GTK_TREE_MODEL (store);
}

static void
setup_sample_rate_combo_box (
  ExportDialogWidget * self)
{
  GtkTreeModel * model =
    create_sample_rate_store ();
  gtk_combo_box_set_model (
    self->sample_rate, model);
  gtk_cell_layout_clear (
    GTK_CELL_LAYOUT (self->sample_rate));
  GtkCellRenderer* renderer =
    gtk_cell_renderer_text_new ();
  gtk_cell_layout_pack_start (
    GTK_CELL_LAYOUT (self->sample_rate),
    renderer, true);
  gtk_cell_layout_set_attributes (
    GTK_CELL_LAYOUT (self->sample_rate),
    renderer, "text", 0, NULL);

  gtk_combo_box_set_active (
    self->sample_rate, false);
}

/**
 * Creates the combo box model for the pattern.
 */
static GtkTreeModel *


@@ 756,6 794,7 @@ on_format_changed (
  SET_UNSENSITIVE (export_genre);
  SET_UNSENSITIVE (export_artist);
  SET_UNSENSITIVE (bit_depth);
  SET_UNSENSITIVE (sample_rate);
  SET_UNSENSITIVE (dither);

  switch (format)


@@ 767,12 806,14 @@ on_format_changed (
      SET_SENSITIVE (export_genre);
      SET_SENSITIVE (export_artist);
      SET_SENSITIVE (dither);
      SET_SENSITIVE (sample_rate);
      break;
    default:
      SET_SENSITIVE (export_genre);
      SET_SENSITIVE (export_artist);
      SET_SENSITIVE (bit_depth);
      SET_SENSITIVE (dither);
      SET_SENSITIVE (sample_rate);
      break;
    }



@@ 843,6 884,14 @@ init_export_info (
    gtk_combo_box_get_active (self->bit_depth);
  g_settings_set_enum (
    S_EXPORT, "bit-depth", info->depth);

  ExportSampleRate sample_rate =
    gtk_combo_box_get_active (self->sample_rate);
  g_settings_set_enum (
    S_EXPORT, "sample-rate", sample_rate);
  info->sample_rate =
    exporter_sample_rate_to_int (sample_rate);

  info->dither =
    gtk_toggle_button_get_active (
      GTK_TOGGLE_BUTTON (self->dither));


@@ 1480,6 1529,7 @@ export_dialog_widget_class_init (
  BIND_CHILD (export_genre);
  BIND_CHILD (filename_pattern);
  BIND_CHILD (bit_depth);
  BIND_CHILD (sample_rate);
  BIND_CHILD (time_range_song);
  BIND_CHILD (time_range_loop);
  BIND_CHILD (time_range_custom);


@@ 1546,6 1596,7 @@ export_dialog_widget_init (
  setup_bit_depth_combo_box (self);
  setup_formats_combo_box (self);
  setup_filename_pattern_combo_box (self);
  setup_sample_rate_combo_box (self);

  setup_treeview (self);