We study the Mediastreamer2 VoIP engine. Part 2

Article material taken from my zen channel .



Create a tone generator


In the previous article, we installed the media streamer library, development tools, and tested their functioning by building a trial application.


Today we will create an application that can saw through a sound card on a sound card. To solve this problem we need to connect the filters to the sound generator circuit shown below:


Sound generator circuit


, . . , . . , , , . , .


, , . , . β€” . , ( ) . , , , . , , 10 .


. , , , . , . , β€” , . , , . , . , , . .


, , . . :


/*  mstest2.c */
#include <mediastreamer2/msfilter.h>
#include <mediastreamer2/msticker.h>
#include <mediastreamer2/dtmfgen.h>
#include <mediastreamer2/mssndcard.h>
int main()
{
    ms_init();

    /*   . */
    MSFilter  *voidsource = ms_filter_new(MS_VOID_SOURCE_ID);
    MSFilter  *dtmfgen = ms_filter_new(MS_DTMF_GEN_ID);
    MSSndCard *card_playback = ms_snd_card_manager_get_default_card(ms_snd_card_manager_get());
    MSFilter  *snd_card_write = ms_snd_card_create_writer(card_playback);

    /*  . */
    MSTicker *ticker = ms_ticker_new();

    /*    . */
    ms_filter_link(voidsource, 0, dtmfgen, 0);
    ms_filter_link(dtmfgen, 0, snd_card_write, 0);

   /*   . */
   ms_ticker_attach(ticker, voidsource);

   /*   . */
   char key='1';
   ms_filter_call_method(dtmfgen, MS_DTMF_GEN_PLAY, (void*)&key);

   /* , ,        .*/
   ms_sleep(2);   
}

, : voidsource, dtmfgen, snd_card_write. .


, , . , , , " " ( ).



ms_filter_link(src, src_out, dst, dst_in)

-, β€” ( , ). -, β€” .


( ). , β€” . , .


(DTMF) "1". ms_filter_call_method() MS_DTMF_GEN_PLAY, , .


:


$ gcc mstest2.c -o mstest2 `pkg-config mediastreamer --libs --cflags`

:


$ ./mstest2

After starting the program, you will hear a short sound signal consisting of two tones in the computer dynamics.


We built and launched our first sound circuit. We saw how to create filter instances, how to connect and how to call their methods. Pleased with the first success, we still need to pay attention to the fact that our program does not release the allocated memory before terminating. In the next article, we will learn how to clean up after ourselves.


All Articles