[asterisk-dev] How to create a slinear silent frame?

Dmitry Andrianov dimas at dataart.com
Mon May 18 08:04:53 CDT 2009


2 Holger Wirtz:

I believe you should not use calloc/free to manipulate frames.
Also, I have no idea why you are trying to manipulate "offset" frame field. This is probably the thing which makes your code crash.

	create buffer and zero it once.
..


        struct ast_frame frame = {
                .frametype = AST_FRAME_VOICE,
                .subclass = AST_FORMAT_SLINEAR,
                .data = buffer,
                .datalen = sizeof(buffer),
                .samples = samples,
                .src = __FUNCTION__,
        };

	return ast_frdup(&frame);

should work. 


2 Atis Lezdins:
one frame (20ms) is not enough to produce any beep. You will need many frames for the beep to be heard.
In any case, apps/app_morsecode.c should be good start.

Regards,
Dmitry Andrianov

-----Original Message-----
From: asterisk-dev-bounces at lists.digium.com [mailto:asterisk-dev-bounces at lists.digium.com] On Behalf Of Atis Lezdins
Sent: Monday, May 18, 2009 3:17 PM
To: Asterisk Developers Mailing List
Subject: Re: [asterisk-dev] How to create a slinear silent frame?

On Mon, May 18, 2009 at 12:36 PM, Holger Wirtz <wirtz at dfn.de> wrote:
> Hi,
>
> I tried to create an empty frame (with data set to 0000000...) but I get
>  crashes when I try to send this frames with ast_write() to a channel.
>
> I created the frame like this:
>
> --- cut here ---
> struct ast_frame* frame_create_silent_voice(int offset,int samples)
> {
>        struct ast_frame* f=NULL;
>        short *data=NULL;
>        int i=0;
>
>        if((f=calloc(1,sizeof(struct ast_frame)))==NULL)
>        {
>                ast_log(LOG_ERROR,"Unable to allocate memory for slinear
> frame\n");
>                return(NULL);
>        }
>
>        f->frametype=AST_FRAME_VOICE;
>        f->subclass=AST_FORMAT_SLINEAR;
>        f->mallocd=AST_MALLOCD_HDR|AST_MALLOCD_DATA;
>        f->samples=samples;
>        f->datalen=samples*sizeof(short);
>        f->offset=offset;
>        f->src=NULL;
>        f->data=NULL;
>
>        if((data=(short *)calloc(1,sizeof(short)*samples)+offset)==NULL)
>        {
>                ast_log(LOG_ERROR,"Unable to create array for frame
> data\n");
>                if(f!=NULL)
>                {
>                        free(f);
>                        f=NULL;
>                }
>        }
>        else
>        {
>                f->data=data;
>        }
>
>        return(f);
> }
> --- cut here ---
>
> What am I doing wrong, can anyone help?
>

While on topic, i'm also interested how to create a beep frame. There
are some frequency generations in indications.c, but i guess i'll need
just a frame :)

Regards,
Atis

-- 
Atis Lezdins,
VoIP Project Manager / Developer,
IQ Labs Inc,
atis at iq-labs.net
Skype: atis.lezdins
Cell Phone: +371 28806004
Cell Phone: +1 800 7300689
Work phone: +1 800 7502835



More information about the asterisk-dev mailing list