~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Open Mash Cross Reference
mash/audio/decoder-mp3.cc

Component: ~ [ mash ] ~ [ apps ] ~ [ gsm ] ~ [ lib ] ~ [ otcl ] ~ [ srm ] ~ [ tcl8.3 ] ~ [ tclcl ] ~ [ tk8.3 ] ~ [ tutorials ] ~

  1 /*
  2  * decoder-mp3.cc --
  3  *
  4  *      FIXME: This file needs a description here.
  5  *
  6  * Copyright (c) 1995-2002 The Regents of the University of California.
  7  * All rights reserved.
  8  *
  9  * Redistribution and use in source and binary forms, with or without
 10  * modification, are permitted provided that the following conditions are met:
 11  *
 12  * A. Redistributions of source code must retain the above copyright notice,
 13  *    this list of conditions and the following disclaimer.
 14  * B. Redistributions in binary form must reproduce the above copyright notice,
 15  *    this list of conditions and the following disclaimer in the documentation
 16  *    and/or other materials provided with the distribution.
 17  * C. Neither the names of the copyright holders nor the names of its
 18  *    contributors may be used to endorse or promote products derived from this
 19  *    software without specific prior written permission.
 20  *
 21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
 22  * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 23  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 24  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
 25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 31  * POSSIBILITY OF SUCH DAMAGE.
 32  */
 33 
 34 static const char rcsid[] =
 35     "@(#) $Header: /usr/mash/src/repository/mash/mash-1/audio/decoder-mp3.cc,v 1.3 2002/03/01 22:23:11 mkang Exp $ (LBL)";
 36 
 37 #include "decoder.h"
 38 #include "controller.h"
 39 #include "pktbuf.h"
 40 extern "C" {
 41 #include "../../lame/include/lame.h"
 42 }
 43 
 44 class MP3Decoder : public PCM_Decoder {
 45     public:
 46         MP3Decoder();
 47         virtual void recv(pktbuf*);
 48     private:
 49         short left[8192], right[8192];
 50         u_int32_t last_seqno;
 51 };
 52 
 53 static class MP3DecoderClass : public TclClass {
 54     public:
 55         MP3DecoderClass() : TclClass("Module/AudioDecoder/MP3") {}
 56         TclObject* create(int /* argc */, const char*const* /* argv */) {
 57                 return (new MP3Decoder);
 58         };
 59 } mp3_decoder_class;
 60 
 61 MP3Decoder::MP3Decoder()
 62 {
 63         lame_decode_init();
 64         last_seqno = 0;
 65 }
 66 
 67 void MP3Decoder::recv(pktbuf* pb)
 68 {
 69         const struct rtphdr* rh = (rtphdr*)pb->dp;
 70         const u_int8_t* frame = (u_int8_t*)(rh + 1);
 71         int len = pb->len - sizeof(*rh);
 72         int outlen;
 73 
 74         if (active()) {
 75           outlen = lame_decode((unsigned char*)frame, len, left, right);
 76           if (outlen) {
 77             // fprintf(stderr, "%d %d\n", rh->rh_seqno, rh->rh_ts);
 78             if ((rh->rh_seqno - last_seqno) == 512)         
 79               consume_samples(rh, (u_int8_t*)left, outlen*2);
 80             else
 81               fprintf(stderr, "fail %d\n", rh->rh_seqno-last_seqno);
 82             last_seqno = rh->rh_seqno;
 83           }
 84         }
 85         pb->release();
 86 }
 87 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.