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

dec_jack.cpp

00001 /* MuSE - Multiple Streaming Engine
00002  * Copyright (C) 2004 Denis Roio 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: dec_jack.cpp,v 1.1 2004/12/13 00:26:36 jaromil Exp $"
00019  *
00020  */
00021 
00022 #include <dec_jack.h>
00023 #include <jutils.h>
00024 #include <config.h>
00025 
00026 #ifdef HAVE_JACK
00027 
00028 int jack_process(jack_nframes_t nframes, void *arg) {
00029   func("jack daemon callback to process %u frames",nframes);
00030   
00031   MuseDecJack *dec = (MuseDecJack*)arg;
00032   
00033   dec->jack_in_buf = (jack_default_audio_sample_t*)
00034     jack_port_get_buffer(dec->jack_in_port,nframes);
00035   
00036   dec->pipetta->write(dec->sample_size*nframes,
00037                       dec->jack_in_buf);
00038 
00039   return 0; // seems to be the success errorcode for jack
00040 }
00041 
00042 void jack_shutdown(void *arg) {
00043   func("jack daemon shutdown callback (TODO?)");
00044   MuseDecJack *dec = (MuseDecJack*)arg;
00045   dec->eos = true;
00046   jack_client_close(dec->client);
00047 }
00048 
00049 MuseDecJack::MuseDecJack() : MuseDec() {
00050   sample_size = sizeof(jack_default_audio_sample_t);
00051   pipetta = new Pipe(); // tune buffer size here
00052   pipetta->set_block(false,false);
00053   pipetta->set_output_type("copy_float_to_int32");
00054   
00055   strncpy(name,"Jack",5);
00056 }
00057 
00058 MuseDecJack::~MuseDecJack() {
00059   delete pipetta;
00060 }
00061 
00062 IN_DATATYPE *MuseDecJack::get_audio() {
00063   int res;
00064   // controlla se c'e' qualcosa nel pipe che e' provenuto dal callback
00065   // e ritorna l'informazione corretta (return code)
00066 
00067   if(eos) return NULL;
00068 
00069   err = false;
00070 
00071   res = pipetta->read(IN_CHUNK,_inbuf);
00072   if(res==IN_CHUNK) {
00073     warning("MuseDecJack::get_audio returns %u",res);
00074     frames = res;
00075 
00076   } else if(res<0) {
00077     warning("MuseDecJack::get_audio returns nothing from pipe");
00078     //    err = true;
00079     return NULL;
00080 
00081   } else {
00082     warning("MuseDecJack::get_audio buffer underrun");
00083     frames = res;
00084     return NULL;
00085   }
00086 
00087   return _inbuf;
00088 }
00089 
00090 int MuseDecJack::load(char *file) {
00091   if( (client = jack_client_new(file)) == 0 ) {
00092     error("can't open jack client. maybe the jack daemon is not running?");
00093     return 0; // return error
00094   }
00095 
00096   jack_set_process_callback(client, jack_process, this);
00097 
00098   samplerate = 44100; // jack_get_sample_rate(client);
00099   channels = 2;
00100   bitrate = 0;
00101   frametot = 0;
00102   seekable = false;
00103   eos = false;
00104 
00105   jack_on_shutdown(client, jack_shutdown, this);
00106 
00107   jack_in_port = jack_port_register(client, "input_channel",
00108                                     JACK_DEFAULT_AUDIO_TYPE,
00109                                     JackPortIsInput, 0);
00110 
00111   if(jack_activate(client)) {
00112     error("jack client opened, but unable to be activated");
00113     return 0; // error
00114   }
00115   
00116   return -2; // opened non seekable
00117 }
00118 
00119 bool MuseDecJack::seek(float pos) {
00120   func("MuseDecJack::seek(%.2f) : jack input channel can't seek!",pos);
00121   return false;
00122 }
00123 
00124 
00125 #endif // HAVE_JACK

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