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.5 2004/03/29 16:04:26 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.5 2004/03/29 16:04:26 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 
00075   /* pthread stuff */
00076   void _thread_init();
00077   void _thread_destroy();
00078   pthread_t _thread;
00079   pthread_attr_t _attr;
00080   pthread_mutex_t _mutex;
00081   pthread_cond_t _cond;
00082   /* ------------- */
00083 
00084   /* total seconds */
00085   int secs;
00086 
00087  public:
00088   Channel();
00089   virtual ~Channel();
00090 
00091 
00092   bool play();
00093   bool stop();
00094 
00095   /* the followings are wrappers for methods
00096      implemented inside the decoder classes
00097      means that to do a new decoder you have just
00098      to implement the following public methods in
00099      your class (inheriting Decoder from decoder.h) */
00100 
00101   MuseDec *dec; /* that's the decoder object superclass
00102                    the specific implementation is instantiated in load()
00103                    where it is recognized by parsing the filename
00104                    TODO: better ways to recognize file/stream types */
00105 
00106   /* load returns:
00107      0 = error
00108      1 = stream is seakable
00109      2 = stream is not seekable  */  
00110   virtual int load(char *file);
00111 
00112   /* seek takes from 0.0 to 1.0 float position */
00113   virtual bool pos(float pos);
00114 
00115   /* clean cleanups variables and destroys floating
00116      buffers in the decoder implementation */
00117   virtual void clean();
00118   
00119   /* ============== end of decoder implementation wrappers */
00120 
00121 
00122   void skip();
00123   float upd_time();
00124   void upd_eos();
00125   void upd_err();
00126 
00127   bool set_resampler(MuseDec *ndec);
00128 
00129   void report(); // DEBUGGING PURPOSES: call it to print out channel state
00130 
00131   Playlist *playlist;
00132 
00133   Pipe *erbapipa;
00134 
00135   float volume;
00136   float position;
00137   int speed;
00138   struct timecode time;
00139 
00140   char lcd[64];
00141 
00142   /* 0.0 - 1.0 oppure 2.0 se EOF, 3.0 se errore */
00143   float state;
00144   /*
00145   int samplerate;
00146   int channels;
00147   int bitrate;
00148   */
00149   
00150   /* frames and samples after resampling to 44khz
00151      samples = number of 44khz stereo samples */
00152   int frames;
00153   int samples;
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 Sat Apr 17 17:38:48 2004 for MuSE by doxygen1.3