Commit 89fb975e authored by jcaceres's avatar jcaceres
Browse files

merge changes with trunk

parent 71c4b609
......@@ -12,6 +12,9 @@
#include "audioDevice.h"
#include "qstring.h"
#include <q3textstream.h>
using namespace std;
jack_port_t **input_port;
jack_port_t **output_port;
jack_default_audio_sample_t **inBufPtr;
......@@ -117,7 +120,7 @@ xx_global_process_xx (unsigned int nframes, void *argc)
return 0;
}
JackClient::JackClient (QString name, int nChans, int nFrames, bool output, bool input, AudioDevice * ad, int aro):Stk ()
JackClient::JackClient (QString name, int nChans, int nFrames, bool output, bool input, AudioDevice * ad, int aro)//:Stk () //Romved STK Dependency
{
alsa_readable_offset = aro;
audioDevice = ad;
......
......@@ -8,14 +8,14 @@
#define _JACKCLIENT_H_
#include <jack/jack.h>
#include "Stk.h"
//#include "Stk.h"
#include "stdio.h"
#include "stdlib.h"
//#include "qstring.h"
#include <qstring.h>
class AudioDevice;
class JackClient:public Stk
class JackClient//:public Stk
{
public:
JackClient (QString name, int nChans, int nFrames, bool output,
......
......@@ -7,6 +7,8 @@
//#include "StreamBD.h"
#include "audioDevice.h"
using namespace std;
extern QString *
IPv4Addr (char *namebuf);
......@@ -143,7 +145,9 @@ StreamBD::cmd (MainDialog *eventThread)
ConnectPlugins (t.netin, t.netout, t.streamout);
break;
//remove STK dependency
/*
case HARPT:
t.netin = new UDPInput (netInfo, audioInfo);
......@@ -178,6 +182,7 @@ StreamBD::cmd (MainDialog *eventThread)
ConnectPlugins (t.netin, t.netout, t.streamout);
break;
*/
case SNDMIRROR:
audioDevice = new AudioDevice (args->audioDeviceID,
......@@ -515,6 +520,9 @@ StreamBD::addPlugin (OutputPlugin * to, Stream * str)
str->addOutput (to);
}
//Remove STK Depdency
/*
void
StreamBD::addSTKProcesses (Stream * str)
{
......@@ -551,7 +559,7 @@ StreamBD::addSTKProcesses (Stream * str)
}
}
}
*/
/**
* @brief Connects, or waits for connection depending on runMode.
......
......@@ -35,12 +35,13 @@
#include <cstdlib>
#include <unistd.h>
#include <stdio.h>
#include <iostream.h>
#include <iostream>
#include "audioInfo.h"
#include "networkInfo.h"
#include <stk/Delay.h>
#include <stk/OneZero.h>
#include "stk_process.h"
// Remove STK dependency
//#include <stk/Delay.h>
//#include <stk/OneZero.h>
//#include "stk_process.h"
#include <qhostaddress.h>
#include <qstring.h>
#include <time.h>
......@@ -159,8 +160,8 @@ void addPlugin (InputPlugin * from, Stream * str);
void addPlugin (OutputPlugin * to, Stream * str);
void addSTKProcesses (Stream * str);
cmdLineArgs *args;
//void addSTKProcesses (Stream * str); //Remove STK dependency
cmdLineArgs *args;
AudioDevice *audioDevice;
public slots:
void go ();
......
......@@ -8,8 +8,8 @@
* --------------------------------------------------------------------
*/
// updated for Stk 4.1.2
// RtAudio.cpp is now in project to compile with desired API
// updated for Stk 4.1.2
// RtAudio.cpp is now in project to compile with desired API
#include "audioDevice.h"
#include <time.h>
......@@ -17,170 +17,182 @@ using namespace std;
AudioDevice::AudioDevice (bool testMode)
{
if (testMode == false)
{
cerr << "You shouldn't ever call new AudioDevice( false );" <<
endl;
exit (1);
}
else
{
probeAudioDevices ();
}
if (testMode == false)
{
cerr << "You shouldn't ever call new AudioDevice( false );" <<
endl;
exit (1);
}
/*
else
{
probeAudioDevices ();
}
*/
}
AudioDevice::AudioDevice (int ID, int numBuffers, audioDeviceModeT mode,
AudioInfoT audioInfo):
audioDeviceID (ID),
audioInfo (audioInfo),
numBuffers (numBuffers),
mode (mode)
audioDeviceID (ID),
audioInfo (audioInfo),
numBuffers (numBuffers),
mode (mode)
{
streamID = 0;
int tmpBufferSize = audioInfo->getFramesPerBuffer ();
jack = audioInfo->isJack ();
if (audioInfo->getNumNetHarpStrings () > 0)
{
harp = true;
}
else
streamID = 0;
int tmpBufferSize = audioInfo->getFramesPerBuffer ();
jack = audioInfo->isJack ();
if (audioInfo->getNumNetHarpStrings () > 0)
{
harp = true;
}
else
{
harp = false;
}
if (jack)
cout << "Creating Jack audio Device.........";
/* //Remove STK Dependency
else
cout << "Creating RtAudio Device.........";
*/
//try
//{
switch (mode)
{
harp = false;
case RECORD:
if (jack)
jdevice =
new JackClient ("jacktrip",//APP_NAME, //*JPC Hack, need to fix later
audioInfo->
getNumChans (),
audioInfo->
getFramesPerBuffer (),
false, true, this,
audioInfo->getJack_alsa_readable_offset ());
/*//Remove STK Dependency
else
device = new RtAudio (streamID,
0,
ID,
audioInfo->
getNumAudioChans (),
RTAUDIO_SINT16,
audioInfo->
getSampleRate (),
&(tmpBufferSize),
numBuffers,
RtAudio::LINUX_ALSA);
*/
break;
case PLAYBACK:
if (jack)
jdevice =
new JackClient ("jacktrip",//APP_NAME, //*JPC Hack, need to fix later
audioInfo->
getNumChans (),
audioInfo->
getFramesPerBuffer (),
true, false, this,
audioInfo->getJack_alsa_readable_offset ());
/*//Remove STK Dependency
else
device = new RtAudio (streamID,
audioInfo->
getNumAudioChans (), ID,
0, RTAUDIO_SINT16,
audioInfo->
getSampleRate (),
&(tmpBufferSize),
numBuffers,
RtAudio::LINUX_ALSA);
*/
break;
case DUPLEX:
if (jack)
jdevice =
new JackClient ("jacktrip",//APP_NAME, //*JPC Hack, need to fix later
audioInfo->
getNumChans (),
audioInfo->
getFramesPerBuffer (),
true, true, this,
audioInfo->getJack_alsa_readable_offset ());
/*//Remove STK Dependency
else
device = new RtAudio ((streamID),
audioInfo->
getNumAudioChans (), ID,
audioInfo->
getNumAudioChans (),
RTAUDIO_SINT16,
audioInfo->
getSampleRate (),
&(tmpBufferSize),
numBuffers,
RtAudio::LINUX_ALSA);
*/
break;
}
if (jack)
cout << "Creating Jack audio Device.........";
else
cout << "Creating RtAudio Device.........";
try
{
switch (mode)
{
case RECORD:
if (jack)
jdevice =
new JackClient ("jacktrip",//APP_NAME, //*JPC Hack, need to fix later
audioInfo->
getNumChans (),
audioInfo->
getFramesPerBuffer (),
false, true, this,
audioInfo->getJack_alsa_readable_offset ());
else
device = new RtAudio (streamID,
0,
ID,
audioInfo->
getNumAudioChans (),
RTAUDIO_SINT16,
audioInfo->
getSampleRate (),
&(tmpBufferSize),
numBuffers,
RtAudio::LINUX_ALSA);
break;
case PLAYBACK:
if (jack)
jdevice =
new JackClient ("jacktrip",//APP_NAME, //*JPC Hack, need to fix later
audioInfo->
getNumChans (),
audioInfo->
getFramesPerBuffer (),
true, false, this,
audioInfo->getJack_alsa_readable_offset ());
else
device = new RtAudio (streamID,
audioInfo->
getNumAudioChans (), ID,
0, RTAUDIO_SINT16,
audioInfo->
getSampleRate (),
&(tmpBufferSize),
numBuffers,
RtAudio::LINUX_ALSA);
break;
case DUPLEX:
if (jack)
jdevice =
new JackClient ("jacktrip",//APP_NAME, //*JPC Hack, need to fix later
audioInfo->
getNumChans (),
audioInfo->
getFramesPerBuffer (),
true, true, this,
audioInfo->getJack_alsa_readable_offset ());
else
device = new RtAudio ((streamID),
audioInfo->
getNumAudioChans (), ID,
audioInfo->
getNumAudioChans (),
RTAUDIO_SINT16,
audioInfo->
getSampleRate (),
&(tmpBufferSize),
numBuffers,
RtAudio::LINUX_ALSA);
break;
}
}
catch (RtError (&m))
//}
/*//Remove STK Dependency
catch (RtError (&m))
{
cout << "FAILED!" << endl;
m.printMessage ();
probeAudioDevices ();
exit (1);
}
*/
cout << "SUCCESS!" << endl;
/*//Remove STK Dependency
if (tmpBufferSize != audioInfo->getFramesPerBuffer ())
{
cerr << "RtAudio device could not use requested buffer length of " << audioInfo->getFramesPerBuffer () << " frames. Using " << tmpBufferSize << endl;
audioInfo->setFramesPerBuffer (tmpBufferSize);
}
*/
/*//Remove STK Dependency
if (!jack)
{
if (device == NULL)
{
cout << "FAILED!" << endl;
m.printMessage ();
probeAudioDevices ();
exit (1);
cerr << "RtAudio Device is NULL!" << endl;
probeAudioDevices ();
}
buffer = device->getStreamBuffer ();
cout << "SUCCESS!" << endl;
if (tmpBufferSize != audioInfo->getFramesPerBuffer ())
{
cerr << "RtAudio device could not use requested buffer length of " << audioInfo->getFramesPerBuffer () << " frames. Using " << tmpBufferSize << endl;
audioInfo->setFramesPerBuffer (tmpBufferSize);
}
if (!jack)
{
if (device == NULL)
{
cerr << "RtAudio Device is NULL!" << endl;
probeAudioDevices ();
}
buffer = device->getStreamBuffer ();
if (buffer == NULL)
{
cerr << "RtAudio device buffer is NULL!" << endl;
probeAudioDevices ();
}
}
bytesPerBuffer = audioInfo->getBytesPerBuffer ();
if (harp == true)
{
generateHarpMixMap ();
}
else
{
readLock = new QSemaphore (1);
writeLock = new QSemaphore (1);
//(*writeLock)++; // lock out write, to start with read
(*writeLock).acquire(); //****JPC qt4 porting******
}
if (jack)
if (buffer == NULL)
{
cerr << "RtAudio device buffer is NULL!" << endl;
probeAudioDevices ();
}
else
device->startStream ();
}
*/
bytesPerBuffer = audioInfo->getBytesPerBuffer ();
if (harp == true)
{
generateHarpMixMap ();
}
else
{
readLock = new QSemaphore (1);
writeLock = new QSemaphore (1);
//(*writeLock)++; // lock out write, to start with read
(*writeLock).acquire(); //****JPC qt4 porting******
}
if (jack)
{
}
//else //Remove STK Dependency
// device->startStream ();
}
AudioDevice::~AudioDevice ()
......@@ -190,136 +202,138 @@ AudioDevice::~AudioDevice ()
void
AudioDevice::jackStart ()
{
cout << "jack start" << endl;
jdevice->start ();
cout << "jack start" << endl;
jdevice->start ();
}
void
AudioDevice::jackStop ()
{
cout << "jack stop" << endl;
jdevice->stop ();
cout << "jack stop" << endl;
jdevice->stop ();
}
/*
void
AudioDevice::tick ()
{
try
try
{
device->tickStream (); // blocks until transfer completed
if (audioInfo->lastTickTime)
{
device->tickStream (); // blocks until transfer completed
if (audioInfo->lastTickTime)
{
clock_t newTime = clock ();
fprintf (stderr, "Audio Tick,%d,%d,%.5f\n", newTime,
*(audioInfo->lastTickTime),
(newTime -
*(audioInfo->lastTickTime)) *
CLOCKS_PER_SEC);
*(audioInfo->lastTickTime) = newTime;
}
}
catch (RtError (&m))
{
m.printMessage ();
clock_t newTime = clock ();
fprintf (stderr, "Audio Tick,%d,%d,%.5f\n", newTime,
*(audioInfo->lastTickTime),
(newTime -
*(audioInfo->lastTickTime)) *
CLOCKS_PER_SEC);
*(audioInfo->lastTickTime) = newTime;
}
}
catch (RtError (&m))
{
m.printMessage ();
}
}
*/
void
AudioDevice::jtick () // called by jack process after transfer completed
{
// jackWait.wakeAll ();
// cout << "jtick" << endl;
// jackWait.wakeAll ();
// cout << "jtick" << endl;
}
void
AudioDevice::bufferPtrs (void *jib, void *job)
{
// jibuffer = jib;
// jobuffer = job;
// jibuffer = jib;
// jobuffer = job;
}
void
AudioDevice::unlockRead ()
{
//(*readLock)--; // so audio input thread will unblock when stopped
(*readLock).release();//****JPC qt4 porting******
(*readLock).release();//****JPC qt4 porting******
}
void
AudioDevice::readBuffer (void *to)
{
if (mode == PLAYBACK)
{
cerr << "ERROR: AudioDevice::readBuffer called on device in PLAYBACK mode!" << endl;
}
if (mode == PLAYBACK)
{
cerr << "ERROR: AudioDevice::readBuffer called on device in PLAYBACK mode!" << endl;
}
//(*readLock)++;
(*readLock).acquire();//****JPC qt4 porting******
memcpy (to, buffer, bytesPerBuffer);
//(*writeLock)--;
(*writeLock).release();//****JPC qt4 porting******
//(*readLock)++;
(*readLock).acquire();//****JPC qt4 porting******
memcpy (to, buffer, bytesPerBuffer);
//(*writeLock)--;
(*writeLock).release();//****JPC qt4 porting******
}
void
AudioDevice::writeBuffer (void *from)
{
if (mode == RECORD)
{
cerr << "ERROR: AudioDevice::writeBuffer called on device in RECORD mode!" << endl;
}
if (harp == false)
{
if (mode == RECORD)
{
cerr << "ERROR: AudioDevice::writeBuffer called on device in RECORD mode!" << endl;
}
if (harp == false)
{
//(*writeLock)++;
(*writeLock).acquire();//****JPC qt4 porting******
memcpy (buffer, from, bytesPerBuffer);
tick (); // calls tickstream, blocks
//(*readLock)--;
(*readLock).release();//****JPC qt4 porting******
//(*writeLock)++;
(*writeLock).acquire();//****JPC qt4 porting******
memcpy (buffer, from, bytesPerBuffer);
//tick (); // calls tickstream, blocks
//(*readLock)--;
(*readLock).release();//****JPC qt4 porting******
}
else
{
}
else
{
harpTick (buffer, from);
tick ();
harpTick (buffer, from);
//tick ();
}
}
}
void
AudioDevice::harpTick (void *toBuffer, void *fromBuffer)
{
double nextSample;
int stringIndex = 0;
int sndChans = audioInfo->getNumAudioChans ();
int netChans = audioInfo->getNumNetHarpStrings ();
for (int frameIndex = 0;
frameIndex < audioInfo->getFramesPerBuffer (); frameIndex++)
double nextSample;
int stringIndex = 0;
int sndChans = audioInfo->getNumAudioChans ();
int netChans = audioInfo->getNumNetHarpStrings ();
for (int frameIndex = 0;
frameIndex < audioInfo->getFramesPerBuffer (); frameIndex++)
{
stringIndex = 0;
for (int chanIndex = 0; chanIndex < sndChans; chanIndex++)
{
stringIndex = 0;
for (int chanIndex = 0; chanIndex < sndChans; chanIndex++)
{
nextSample = 0.0;
for (int sampleIndex = 0;
sampleIndex < stringsPerChan[chanIndex];