Commit ac9c3420 authored by jcaceres's avatar jcaceres
Browse files

folder rearange

parents
Prosecutors will be violated.
This is hazardous code. Because no one has yet prettified it for public
consumption, we make all disclaimers and warrant that it's going to hurt
our reputation as coders, be difficult to compile, etc.
That will change, but meanwhile we can't simply let this loose
on the world without those warnings plus some instructions about freedom, liberty, copying it and commercial use. Components of the STK project are included, so this project and it's parts are subject to the "Synthesis Toolkit License" which sounds like what we intend for the rest of it. Some of the network audio technology included is patented by Stanford University and much of it is public domain. Check with Chris Chafe (the PI) if interested. Many students and other collaborators have helped with the project which began in earnest in 2000 under a grant from NSF.
Any commercial use of the code in this project should be permitted by the PI and Stanford University.
"Synthesis Toolkit License"
/******************/
Legal and Ethical Notes
This software was designed and created to be made publicly available for free,
primarily for academic purposes, so if you use it, pass it on with this
documentation, and for free. If you make a million dollars with it, give
us some. If you make compositions with it, put us in the program notes.
Some of the concepts are covered by various patents, some known to us and
likely others which are unknown. Many of the ones known to us are administered
by the Stanford Office of Technology and Licensing. The good news is that
large hunks of the techniques used here are public domain. To avoid subtle
legal issues, we will not state what's freely useable here, but we will try
to note within the various classes where certain things are likely to be
protected by patents.
Disclaimer
STK is free and we do not guarantee anything. We've been hacking on this code
for a while now and most of it seems to work pretty well. But, there surely
are some bugs floating around. Sometimes things work fine on one computer
platform but not so fine on another. FPU overflows and underflows cause very
weird behavior which also depends on the particular CPU and OS. Let us know
about bugs you find and we'll do our best to correct them.
/*! \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
//
// File: JackClient.h
// Created by: cc <cc@sony.stanford.edu>
// Created on: Sat Jul 26 13:08:21 2003
//
#ifndef _JACKCLIENT_H_
#define _JACKCLIENT_H_
#include <jack/jack.h>
#include "Stk.h"
#include "stdio.h"
#include "stdlib.h"
#include "qstring.h"
class AudioDevice;
class JackClient:public Stk
{
public:
JackClient (QString name, int nChans, int nFrames, bool output,
bool input, AudioDevice * ad, int aro = 0);
~JackClient ();
void go ();
void start ();
void stop ();
int nChans;
int nFrames;
int alsa_readable_offset;
protected:
jack_client_t * client;
const char **ports;
AudioDevice * audioDevice;
};
#endif //_JACKCLIENT_H_
//
// File: MainDialog.h
// Created by: cc <cc@cmn42.Stanford.EDU>
// Created on: Sun Mar 2 10:20:41 2003
//
#ifndef _MAINDIALOG_H_
#define _MAINDIALOG_H_
#include "../src/ui/MainWindow.h"
#include "qptrlist.h"
#include "qthread.h"
#include "qstring.h"
#include "qtimer.h"
#include "StreamBD.h"
#include "StripChart.h"
class MainDialog:public MainWindow
{
Q_OBJECT public:
MainDialog (QWidget * parent = 0, const char *name = 0);
virtual ~ MainDialog ();
void init(StreamBD *s);
StripChart *plot;
virtual void closeEvent (QCloseEvent * e);
void customEvent (QCustomEvent * e);
void addThread (QObject * t);
QPtrList < QObject > mythreads;
public slots:void goThreads (bool);
signals:void startThread ();
void stopThread ();
void joinThread ();
};
#endif //_MAINDIALOG_H_
//
// File: StreamBD.h
// Created by: User <Email>
// Created on: Tue Apr 13 22:19:53 2004
//
/**********************************************************************
* was file: streambd.cpp
**********************************************************************
* 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)
* --------------------------------------------------------------------
*/
/* I/O Streams
* -----------
* - audioin and audioout are audio in and out.
* - netin and netout are UDP network in and out.
* - streamin connects netin to audioout or netout. Command line arg networkInputQueueLengthInAudioBuffers
* determines the amount of buffering in the stream.
* - streamout connects audioin to audioout or netout. DEFAULT_OUTPUT_STREAM_QUEUE_LENGTH are used to
* buffer the connection (DEFAULT_OUTPUT_STREAM_QUEUE_LENGTH is the fewest output buffers that can
* be used reliably.
*/
#include "audio_input.h"
#include "audio_output.h"
#include "udp_input.h"
#include "udp_output.h"
#include "stream.h"
#include "udp.h"
#include <cstdlib>
#include <unistd.h>
#include <stdio.h>
#include <iostream.h>
#include "audioInfo.h"
#include "networkInfo.h"
#include <stk/Delay.h>
#include <stk/OneZero.h>
#include "stk_process.h"
#include <qhostaddress.h>
#include <qstring.h>
#include <time.h>
#include "qobject.h"
/* Define the audio sample type */
typedef signed short INT16;
#ifndef _STREAMBD_H_
#define _STREAMBD_H_
/** @brief Default settings used if not specified at the command line.
*
* Appropriate values depend on machine hardware. Faster machines
* can have lower buffer lengths without under / overrun problems etc.
*/
#define DEFAULT_SAMPLE_RATE 48000
#define DEFAULT_NETHARP_STRINGS 0
#define DEFAULT_AUDIO_CHANNELS 2
#define DEFAULT_NETWORK_QUEUE_LENGTH 2
#define DEFAULT_AUDIO_BUFFER_SIZE 128
#define DEFAULT_AUDIO_QUEUE_LENGTH 10
#define DEFAULT_HOSTNAME_MAXLENGTH 100
#define DEFAULT_NETWORK_PORT_OFFSET 0
#define DEFAULT_FIFO 0
#define DEFAULT_AUDIO_DEVICE 0 // audioDevice will choose the default device.
#define DEFAULT_SECONDS_BETWEEN_PLUCKS 1 // #Seconds between plucks, integer value.
#define DEFAULT_LOW_PASS_FILTER_COEFFICIENT 0 // Off, saves processor cycles.
#define DEFAULT_DELAY_LINE_COEFFICIENT 0 // Off, saves processor cycles.
#define DEFAULT_JACK 0 // Off
#define DEFAULT_GUI 0 // Off
#define DEFAULT_PACKET_REDUNDANCY 4 // copies of a buffer in stream
#define DEFAULT_OUTPUT_STREAM_QUEUE_LENGTH 4 //! Minimum number of buffers that can be used reliably on your hardware.
#define DEFAULT_JACK_ALSA_READABLE_OFFSET 0
/**
* @brief contains all possible command line arguments.
*/
class AudioInput;
class AudioOutput;
struct streamThreads
{
AudioInput *audioin;
AudioOutput *audioout;
UDPInput *netin;
UDPOutput *netout;
Stream *streamin;
Stream *streamout;
};
enum runModeT
{ TRANSMIT, RECEIVE, NETMIRROR, SNDMIRROR, HARPT, HARPR, AUDIOINFO };
typedef struct cmdLineArgs
{
int sampleRate; /*! Audio sample rate. */
int netHarpStrings; /*! Number of audio channels being sent over the network
* connection. In harp mode, any number of independent
* network channels (harp strings) can be run and mixed
* down to the number of audioChannels for monitoring. */
int audioChannels; /*! Number of audio channels to output on audioout. */
int networkInputQueueLengthInPackets; /*! Number of buffers of length rtBufferSize to buffer
* the incoming network connection with. */
int framesPerAudioBuffer; /*! Size of buffers to be fed to the audioDevice output
* device (in samples). */
int audioInputQueueLengthInAudioBuffers; /*! Number of buffers of size framesPerAudioBuffer with which the
* audio output is buffered. */
char remoteHostname[100]; /*! Holds the hostname to connect to in TRANSMIT and HARPT mode. */
int networkPortOffset; /*! Network port offset. */
int audioDeviceID; /*! Will use default audio device if not specified. */
int runFifo; /*! Run streambd with fifo priority (reduces delay). */
runModeT runMode; /*! Run mode as defined above. */
int secondsBetweenPlucks; /*! Number of seconds (integer) to wait between plucks. */
float lowPassFilterCoeff; /*! Specifies low-pass filter coefficient. */
int delayIncrementBetweenStrings; /*! Pitch increment between strings (cumulative). */
bool jack; /*! Use jack audio subsystem, v.1, otherwise RtAudio. */
bool gui; /*! GUI. */
int redundancy; /*! copies of a buffer in stream */
int jack_alsa_readable_offset; /*! bump up which is lowest alsa input channel */
} *cmdLineArgsT;
class AudioDevice;
class MainDialog;
class StreamBD:public QObject
{
Q_OBJECT public:
StreamBD();
~StreamBD();
int cmd (MainDialog *eventThread);
void start();
void finish();
void PrintUsage ();
struct streamThreads t;
int ParseCommandLine (int argc, char *argv[]);
QString *GetLocalHostName ();
void EstablishConnection (runModeT runMode, char *hostname,
UDPOutput * netout, UDPInput * netin);
// int get_fifo_priority (void);
// int set_fifo_priority (void);
void ConnectPlugins (InputPlugin * from, OutputPlugin * to,
Stream * through);
void addPlugin (InputPlugin * from, Stream * str);
void addPlugin (OutputPlugin * to, Stream * str);
void addSTKProcesses (Stream * str);
cmdLineArgs *args;
AudioDevice *audioDevice;
public slots:
void go ();
void stop ();
void join ();
};
#endif //_STREAMBD_H_
//
// File: PingDialog.h
// Created by: cc <cc@cmn42.Stanford.EDU>
// Created on: Sun Mar 2 10:20:41 2003
//
#ifndef _PINGSTRIPCHART_H_
#define _PINGSTRIPCHART_H_
#include <stdlib.h>
#include <qapplication.h>
#include <qwt_plot.h>
#include <qwt_math.h>
const int PLOT_SIZE = 101; // 0 to 200
//-----------------------------------------------------------------
// data_plot.cpp
//
// This example shows how to display time-varying data
// using QwtPlot.
//
//-----------------------------------------------------------------
class StripChart : public QwtPlot
{
Q_OBJECT public:
StripChart(QWidget * parent = 0, const char *name = 0);
virtual ~ StripChart ();
void dpy();
void setV1(double v1);
void setV2(double v2);
void setV3(double v3);
double v1State;
double v2State;
double v3State;
double rtt;
double stddev;
double avg;
bool _go;
protected:
virtual void timerEvent(QTimerEvent *e);
private:
double w[PLOT_SIZE], x[PLOT_SIZE], y[PLOT_SIZE], z[PLOT_SIZE];
public slots:void goPlot (bool);
};
#endif //_PINGSTRIPCHART_H_
/// The custom event class
#ifndef THREADCOMMEVENT_H
#define THREADCOMMEVENT_H
#include "qobject.h"
class ThreadCommEvent:public QCustomEvent
{
public:
ThreadCommEvent (double val0, double val1,
double val2):QCustomEvent (QEvent::User + 117),
_val0 (val0), _val1 (val1), _val2 (val2)
{
};
double val0 () const
{
return _val0;
};
double val1 () const
{
return _val1;
};
double val2 () const
{
return _val2;
};
private:
double _val0;
double _val1;
double _val2;
};
class ReverbCommEvent:public QCustomEvent
{
public:
ReverbCommEvent (double val0, double val1,
double val2):QCustomEvent (QEvent::User + 118),
_val0 (val0), _val1 (val1), _val2 (val2)
{
};
double val0 () const
{
return _val0;
};
double val1 () const
{
return _val1;
};
double val2 () const
{
return _val2;
};
private:
double _val0;
double _val1;
double _val2;
};
#endif // THREADCOMMEVENT_H
#ifndef _AUDIOCONSTS_H
#define _AUDIOCONSTS_H
#include <stdint.h>
typedef signed short INT16; /**< @brief Audio sample type. */
#endif
/**********************************************************************
* File: audioDevice.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)
* --------------------------------------------------------------------
*/
#ifndef _AUDIO_DEVICE_H
#define _AUDIO_DEVICE_H
#include <iostream>
#include <stdlib.h>
#include <math.h>
#include <stk/RtAudio.h>
#include "audioInfo.h"
#include "JackClient.h"
#include "qthread.h"
#include "StreamBD.h"
/**
* @brief Interfaces with an RtAudio sound device.
*/
// typedef class AudioDevice
class AudioDevice
{
public:
/** @brief Modes the audio device can be opened in:
*
* RECORD - The device can only be used for audio input.
* PLAYBACK - The device can only be used for audio output.
* DUPLEX - The device can be used for both input and output.
*/
enum audioDeviceModeT
{ RECORD, PLAYBACK, DUPLEX };
public:
AudioInput *inThread;
AudioOutput *outThread;
void setThreads(streamThreads t);
private:
//RtAudio *device; //!< RtAudio Device.
RtAudio * device;
JackClient *jdevice;
char *buffer; //!< Pointer to the RtAudio audio buffer.
void *jibuffer;
void *jobuffer;
int streamID; //!< RtAudio Stream ID
int audioDeviceID; //!< Audio device ID.
AudioInfoT audioInfo; //!< Relevant audio information.
int numBuffers; //!< Length of the device buffer (in buffers
//!< of size AudioInfoT->framesPerBuffer).
int bytesPerBuffer; //!< Total number of bytes per audio buffer.
int *stringsPerChan; //!< Array of number of NetHarp strings per audio output channel for audio monitoring.
bool harp; //!< Harp mode?
QSemaphore *readLock; //!< Thread protection.
QSemaphore *writeLock; //!< Thread protection.
audioDeviceModeT mode; //!< Device mode.
void generateHarpMixMap (); //!< Generates mix map for mixing X NetHarp strings to Y audio channels
void checkRequirements (int i, RtAudioDeviceInfo * info);
public:
/**
* @brief Constructor.
*
* @param audioDeviceID - The device ID of the sound device to use (-1 for default).
* @param numBuffers - The length of the queue of audio buffers maintained on the audio device.
* @param audioInfo - Relevant audio information.
*/
AudioDevice (int audioDeviceID, int numBuffers,
audioDeviceModeT mode,
AudioInfoT audioInfo);
AudioDevice (bool test);
~AudioDevice ();
/**
* @brief tick the audio device.
*
* Plays the samples currently in the buffer, and (if in duplex mode), reads in a new buffer from the audio inputs.
*/
void tick ();
/**
* @brief tick the audio device.
*
* Jack audio version, jack subsystem calls jtick.
*/
void jtick ();
/**
* @brief read a buffer of audio samples from the device into the <b>to</b> buffer. (blocks).
*/
void readBuffer (void *to);
/**
* @brief write a buffer of audio samples from the <b>from</b> buffer to the audio device buffer. (blocks).
*/
void writeBuffer (void *from);
QWaitCondition jackWait;
void bufferPtrs (void * jib, void * job);
void jackStart ();
void jackStop ();
void probeAudioDevices (); //!< Probes audio devices to see if all required functionality is supported.
void unlockRead ();
void harpTick (void *toBuffer, void *fromBuffer);
bool jack;
// } *AudioDeviceT;
};
#endif
/**********************************************************************
* File: audioInfo.h
**********************************************************************
* A project of the SoundWIRE research group at CCRMA