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;

GObject *soundcard;

GError *error;

/* instantiate AgsDevout */
soundcard = ags_devout_new(NULL);

/* create AgsAudio objects */
master_audio = (AgsAudio *) g_object_new(AGS_TYPE_AUDIO,
                                         "soundcard\0", soundcard,
                                         NULL);
slave_audio = (AgsAudio *) g_object_new(AGS_TYPE_AUDIO,
                                        "soundcard\0", 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

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

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

AgsAudio *master_audio, *slave_audio;
AgsLinkChannel *linkChannel;

GObject *soundcard;

GError *error;

/* instantiate AgsDevout */
soundcard = ags_devout_new(NULL);

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

/* 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

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

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

AgsApplicationContext *application_context;
AgsTaskThread *task_thread;

application_context = ags_application_context_get_instance();
task_thread = application_context->task_thread;

/* 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_thread_append_task(task_thread,
			    link_channel);  

link_channel = ags_link_channel_new(ags_channel_nth(master_audio->input, 1),
                                    ags_channel_nth(slave_audio->output, 1));
ags_task_thread_append_task(task_thread,
			    link_channel);