Hands-On

There may be two ways how you can link AgsChannel objects.

Example 6.2. Prerequisites

#include <glib.h>
#include <glib-object.h>

#include <ags/libags.h>
#include <ags/libags-audio.h>

AgsAudio *master_audio, *slave_audio;
AgsLinkChannel *linkChannel;

AgsApplicationContext *application_context;
AgsTaskLauncher *task_launcher;

GObject *soundcard;

GError *error;

application_context = ags_application_context_get_instance();
task_launcher = ags_concurrency_provider_get_task_launcher(AGS_CONCURRENCY_PROVIDER(application_context));

/* create AgsAudio objects */
master_audio = (AgsAudio *) g_object_new(AGS_TYPE_AUDIO,
                                         "soundcard", soundcard,
                                         NULL);
slave_audio = (AgsAudio *) g_object_new(AGS_TYPE_AUDIO,
                                        "soundcard", soundcard,
                                        NULL);

/* assign AgsAudioSignal objects to master_audio and slave_audio */
ags_audio_set_flags(master_audio,
                    AGS_AUDIO_OUTPUT_HAS_RECYCLING);
ags_audio_set_flags(slave_audio,
                    (AGS_AUDIO_ASYNC | AGS_AUDIO_OUTPUT_HAS_RECYCLING | AGS_AUDIO_INPUT_HAS_RECYCLING));

/* create AgsChannel objects within master_audio and slave_audio */
ags_audio_set_audio_channels(master_audio, 2);
ags_audio_set_pads(master_audio, AGS_TYPE_OUTPUT, 1);
ags_audio_set_pads(master_audio, AGS_TYPE_INPUT, 1);
      
ags_audio_set_audio_channels(slave_audio, 2);
ags_audio_set_pads(slave_audio, AGS_TYPE_OUTPUT, 1);
ags_audio_set_pads(slave_audio, AGS_TYPE_INPUT, 8);

      

Assumed you know really what you do, you may be interested in following code.

Example 6.3. Thread-Unsafe way


/* link master_audio's input with slave_audio's output */
ags_channel_set_link(ags_channel_nth(master_audio->input, 0),
                     ags_channel_nth(slave_audio->output, 0),
                     &error);
  

ags_channel_set_link(ags_channel_nth(master_audio->input, 1),
                     ags_channel_nth(slave_audio->output, 1),
                     &error);

      

But generally you wish to create an AgsTask object and let it to link the AgsChannel for you.

Example 6.4. Multithread-Safe way

/* creating AgsLink task and add it to AgsDevout */
link_channel = ags_link_channel_new(ags_channel_nth(master_audio->input, 0),
                                    ags_channel_nth(slave_audio->output, 0));
ags_task_launcher_add_task(task_launcher,
			   link_channel);  

link_channel = ags_link_channel_new(ags_channel_nth(master_audio->input, 1),
                                    ags_channel_nth(slave_audio->output, 1));
ags_task_launcher_add_task(task_launcher,
			   link_channel);