Ejemplo n.º 1
0
static int load_module(void *mod)
{
	int index;

	/* XXX better init ? */
	for (index = 0; index < (sizeof(ulaw_silence) / sizeof(ulaw_silence[0])); index++)
		ulaw_silence[index] = AST_LIN2MU(0);
	for (index = 0; index < (sizeof(alaw_silence) / sizeof(alaw_silence[0])); index++)
		alaw_silence[index] = AST_LIN2A(0);

	return ast_format_register(&pcm_f) || ast_format_register(&alaw_f)
		|| ast_format_register(&au_f);
}
Ejemplo n.º 2
0
/*! \brief convert and store samples in outbuf */
static int lintoulaw_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
{
	int i = f->samples;
	char *dst = pvt->outbuf.c + pvt->samples;
	int16_t *src = f->data.ptr;

	pvt->samples += i;
	pvt->datalen += i;	/* 1 byte/sample */

	while (i--)
		*dst++ = AST_LIN2MU(*src++);

	return 0;
}
static void make_tone_burst(unsigned char *data, float freq, float loudness, int len, int *x)
{
	int     i;
	float   val;
                                                                                                                                    
        for(i = 0; i < len; i++){
		val = loudness * sin((freq * 2.0 * M_PI * (*x)++)/8000.0);
		data[i] = AST_LIN2MU((int)val);
	}

	/* wrap back around from 8000 */

	if (*x >= 8000) *x = 0;
	return;
}
Ejemplo n.º 4
0
static int i4l_write(struct ast_modem_pvt *p, struct ast_frame *f)
{
#define MAX_WRITE_SIZE 2048
    unsigned char result[MAX_WRITE_SIZE << 1];
    unsigned char b;
    int bpos=0, x;
    int res;
    if (f->datalen > MAX_WRITE_SIZE) {
        ast_log(LOG_WARNING, "Discarding too big frame of size %d\n", f->datalen);
        return -1;
    }
    if (f->frametype != AST_FRAME_VOICE) {
        ast_log(LOG_WARNING, "Don't know how to handle %d type frames\n", f->frametype);
        return -1;
    }
    if (f->subclass != AST_FORMAT_SLINEAR) {
        ast_log(LOG_WARNING, "Don't know how to handle anything but signed linear frames\n");
        return -1;
    }
    for (x=0; x<f->datalen/2; x++) {
        b = AST_LIN2MU(((short *)f->data)[x]);
        result[bpos++] = b;
        if (b == CHAR_DLE)
            result[bpos++]=b;
    }
#if 0
    res = fwrite(result, bpos, 1, p->f);
    res *= bpos;
#else
    res = write(p->fd, result, bpos);
#endif
    if (res < 1) {
        if (errno != EAGAIN) {
            ast_log(LOG_WARNING, "Failed to write buffer\n");
            return -1;
        }
    }
#if 0
    printf("Result of write is %d\n", res);
#endif
    return 0;
}
Ejemplo n.º 5
0
static int load_module(void)
{
	int res;
	int x;

	for (x=0;x<256;x++) {
		mu2a[x] = AST_LIN2A(AST_MULAW(x));
		a2mu[x] = AST_LIN2MU(AST_ALAW(x));
	}

	res = ast_register_translator(&alawtoulaw);
	res |= ast_register_translator(&ulawtoalaw);

	if (res) {
		unload_module();
		return AST_MODULE_LOAD_FAILURE;
	}

	return AST_MODULE_LOAD_SUCCESS;
}
static int load_module(void)
{
	int i;

	/* XXX better init ? */
	for (i = 0; i < ARRAY_LEN(ulaw_silence); i++)
		ulaw_silence[i] = AST_LIN2MU(0);
	for (i = 0; i < ARRAY_LEN(alaw_silence); i++)
		alaw_silence[i] = AST_LIN2A(0);

	ast_format_set(&pcm_f.format, AST_FORMAT_ULAW, 0);
	ast_format_set(&alaw_f.format, AST_FORMAT_ALAW, 0);
	ast_format_set(&au_f.format, AST_FORMAT_ULAW, 0);
	ast_format_set(&g722_f.format, AST_FORMAT_G722, 0);
	if ( ast_format_def_register(&pcm_f)
		|| ast_format_def_register(&alaw_f)
		|| ast_format_def_register(&au_f)
		|| ast_format_def_register(&g722_f) )
		return AST_MODULE_LOAD_FAILURE;
	return AST_MODULE_LOAD_SUCCESS;
}
Ejemplo n.º 7
0
static int load_module(void)
{
	int res;
	int x;

	ast_format_set(&alawtoulaw.src_format, AST_FORMAT_ALAW, 0);
	ast_format_set(&alawtoulaw.dst_format, AST_FORMAT_ULAW, 0);

	ast_format_set(&ulawtoalaw.src_format, AST_FORMAT_ULAW, 0);
	ast_format_set(&ulawtoalaw.dst_format, AST_FORMAT_ALAW, 0);

	for (x=0;x<256;x++) {
		mu2a[x] = AST_LIN2A(AST_MULAW(x));
		a2mu[x] = AST_LIN2MU(AST_ALAW(x));
	}
	res = ast_register_translator(&alawtoulaw);
	if (!res)
		res = ast_register_translator(&ulawtoalaw);
	else
		ast_unregister_translator(&alawtoulaw);
	if (res)
		return AST_MODULE_LOAD_FAILURE;
	return AST_MODULE_LOAD_SUCCESS;
}