Chapter 7. The recycling tree
Prev |  | Next

# Chapter 7. The recycling tree

AgsRecycling has a strong relation to AgsChannel although not every channel might have its very own recycling. Rather having a reference to a start and end region of an inter-connnected AgsRecycling. It may create or destroy audio signals event based.

Inter-connected gets its meaning as `void ags_channel_set_recycling(AgsChannel*, AgsRecycling*, AgsRecycling*, gboolean, gboolean)` invoked by `void ags_channel_set_link(AgsChannel*, AgsChannel*, GError**)` connects AgsRecycling:next and AgsRecycling:prev together from different channels. Providing you the AgsRecyclingContext. A recycling context has generally one parent and many children from different channels.

AgsRecallID points to one recycling context in order to make decisions of what level you are running in. Theoretically super-threaded tree can run upto the recycling context level.

Note, recyclings have they own recall base object AgsRecallRecycling. Usually, you do `void ags_recall_add_child(AgsRecall*, AgsRecall*)` to instances inherit of AgsRecallChannelRun.

## Add and remove audio signal

The two signals ::add_audio_signal and ::remove_audio_signal should be invoked as adding or removing AgsAudioSignal to an AgsRecycling. Recalls act as producer or consumer of AgsAudioSignal. They do basically play notation or process your effects. Its are located in AgsAudio or AgsChannel.

There is generally a need for providing a template audio signal within your recycling. As this does this example. This reduces the overhead of reading files for every playing during a button click, notation or pattern.

Example 7.1. AgsRecycling and AgsAudioSignal

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

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

    AgsRecycling *recycling;
    AgsAudioSignal *template;

    AgsApplicationContext *application_context;

    GObject *current_soundcard;

    GList *start_soundcard;

    guint stream_length;

    application_context = ags_application_context_get_instance();

    start_soundcard = ags_sound_provider_get_soundcard(AGS_SOUND_PROVIDER(application_context));

    current_soundcard = NULL;

    if(start_soundcard != NULL){
      current_soundcard = start_soundcard->data;
    }

    /* create recycling */
    recycling = ags_recycling_new(current_soundcard);

    /* create audio signal and add to recycling */
    stream_length = 5;

    audio_signal = ags_audio_signal_new(current_soundcard,
                                        recycling,
                                        NULL,
                                        stream_length);
    ags_audio_signal_set_flags(audio_signal,
    			   AGS_AUDIO_SIGNAL_TEMPLATE);
    ags_recycling_add_audio_signal(recyclig,
                                   audio_signal);

    g_list_free_full(start_soundcard,
    		 (GDestroyNotify) g_object_unref);

Prev |  | Next
Hands-On | Home | Chapter 8. Your audio data in AgsAudioSignal