~ubuntu-branches/ubuntu/quantal/linphone/quantal

« back to all changes in this revision

Viewing changes to mediastreamer/msLPC10decoder.c

  • Committer: Bazaar Package Importer
  • Author(s): Samuel Mimram
  • Date: 2004-06-30 13:58:16 UTC
  • Revision ID: james.westby@ubuntu.com-20040630135816-wwx75gdlodkqbabb
Tags: upstream-0.12.2
ImportĀ upstreamĀ versionĀ 0.12.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  The mediastreamer library aims at providing modular media processing and I/O
 
3
        for linphone, but also for any telephony application.
 
4
  Copyright (C) 2001  Simon MORLAT simon.morlat@linphone.org
 
5
                                                                                
 
6
  This library is free software; you can redistribute it and/or
 
7
  modify it under the terms of the GNU Lesser General Public
 
8
  License as published by the Free Software Foundation; either
 
9
  version 2.1 of the License, or (at your option) any later version.
 
10
 
 
11
  This library is distributed in the hope that it will be useful,
 
12
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
  Lesser General Public License for more details.
 
15
 
 
16
  You should have received a copy of the GNU Lesser General Public
 
17
  License along with this library; if not, write to the Free Software
 
18
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
19
*/
 
20
 
 
21
 
 
22
#include "msLPC10decoder.h"
 
23
#include "msLPC10encoder.h"
 
24
#include <stdlib.h>
 
25
#include <lpc10.h>
 
26
 
 
27
extern MSFilter * ms_LPC10encoder_new(void);
 
28
 
 
29
MSCodecInfo LPC10info={
 
30
        {
 
31
                "LPC10-15 codec",
 
32
                0,
 
33
                MS_FILTER_AUDIO_CODEC,
 
34
                ms_LPC10encoder_new,
 
35
                "A low quality but very low bit rate codec from the U.S. Department of Defense."
 
36
        },
 
37
        ms_LPC10encoder_new,
 
38
        ms_LPC10decoder_new,
 
39
        360,
 
40
        7,
 
41
        2400,
 
42
        8000,
 
43
        115,
 
44
        "1015",
 
45
        1,
 
46
        1,
 
47
};
 
48
 
 
49
static MSLPC10DecoderClass *ms_LPC10decoder_class=NULL;
 
50
 
 
51
MSFilter * ms_LPC10decoder_new(void)
 
52
{
 
53
        MSLPC10Decoder *r;
 
54
        
 
55
        r=g_new(MSLPC10Decoder,1);
 
56
        ms_LPC10decoder_init(r);
 
57
        if (ms_LPC10decoder_class==NULL)
 
58
        {
 
59
                ms_LPC10decoder_class=g_new(MSLPC10DecoderClass,1);
 
60
                ms_LPC10decoder_class_init(ms_LPC10decoder_class);
 
61
        }
 
62
        MS_FILTER(r)->klass=MS_FILTER_CLASS(ms_LPC10decoder_class);
 
63
        return(MS_FILTER(r));
 
64
}
 
65
        
 
66
 
 
67
/* FOR INTERNAL USE*/
 
68
void ms_LPC10decoder_init(MSLPC10Decoder *r)
 
69
{
 
70
        ms_filter_init(MS_FILTER(r));
 
71
        MS_FILTER(r)->infifos=r->f_inputs;
 
72
        MS_FILTER(r)->outfifos=r->f_outputs;
 
73
        MS_FILTER(r)->r_mingran=7;
 
74
        memset(r->f_inputs,0,sizeof(MSFifo*)*MSLPC10DECODER_MAX_INPUTS);
 
75
        memset(r->f_outputs,0,sizeof(MSFifo*)*MSLPC10DECODER_MAX_INPUTS);
 
76
        r->lpc10_dec=create_lpc10_decoder_state();
 
77
}
 
78
 
 
79
void ms_LPC10decoder_class_init(MSLPC10DecoderClass *klass)
 
80
{
 
81
        ms_filter_class_init(MS_FILTER_CLASS(klass));
 
82
        ms_filter_class_set_name(MS_FILTER_CLASS(klass),"LPC10Dec");
 
83
        MS_FILTER_CLASS(klass)->max_finputs=MSLPC10DECODER_MAX_INPUTS;
 
84
        MS_FILTER_CLASS(klass)->max_foutputs=MSLPC10DECODER_MAX_INPUTS;
 
85
        MS_FILTER_CLASS(klass)->r_maxgran=7;
 
86
        MS_FILTER_CLASS(klass)->w_maxgran=LPC10_SAMPLES_PER_FRAME*2;
 
87
        MS_FILTER_CLASS(klass)->destroy=(MSFilterDestroyFunc)ms_LPC10decoder_destroy;
 
88
        MS_FILTER_CLASS(klass)->process=(MSFilterProcessFunc)ms_LPC10decoder_process;
 
89
        MS_FILTER_CLASS(klass)->info=(MSFilterInfo*)&LPC10info;
 
90
}
 
91
        
 
92
void ms_LPC10decoder_process(MSLPC10Decoder *r)
 
93
{
 
94
        MSFifo *fi,*fo;
 
95
        int err1;
 
96
        void *s,*d;
 
97
        float speech[LPC10_SAMPLES_PER_FRAME];
 
98
        INT32 bits[LPC10_BITS_IN_COMPRESSED_FRAME];
 
99
        
 
100
        /* process output fifos, but there is only one for this class of filter*/
 
101
        
 
102
        fi=r->f_inputs[0];
 
103
        fo=r->f_outputs[0];
 
104
        if (fi!=NULL)
 
105
        {
 
106
                err1=ms_fifo_get_read_ptr(fi,7,&s);
 
107
                if (err1>0)
 
108
                {
 
109
                        err1=ms_fifo_get_write_ptr(fo,LPC10_SAMPLES_PER_FRAME*2,&d);
 
110
                        if (d!=NULL)
 
111
                        {
 
112
                                read_bits(s, bits, LPC10_BITS_IN_COMPRESSED_FRAME);
 
113
                                lpc10_decode(bits,speech, r->lpc10_dec);
 
114
                                write_16bit_samples((INT16*)d, speech, LPC10_SAMPLES_PER_FRAME);
 
115
                        }
 
116
                }
 
117
        }
 
118
}
 
119
 
 
120
void ms_LPC10decoder_uninit(MSLPC10Decoder *obj)
 
121
{
 
122
        free(obj->lpc10_dec);
 
123
}
 
124
 
 
125
void ms_LPC10decoder_destroy( MSLPC10Decoder *obj)
 
126
{
 
127
        ms_LPC10decoder_uninit(obj);
 
128
        g_free(obj);
 
129
}