JackPort.cpp

00001 /*
00002 Copyright (C) 2001-2003 Paul Davis
00003 Copyright (C) 2004-2006 Grame
00004 
00005 This program is free software; you can redistribute it and/or modify
00006   it under the terms of the GNU General Public License as published by
00007   the Free Software Foundation; either version 2 of the License, or
00008   (at your option) any later version.
00009 
00010   This program is distributed in the hope that it will be useful,
00011   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013   GNU General Public License for more details.
00014 
00015   You should have received a copy of the GNU General Public License
00016   along with this program; if not, write to the Free Software
00017   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 
00019 */
00020 
00021 #include "JackPort.h"
00022 #include "JackError.h"
00023 #include <stdio.h>
00024 
00025 namespace Jack
00026 {
00027 
00028 JackPort::JackPort()
00029         : fFlags(JackPortIsInput), fRefNum( -1), fLatency(0), fMonitorRequests(0), fInUse(false), fLocked(false), fTied(NO_PORT)
00030 {}
00031 
00032 JackPort::~JackPort()
00033 {}
00034 
00035 void JackPort::Allocate(int refnum, const char* port_name, JackPortFlags flags)
00036 {
00037     fFlags = flags;
00038     fRefNum = refnum;
00039     strcpy(fName, port_name);
00040     memset(fBuffer, 0, BUFFER_SIZE_MAX * sizeof(float));
00041     fInUse = true;
00042     fLocked = false;
00043     fLatency = 0;
00044     fTied = NO_PORT;
00045 }
00046 
00047 void JackPort::Release()
00048 {
00049     fFlags = JackPortIsInput;
00050     fRefNum = -1;
00051     fInUse = false;
00052     fLocked = false;
00053     fLatency = 0;
00054     fTied = NO_PORT;
00055 }
00056 
00057 bool JackPort::IsUsed() const
00058 {
00059     return fInUse;
00060 }
00061 
00062 float* JackPort::GetBuffer()
00063 {
00064     return fBuffer;
00065 }
00066 
00067 int JackPort::GetRefNum() const
00068 {
00069     return fRefNum;
00070 }
00071 
00072 int JackPort::Lock()
00073 {
00074     fLocked = true;
00075     return 0;
00076 }
00077 
00078 int JackPort::Unlock()
00079 {
00080     fLocked = false;
00081     return 0;
00082 }
00083 
00084 jack_nframes_t JackPort::GetLatency() const
00085 {
00086     return fLatency;
00087 }
00088 
00089 void JackPort::SetLatency(jack_nframes_t nframes)
00090 {
00091     fLatency = nframes;
00092 }
00093 
00094 int JackPort::Tie(jack_port_id_t port_index)
00095 {
00096     fTied = port_index;
00097     return 0;
00098 }
00099 
00100 int JackPort::UnTie()
00101 {
00102     fTied = NO_PORT;
00103     return 0;
00104 }
00105 
00106 int JackPort::RequestMonitor(bool onoff)
00107 {
00117     if (onoff) {
00118         fMonitorRequests++;
00119     } else if (fMonitorRequests) {
00120         fMonitorRequests--;
00121     }
00122 
00123     return 0;
00124 }
00125 
00126 int JackPort::EnsureMonitor(bool onoff)
00127 {
00137     if (onoff) {
00138         if (fMonitorRequests == 0) {
00139             fMonitorRequests++;
00140         }
00141     } else {
00142         if (fMonitorRequests > 0) {
00143             fMonitorRequests = 0;
00144         }
00145     }
00146 
00147     return 0;
00148 }
00149 
00150 bool JackPort::MonitoringInput()
00151 {
00152     return (fMonitorRequests > 0);
00153 }
00154 
00155 const char* JackPort::GetName() const
00156 {
00157     return fName;
00158 }
00159 
00160 const char* JackPort::GetShortName() const
00161 {
00162     /* we know there is always a colon, because we put
00163        it there ...
00164     */ 
00165     return strchr(fName, ':') + 1;
00166 }
00167 
00168 int JackPort::Flags() const
00169 {
00170     return fFlags;
00171 }
00172 
00173 const char* JackPort::Type() const
00174 {
00175     // TO IMPROVE
00176     return "Audio";
00177 }
00178 
00179 int JackPort::SetName(const char* new_name)
00180 {
00181     char* colon = strchr(fName, ':');
00182     int len = sizeof(fName) - ((int) (colon - fName)) - 2;
00183     snprintf(colon + 1, len, "%s", new_name);
00184     return 0;
00185 }
00186 
00187 void JackPort::MixBuffer(float* mixbuffer, float* buffer, jack_nframes_t frames)
00188 {
00189     jack_nframes_t frames_group = frames / 4;
00190     frames = frames % 4;
00191 
00192     while (frames_group > 0) {
00193         register float mixFloat1 = *mixbuffer;
00194         register float sourceFloat1 = *buffer;
00195         register float mixFloat2 = *(mixbuffer + 1);
00196         register float sourceFloat2 = *(buffer + 1);
00197         register float mixFloat3 = *(mixbuffer + 2);
00198         register float sourceFloat3 = *(buffer + 2);
00199         register float mixFloat4 = *(mixbuffer + 3);
00200         register float sourceFloat4 = *(buffer + 3);
00201 
00202         buffer += 4;
00203         frames_group--;
00204 
00205         mixFloat1 += sourceFloat1;
00206         mixFloat2 += sourceFloat2;
00207         mixFloat3 += sourceFloat3;
00208         mixFloat4 += sourceFloat4;
00209 
00210         *mixbuffer = mixFloat1;
00211         *(mixbuffer + 1) = mixFloat2;
00212         *(mixbuffer + 2) = mixFloat3;
00213         *(mixbuffer + 3) = mixFloat4;
00214 
00215         mixbuffer += 4;
00216     }
00217 
00218     while (frames > 0) {
00219         register float mixFloat1 = *mixbuffer;
00220         register float sourceFloat1 = *buffer;
00221         buffer++;
00222         frames--;
00223         mixFloat1 += sourceFloat1;
00224         *mixbuffer = mixFloat1;
00225         mixbuffer++;
00226     }
00227 }
00228 
00229 } // end of namespace

Generated on Wed Jan 10 11:42:46 2007 for Jackdmp by  doxygen 1.4.5