Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members   File Members  

inchannels.h

Go to the documentation of this file.
00001 /* MuSE - Multiple Streaming Engine
00002  * Copyright (C) 2000-2004 Denis Rojo aka jaromil <jaromil@dyne.org>
00003  *
00004  * This source code is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Public License as published 
00006  * by the Free Software Foundation; either version 2 of the License,
00007  * or (at your option) any later version.
00008  *
00009  * This source code is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00012  * Please refer to the GNU Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Public License along with
00015  * this source code; if not, write to:
00016  * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017  *
00018  * "$Id: inchannels.h,v 1.7 2004/12/13 00:26:37 jaromil Exp $"
00019  *
00020  * different classes for different IN channels
00021  * they are instantiated and used by the Stream_mixer class (jmixer.cpp)
00022  
00023    $Id: inchannels.h,v 1.7 2004/12/13 00:26:37 jaromil Exp $
00024 
00025  */
00026 
00032 #ifndef __INCHANNELS_H__
00033 #define __INCHANNELS_H__
00034 
00035 #define MP3CHAN 1
00036 #define OGGCHAN 2
00037 
00038 #include <pthread.h>
00039 
00040 /* muse generic tweakin headers */
00041 #include <generic.h>
00042 #include <decoder.h>
00043 #include <playlist.h>
00044 #include <pipe.h>
00045 
00046 struct timecode {
00047   int h;
00048   int m;
00049   int s;
00050   float f;
00051 };
00052 
00053 /* resampler function prototype
00054    instances are in audioproc.cpp */
00055 typedef int (Resampler )(IN_DATATYPE*, IN_DATATYPE*, IN_DATATYPE*, unsigned num, float volume);
00056 
00057 
00058 /* parent class Channel
00059    this class shadows codec specific classes to the jmixer
00060    never instantiated: it's being inherited from decoders
00061 */
00062 
00063 class Channel {
00064 
00065  private:
00066   /* resample */
00067   IN_DATATYPE *resample(IN_DATATYPE *audio);
00068   /* resampling buffer */
00069   IN_DATATYPE buffo[IN_CHUNK*32];
00070   /* saved samples for interpolation */
00071   IN_DATATYPE prev_smp[4];
00072   /* resample routine pointer */
00073   Resampler *munch;
00074   /* AM: need this variable to safely call clean() - to delete the
00075      decoder/buffers etc. when the run() loop is not using them.  */
00076   bool idle;
00077 
00078   /* pthread stuff */
00079   void _thread_init();
00080   void _thread_destroy();
00081   pthread_t _thread;
00082   pthread_attr_t _attr;
00083   pthread_mutex_t _mutex;
00084   pthread_cond_t _cond;
00085   /* ------------- */
00086 
00087   /* total seconds */
00088   int secs;
00089 
00090  public:
00091   Channel();
00092   virtual ~Channel();
00093 
00094 
00095   bool play();
00096   bool stop();
00097 
00098   /* the followings are wrappers for methods
00099      implemented inside the decoder classes
00100      means that to do a new decoder you have just
00101      to implement the following public methods in
00102      your class (inheriting Decoder from decoder.h) */
00103 
00104   MuseDec *dec; /* that's the decoder object superclass
00105                    the specific implementation is instantiated in load()
00106                    where it is recognized by parsing the filename
00107                    @TODO: better ways to recognize file/stream types in Channel */
00108 
00109   /* load returns:
00110      0 = error
00111      1 = stream is seakable
00112      2 = stream is not seekable  */  
00113   virtual int load(char *file);
00114 
00115   /* seek takes from 0.0 to 1.0 float position */
00116   virtual bool pos(float pos);
00117 
00118   /* clean cleanups variables and destroys floating
00119      buffers in the decoder implementation */
00120   virtual void clean();
00121   
00122   /* ============== end of decoder implementation wrappers */
00123 
00124 
00125   void skip();
00126   float upd_time();
00127   void upd_eos();
00128   void upd_err();
00129 
00130   bool set_resampler(MuseDec *ndec);
00131 
00132   void report(); // DEBUGGING PURPOSES: call it to print out channel state
00133 
00134   Playlist *playlist;
00135 
00136   Pipe *erbapipa;
00137 
00138   float volume;
00139   float position;
00140   int speed;
00141   struct timecode time;
00142 
00143   char lcd[64];
00144 
00145   /* 0.0 - 1.0 oppure 2.0 se EOF, 3.0 se errore */
00146   float state;
00147   /*
00148   int samplerate;
00149   int channels;
00150   int bitrate;
00151   */
00152   
00153   int frames; 
00154 
00155   uint8_t playmode;
00156 
00157   bool opened;
00158   bool on;
00159   bool update;
00160   bool seekable;
00161   bool running;
00162   bool quit;
00163   bool fill_prev_smp;
00164 
00165   //  int frametot, framepos, fps;  
00166 
00167   /* pthread stuff */
00168   void start() {
00169     pthread_create(&_thread, &_attr, &kickoff, this); };
00170   void run();
00171   void lock() { pthread_mutex_lock(&_mutex); };
00172   void unlock() { pthread_mutex_unlock(&_mutex); };
00173   void wait() { pthread_cond_wait(&_cond,&_mutex); };
00174   void signal() { pthread_cond_signal(&_cond); };
00175   /* ------------- */
00176 
00177  protected:
00178   static void* kickoff(void *arg) { ((Channel *) arg)->run(); return NULL; };
00179 
00180 };
00181 
00182 /* dsp-in Channel // get sound from soundcard's dsp */
00183   
00184 class LiveIn {
00185  private:
00186   int *dsp;
00187   unsigned int num_samples;
00188   int sample_rate;
00189   int opt;
00190 
00191   int get_audio();  
00192 
00193  public:
00194   LiveIn();
00195   ~LiveIn();
00196   
00197   void init(int smpr, int chans, int *thedsp);
00198   int mix(int *mixpcm);
00199 
00200   IN_DATATYPE *gotin;
00201   int channels;
00202   int rate;
00203   bool on;
00204 };
00205 
00206 #endif

Generated on Thu Dec 16 12:28:21 2004 for MuSE by doxygen1.3