Commit 2f4d247b authored by jcaceres's avatar jcaceres
Browse files

merged with trunk -r114

parent a9c1bac4
......@@ -31,8 +31,8 @@
* audioDevice.cpp
*/
#include "audioDevice.h"
#include <time.h>
#include "AudioDevice.h"
#include <ctime>
using namespace std;
AudioDevice::AudioDevice (bool testMode)
......
......@@ -35,12 +35,12 @@
#define _AUDIO_DEVICE_H
#include <iostream>
#include <stdlib.h>
#include <math.h>
#include <cstdlib>
#include <cmath>
#include "audioInfo.h"
#include "JackClient.h"
#include "qthread.h"
#include "StreamBD.h"
#include <QThread>
#include "JackTrip.h"
#include <QWaitCondition>
#include <QSemaphore>
......
......@@ -35,14 +35,14 @@
*
*/
#include "audio_input.h"
#include "stream.h"
#include "AudioInput.h"
#include "Stream.h"
#include <iostream>
using namespace std;
AudioInput::AudioInput (AudioDevice * audioDevice, AudioInfoT audioInfo):
InputPlugin ("Audio Input Plugin"),
InputStreamPlugin ("Audio Input StreamPlugin"),
audioDevice (audioDevice), audioInfo (audioInfo)
{
dontRun = audioInfo->jack;
......
......@@ -34,8 +34,8 @@
#ifndef _AUDIO_INPUT_H
#define _AUDIO_INPUT_H
#include "input_plugin.h"
#include "audioDevice.h"
#include "InputStreamPlugin.h"
#include "AudioDevice.h"
#include "audioInfo.h"
/**
......@@ -43,7 +43,7 @@
* on a Stream.
*/
class AudioInput:public InputPlugin
class AudioInput:public InputStreamPlugin
{
private:
AudioDevice * audioDevice;
......
......@@ -31,16 +31,16 @@
* audio_output.cpp
*/
#include "audio_output.h"
#include "stream.h"
#include "AudioOutput.h"
#include "Stream.h"
//#include "ambisonics/ambisonicsdecoder.h"
#include <string.h>
#include <cstring>
#include <iostream>
using namespace std;
AudioOutput::AudioOutput (AudioDevice * audioDevice, AudioInfoT audioInfo):
OutputPlugin ("Audio Output plugin"),
OutputStreamPlugin ("Audio Output plugin"),
audioDevice (audioDevice), audioInfo (audioInfo), decoder (NULL)
{
dontRun = audioInfo->jack;
......
......@@ -34,8 +34,8 @@
#ifndef _AUDIO_OUTPUT_H
#define _AUDIO_OUTPUT_H
#include "output_plugin.h"
#include "audioDevice.h"
#include "OutputStreamPlugin.h"
#include "AudioDevice.h"
#include "audioInfo.h"
class AmbisonicsDecoder;
......@@ -44,7 +44,7 @@ class AmbisonicsDecoder;
* @brief Sends audio buffers from a Stream to the RtAudio (sound) device.
*/
class AudioOutput:public OutputPlugin
class AudioOutput:public OutputStreamPlugin
{
private:
AudioDevice * audioDevice;
......
/*! \mainpage StreamBD Documentation
*
*
* Download streamBD <a
href="http://www-ccrma.stanford.edu/groups/soundwire/software/newstream/newstream1_0b.tar.gz">here</a>.
* \n
* View installation and run <a href="INSTRUCTIONS.TXT">instructions</a>.
* \n
* If you encounter CommonC++ errors (compile-time errors that begin cc_ )
* Download CommonC++1.5.0 (http://cplusplus.sourceforge.net) from here:
* <a
href="http://www-ccrma.stanford.edu/groups/soundwire/software/newstream/commomc++-1.5.0.tar>http://www-ccrma.stanford.edu/groups/soundwire/software/newstream/commonc++-1.5.0.tar</a>.
* \n
*\section intro Introduction
*
* StreamBD provides low-latency uncompressed audio streaming over high quality networks.
* It can be used to route audio streams across a high quality network, or to use the network
* connection as the delay line in a simple string synthesis to "pluck" the network, and generate
* a multi-channel network harp as described in our ICASSP2002 <a href="http://www-ccrma.stanford.edu/%7Ecc/soundwire/icassp02.pdf">paper</a>.
*
* As an audio stream router it consists of the following four nodes:
* \n\n
* audioin, audioout, netin, netout.
* \n\n
* Streambd can be run in any of the following modes to achieve any
* possible connection of input to output.
* \n\n
* <B>Transmit</B>\n
* Run with a remote hostname, this mode establishes a
* connection to a remote host running in RECEIVE mode. It
* patches audio in exactly the same way RECEIVE does:
* audioin to netout, netin to audioout. Use one machine in
* TRANSMIT mode and one machine in RECEIVE mode to establish
* a bidirectional connection.
* \n\n
* <B>Receive</B>\n
* Listen for a connection from another machine running in
* TRANSMIT mode. When contacted, patch audioin to netout and
* netin to audioout. Use one machine in RECEIVE mode and one
* machine in TRANSMIT mode to establish a bidirectional
* connection.
* \n\n
* <B>Netmirror</B>\n
* Patch netin to netout. Do not create audioin or audioout.
* (No audio interface is needed.) The input stream from the
* network is streamed straight to the network output. When run
* the program listens for a connection. When contacted by
* another machine running in TRANSMIT mode, it establishes a
* return connection. Use this mode to test your connection to
* a remote machine.
* \n\n
* <B>Sndmirror</B> \n
* Patch audioin to audioout. Do not create netin or netout.
* (No network interface is needed.) All sound input is streamed
* straight to the sound output. Use this mode to test audio
* hardware.
* \n\n
* <B>HarpT</B>\n
* Run with a hostname, this mode connects to a HARPR receiver
* machine, and adds STK low pass filtering or delay (to
* "tune" the different strings of the Netharp). Coefficients
* for the STK processes are specified at the command line (off
* by default).
* \n\n
* <B>HarpR</B>\n
* Connected to by a HARPT. Can also apply processes so that
* synthesis CPU requirements can be shared between the
* two machines (low-pass filtering on one, delay on the other.)
* \n\n
* Questions or comments: Daniel Walling (<a href="mailto:dwalling@ccrma.stanford.edu">dwalling@ccrma.stanford.edu</a>).
*/
/**********************************************************************
* File: streambd.h
**********************************************************************
* A project of the SoundWIRE research group at CCRMA
* http://www-ccrma.stanford.edu/groups/soundwire/
* --------------------------------------------------------------------
* Coded by Daniel Walling (dwalling@ccrma.stanford.edu)
* Based on Scott Wilson's streambd code (rswilson@ccrma.stanford.edu)
* --------------------------------------------------------------------
*/
#ifndef _STREAM_BD_H
#define _STREAM_BD_H
#endif
......@@ -36,18 +36,18 @@
#ifndef _INPUT_PLUGIN_H
#define _INPUT_PLUGIN_H
#include "plugin.h"
#include "StreamPlugin.h"
class Stream;
class InputPlugin : public Plugin
class InputStreamPlugin : public StreamPlugin
{
protected:
int key;
Stream *stream;
public:
InputPlugin(const char *name) : key( -1 )
InputStreamPlugin(const char *name) : key( -1 )
{
this->setName(name);
this->dontRun = false;
......
......@@ -32,9 +32,9 @@
*/
#include "JackClient.h"
#include "math.h"
#include "string.h"
#include "audioDevice.h"
#include <cmath>
#include <cstring>
#include "AudioDevice.h"
//#include "qstring.h"
#include <QString>
//#include <q3textstream.h>
......
......@@ -36,9 +36,9 @@
#define _JACKCLIENT_H_
#include <jack/jack.h>
#include "stdio.h"
#include "stdlib.h"
#include <qstring.h>
#include <cstdio>
#include <cstdlib>
#include <QString>
class AudioDevice;
class JackClient//:public Stk
......
......@@ -28,20 +28,23 @@
*/
/*
* StreamBD.cpp
* JackTrip.cpp
*/
//#include "StreamBD.h"
#include "audioDevice.h"
//#include "JackTrip.h"
#include "AudioDevice.h"
using namespace std;
extern QString *
IPv4Addr (char *namebuf);
/**
* @brief return fifo priority for streambd.
//---------------------------------------------------------------------------------------------
/*! \brief Returns fifo priority for streambd.
*
*/
//---------------------------------------------------------------------------------------------
int
get_fifo_priority (bool half)
{
......@@ -52,13 +55,16 @@ get_fifo_priority (bool half)
if (half) priority = (max - (max - min) / 2);
else
priority = max;
// priority=min;
//priority=min;
return priority;
}
/**
* @brief Set fifo priority (if user has sufficient privileges).
//---------------------------------------------------------------------------------------------
/*! \brief Set fifo priority (if user has sufficient privileges).
*
*/
//---------------------------------------------------------------------------------------------
int
set_fifo_priority (bool half)
{
......@@ -94,20 +100,33 @@ set_fifo_priority (bool half)
}
StreamBD::StreamBD()
//---------------------------------------------------------------------------------------------
/*! \brief
*/
//---------------------------------------------------------------------------------------------
JackTrip::JackTrip()
{
args = new cmdLineArgs;
}
StreamBD::~StreamBD()
//---------------------------------------------------------------------------------------------
/*! \brief
*/
//---------------------------------------------------------------------------------------------
JackTrip::~JackTrip()
{
// TODO: put destructor code here
}
//---------------------------------------------------------------------------------------------
/*! \brief
*/
//---------------------------------------------------------------------------------------------
int
StreamBD::cmd (MainDialog *eventThread)
JackTrip::cmd (MainDialog *eventThread)
{
// Get the local host address
QString *localhostName = GetLocalHostName ();
......@@ -170,7 +189,7 @@ StreamBD::cmd (MainDialog *eventThread)
t.netin = new UDPInput (netInfo, audioInfo);
t.netout = new UDPOutput (netInfo, audioInfo);
ConnectPlugins (t.netin, t.netout, t.streamout);
ConnectStreamPlugins (t.netin, t.netout, t.streamout);
break;
//remove STK dependency
......@@ -182,7 +201,7 @@ StreamBD::cmd (MainDialog *eventThread)
addSTKProcesses (t.streamin);
ConnectPlugins (t.netin, t.netout, t.streamin);
ConnectStreamPlugins (t.netin, t.netout, t.streamin);
audioDevice = new AudioDevice (args->audioDeviceID,
args->
......@@ -192,7 +211,7 @@ StreamBD::cmd (MainDialog *eventThread)
t.audioout = new AudioOutput (audioDevice, audioInfo);
addPlugin (t.audioout, t.streamin);
addStreamPlugin (t.audioout, t.streamin);
// Synchronize network packet transfers to audio device tick rate.
t.streamin->synchronizeOutputsTo (t.audioout);
......@@ -206,7 +225,7 @@ StreamBD::cmd (MainDialog *eventThread)
addSTKProcesses (t.streamout);
ConnectPlugins (t.netin, t.netout, t.streamout);
ConnectStreamPlugins (t.netin, t.netout, t.streamout);
break;
*/
......@@ -221,7 +240,7 @@ StreamBD::cmd (MainDialog *eventThread)
t.audioin = new AudioInput (audioDevice, audioInfo);
t.audioout = new AudioOutput (audioDevice, audioInfo);
ConnectPlugins (t.audioin, t.audioout, t.streamout);
ConnectStreamPlugins (t.audioin, t.audioout, t.streamout);
break;
default:
......@@ -237,12 +256,12 @@ StreamBD::cmd (MainDialog *eventThread)
audioDevice->setThreads(t);
t.netin = new UDPInput (netInfo, audioInfo);
t.netin->setGUI((QObject *)eventThread);
//t.netin->setGUI((QObject *)eventThread);
t.netout = new UDPOutput (netInfo, audioInfo);
t.netout->setGUI((QObject *)eventThread);
//t.netout->setGUI((QObject *)eventThread);
ConnectPlugins (t.audioin, t.netout, t.streamout);
ConnectPlugins (t.netin, t.audioout, t.streamin);
ConnectStreamPlugins (t.audioin, t.netout, t.streamout);
ConnectStreamPlugins (t.netin, t.audioout, t.streamin);
}
......@@ -283,13 +302,22 @@ StreamBD::cmd (MainDialog *eventThread)
}
//---------------------------------------------------------------------------------------------
/*! \brief
*/
//---------------------------------------------------------------------------------------------
void
StreamBD::start ()
JackTrip::start ()
{
}
//---------------------------------------------------------------------------------------------
/*! \brief
*/
//---------------------------------------------------------------------------------------------
void
StreamBD::finish ()
JackTrip::finish ()
{
cout << "Finishing" << endl;
if (args->jack)
......@@ -302,36 +330,52 @@ StreamBD::finish ()
cout << "stopped streamout threads" << endl;
}
//---------------------------------------------------------------------------------------------
/*! \brief
*/
//---------------------------------------------------------------------------------------------
void
StreamBD::go ()
JackTrip::go ()
/* cause run loop to start */
{
start ();
}
//---------------------------------------------------------------------------------------------
/*! \brief
*/
//---------------------------------------------------------------------------------------------
void
StreamBD::stop ()
JackTrip::stop ()
/* cause run loop to finish */
{
// loop = false; not a thread
finish();
}
//---------------------------------------------------------------------------------------------
/*! \brief
*/
//---------------------------------------------------------------------------------------------
void
StreamBD::join ()
JackTrip::join ()
/* wait for thread to exit */
{
// wait (); not a thread
}
/* PrintUsage(struct cmdLineArgs *args)
* ------------------------------------
//---------------------------------------------------------------------------------------------
/*! \brief PrintUsage()
*
* Print all of the command line arguments and their default values
*/
//---------------------------------------------------------------------------------------------
void
StreamBD::PrintUsage ()
JackTrip::PrintUsage ()
{
cout << "===========================================================================" << endl;
cout << " jacktrip A project of the SoundWIRE group at CCRMA, Stanford." << endl;
......@@ -373,14 +417,16 @@ StreamBD::PrintUsage ()
endl;
}
/**
* @brief Parse the command line.
//---------------------------------------------------------------------------------------------
/*! \brief Parse the command line.
*
* Use default values for all cmdLineArgs entries
* unless explicitly assigned values on the commandline.
*/
//---------------------------------------------------------------------------------------------
int
StreamBD::ParseCommandLine (int argc, char *argv[])
JackTrip::ParseCommandLine (int argc, char *argv[])
{
// Set Default Values
......@@ -524,8 +570,13 @@ StreamBD::ParseCommandLine (int argc, char *argv[])
return 1;
}
//---------------------------------------------------------------------------------------------
/*! \brief
*/
//---------------------------------------------------------------------------------------------
void
StreamBD::ConnectPlugins (InputPlugin * from, OutputPlugin * to, Stream * through)
JackTrip::ConnectStreamPlugins (InputStreamPlugin * from, OutputStreamPlugin * to, Stream * through)
{
from->setStream (through);
to->setStream (through);
......@@ -534,69 +585,40 @@ StreamBD::ConnectPlugins (InputPlugin * from, OutputPlugin * to, Stream * throug
through->addOutput (to);
}
//---------------------------------------------------------------------------------------------
/*! \brief
*/
//---------------------------------------------------------------------------------------------
void
StreamBD::addPlugin (InputPlugin * from, Stream * str)
JackTrip::addStreamPlugin (InputStreamPlugin * from, Stream * str)
{
from->setStream (str);
str->addInput (from);
}
//---------------------------------------------------------------------------------------------
/*! \brief
*/
//---------------------------------------------------------------------------------------------
void
StreamBD::addPlugin (OutputPlugin * to, Stream * str)
JackTrip::addStreamPlugin (OutputStreamPlugin * to, Stream * str)
{
to->setStream (str);
str->addOutput (to);
}
//Remove STK Depdency
/*
void
StreamBD::addSTKProcesses (Stream * str)
{
// Declare STK filter processes for harp mode.
OneZero *oneZero[args->netHarpStrings];
STKProcess *oneZeroProcess[args->netHarpStrings];
Delay *delay[args->netHarpStrings];
STKProcess *delayProcess[args->netHarpStrings];
// Add STKProcesses to every network channel.
int thisDelay = 0;
for (int i = 0; i < args->netHarpStrings; i++)
{
// The OneZero filter lowpasses the signal each time it reflects,
// modelling the behavior of reflections from the ends of a string.
if (args->lowPassFilterCoeff != 0)
{
oneZero[i] = new OneZero ();
oneZeroProcess[i] =
new STKProcess ((Filter *) oneZero[i]);
oneZero[i]->setGain (args->lowPassFilterCoeff / 100.0);
str->addProcess (oneZeroProcess[i]);
}
// The delay line tunes the strings so that they don't all
// have the fundamental frequency determined by the network.
if (args->delayIncrementBetweenStrings != 0)
{
thisDelay = args->delayIncrementBetweenStrings * i;
delay[i] = new Delay ((long) thisDelay, (long) thisDelay); // theDelay,maxDelay
delayProcess[i] =
new STKProcess ((Filter *) delay[i]);
str->addProcess (delayProcess[i]);
}
}
}
*/
/**
* @brief Connects, or waits for connection depending on runMode.
//---------------------------------------------------------------------------------------------
/*! \brief Connects, or waits for connection depending on runMode.
*
* If transmit or harpt, connect to hostname.
* If any other mode, wait for a peer, then connect back to that peer.
*/
//---------------------------------------------------------------------------------------------
void
StreamBD::EstablishConnection (runModeT runMode, char *hostname, UDPOutput * netout,
JackTrip::EstablishConnection (runModeT runMode, char *hostname, UDPOutput * netout,
UDPInput * netin)
{
if (runMode == TRANSMIT || runMode == HARPT)
......@@ -616,11 +638,8 @@ StreamBD::EstablishConnection (runModeT runMode, char *hostname, UDPOutput * net
usleep (10000);
//cout << ".";
}
/////FOLOW THIS TO FIND THE PROBLEM
//**************JPC COMENTED OUT*******************
cout << endl << "Connection received from: " <<
netin->peer().toString().toStdString() << endl;
//*************************************************
cout << "Requesting return connection....";
//netout->connect (netin->peer ());
netout->setPeerAddress (netin->peer ());
......@@ -628,11 +647,15 @@ StreamBD::EstablishConnection (runModeT runMode, char *hostname, UDPOutput * net
}
}
/**
* @brief Lookup the hostname of the local machine.
//---------------------------------------------------------------------------------------------
/*! \brief Lookup the hostname of the local machine.
*
*/
//---------------------------------------------------------------------------------------------
QString *
StreamBD::GetLocalHostName ()
JackTrip::GetLocalHostName ()
{
char localhostbuf[100];
if (gethostname (localhostbuf, 99))
......
......@@ -28,7 +28,7 @@
*/
/*
* StreamBD.h
* JackTrip.h
*
* I/O Streams
* -----------
......