~ubuntu-branches/ubuntu/wily/sflphone/wily

« back to all changes in this revision

Viewing changes to daemon/src/audio/codecs/g722.cpp

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2014-01-28 18:23:36 UTC
  • mfrom: (1.1.11)
  • mto: This revision was merged to the branch mainline in revision 24.
  • Revision ID: package-import@ubuntu.com-20140128182336-3xenud1kbnwmf3mz
* New upstream release 
  - Fixes "New Upstream Release" (Closes: #735846)
  - Fixes "Ringtone does not stop" (Closes: #727164)
  - Fixes "[sflphone-kde] crash on startup" (Closes: #718178)
  - Fixes "sflphone GUI crashes when call is hung up" (Closes: #736583)
* Build-Depends: ensure GnuTLS 2.6
  - libucommon-dev (>= 6.0.7-1.1), libccrtp-dev (>= 2.0.6-3)
  - Fixes "FTBFS Build-Depends libgnutls{26,28}-dev" (Closes: #722040)
* Fix "boost 1.49 is going away" unversioned Build-Depends: (Closes: #736746)
* Add Build-Depends: libsndfile-dev, nepomuk-core-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 *  Copyright (C) 2004-2012 Savoir-Faire Linux Inc.
 
2
 *  Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
3
3
 *  Author:  Alexandre Savard <alexandre.savard@savoirfairelinux.com>
4
4
 *
5
5
 *  Mostly borrowed from asterisk's sources (Steve Underwood <steveu@coppice.org>)
41
41
 
42
42
    public:
43
43
        G722() : sfl::AudioCodec(9, "G722", 16000, 320, 1), decode_state_(),
44
 
        encode_state_() {
 
44
            encode_state_() {
45
45
            bitrate_ = 64;
46
46
            hasDynamicPayload_ = false;
47
47
 
50
50
        }
51
51
 
52
52
    private:
53
 
        int decode(SFLDataFormat *dst, unsigned char *src, size_t buf_size)
 
53
        AudioCodec *
 
54
        clone()
 
55
        {
 
56
            return new G722;
 
57
        }
 
58
 
 
59
        int decode(SFLAudioSample *dst, unsigned char *src, size_t buf_size)
54
60
        {
55
61
            return g722_decode(dst, src, buf_size);
56
62
        }
57
63
 
58
 
        int encode(unsigned char *dst, SFLDataFormat *src, size_t /*buf_size*/)
 
64
        int encode(unsigned char *dst, SFLAudioSample *src, size_t /*buf_size*/)
59
65
        {
60
66
            int out = g722_encode(dst, src, frameSize_);
61
67
            return out;
62
68
        }
63
69
 
64
 
        static void g722_state_init(g722_state_t &state)
65
 
        {
 
70
        static void g722_state_init(g722_state_t &state) {
66
71
            state.itu_test_mode = false;
67
72
 
68
73
            // 8 => 64 kbps;  7 => 56 kbps;  6 => 48 kbps
86
91
            state.out_bits = 0;
87
92
        }
88
93
 
89
 
        SFLDataFormat saturate(int32_t amp)
 
94
        SFLAudioSample saturate(int32_t amp)
90
95
        {
91
 
            SFLDataFormat amp16 = 0;
 
96
            SFLAudioSample amp16 = 0;
92
97
 
93
98
            /* Hopefully this is optimised for the common case - not clipping */
94
 
            amp16 = (SFLDataFormat) amp;
 
99
            amp16 = (SFLAudioSample) amp;
95
100
 
96
101
            if (amp == amp16)
97
102
                return amp16;
102
107
            return INT16_MIN;
103
108
        }
104
109
 
105
 
        void block4_encode(int band, int d)
106
 
        {
 
110
        void block4_encode(int band, int d) {
107
111
            int wd1 = 0;
108
112
            int wd2 = 0;
109
113
            int wd3 = 0;
207
211
 
208
212
        }
209
213
 
210
 
        void block4_decode(int band, int d)
211
 
        {
 
214
        void block4_decode(int band, int d) {
212
215
            int wd1 = 0;
213
216
            int wd2 = 0;
214
217
            int wd3 = 0;
313
316
            decode_state_.band[band].s = saturate(decode_state_.band[band].sp + decode_state_.band[band].sz);
314
317
        }
315
318
 
316
 
        int g722_decode(SFLDataFormat amp[], const uint8_t g722_data[], int len)
 
319
        int g722_decode(SFLAudioSample amp[], const uint8_t g722_data[], int len)
317
320
        {
318
321
            static const int wl[8] = {-60, -30, 58, 172, 334, 538, 1198, 3042 };
319
322
            static const int rl42[16] = {0, 7, 6, 5, 4, 3, 2, 1, 7, 6, 5, 4, 3,  2, 1, 0 };
508
511
                }
509
512
 
510
513
                if (decode_state_.itu_test_mode) {
511
 
                    amp[outlen++] = (SFLDataFormat)(rlow << 1);
512
 
                    amp[outlen++] = (SFLDataFormat)(rhigh << 1);
 
514
                    amp[outlen++] = (SFLAudioSample)(rlow << 1);
 
515
                    amp[outlen++] = (SFLAudioSample)(rhigh << 1);
513
516
                } else {
514
517
                    if (decode_state_.eight_k) {
515
 
                        amp[outlen++] = (SFLDataFormat) rlow;
 
518
                        amp[outlen++] = (SFLAudioSample) (rlow << 1);
516
519
                    } else {
517
520
                        /* Apply the receive QMF */
518
521
                        for (i = 0;  i < 22;  i++)
531
534
                            xout1 += decode_state_.x[2*i + 1]*qmf_coeffs[11 - i];
532
535
                        }
533
536
 
534
 
                        amp[outlen++] = (SFLDataFormat)(xout1 >> 12);
 
537
                        amp[outlen++] = (SFLAudioSample)(xout1 >> 11);
535
538
 
536
 
                        amp[outlen++] = (SFLDataFormat)(xout2 >> 12);
 
539
                        amp[outlen++] = (SFLAudioSample)(xout2 >> 11);
537
540
                    }
538
541
                }
539
542
            }
541
544
            return outlen;
542
545
        }
543
546
 
544
 
        int g722_encode(uint8_t g722_data[], const SFLDataFormat amp[], int len)
 
547
        int g722_encode(uint8_t g722_data[], const SFLAudioSample amp[], int len)
545
548
        {
546
549
            static const int q6[32] = {
547
550
                0,   35,   72,  110,  150,  190,  233,  276,
625
628
                        xhigh = amp[j++] >> 1;
626
629
                } else {
627
630
                    if (encode_state_.eight_k) {
628
 
                        xlow = amp[j++];
 
631
                        xlow = amp[j++] >> 1;
629
632
                    } else {
630
633
                        /* Apply the transmit QMF */
631
634
                        /* Shuffle the buffer down */
646
649
                            sumeven += encode_state_.x[2*i + 1]*qmf_coeffs[11 - i];
647
650
                        }
648
651
 
649
 
                        xlow = (sumeven + sumodd) >> 13;
 
652
                        xlow = (sumeven + sumodd) >> 14;
650
653
 
651
 
                        xhigh = (sumeven - sumodd) >> 13;
 
654
                        xhigh = (sumeven - sumodd) >> 14;
652
655
                    }
653
656
                }
654
657