CSL  6.0
JUCEIO.cpp
Go to the documentation of this file.
1 //
2 // JUCEIO.cpp -- DAC IO using JACK
3 // See the copyright notice and acknowledgment of authors in the file COPYRIGHT
4 //
5 
6 #include "JUCEIO.h"
7 
8 using namespace csl;
9 
10 // JUCEIO Class
11 
12 JUCEIO::JUCEIO(unsigned s_rate, unsigned b_size,
13  int in_device, int out_device,
14  unsigned in_chans, unsigned out_chans)
15  : IO(s_rate, b_size, in_device, out_device, in_chans, out_chans) {
16  // initialise the device manager with no settings
17  // so that it picks a default device to use.
18 // printf("Audio IO startup\n");
19  const juce::String errorMsg (audioDeviceManager.initialise(
20  (int) in_chans, /* number of input channels */
21  (int) out_chans, /* number of output channels */
22  0, /* no XML settings.. */
23  true)); /* select default device on failure */
24  if (errorMsg.isNotEmpty()) {
25  printf("JUCEIO error: %s\n", (char *) errorMsg.toRawUTF8());
26 // AlertWindow::showMessageBox (AlertWindow::WarningIcon,
27 // String("CSL Test"),
28 // String("Couldn't open an output device!\n\n") + errorMsg);
29  }
30 // audioDeviceManager.setAudioCallback(0); // start the IO device callback later
31 
32  juce::AudioIODevice * dev = audioDeviceManager.getCurrentAudioDevice();
33  printf("Audio IO rate %g; block size %d\n", dev->getCurrentSampleRate(),
34  dev->getDefaultBufferSize());
35 
36 }
37 
39  audioDeviceManager.removeAudioCallback(this);
40 }
41 
42 ///< open/close start/stop methods
43 
44 void JUCEIO::open() throw(CException) {
45 
46 }
47 
48 void JUCEIO::close() throw(CException) {
49 
50 }
51 
52 void JUCEIO::start() throw(CException) {
53  audioDeviceManager.addAudioCallback(this);
54 
55 }
56 
57 void JUCEIO::stop() throw(CException) {
58  audioDeviceManager.removeAudioCallback(this);
59 }
60 
61 // Audio playback callback & utilities
62 
63 void JUCEIO::audioDeviceIOCallback (const float** inData, int numIns,
64  float** outData, int numOuts,
65  int numSamples) {
66  if ((mStatus != kIORunning) || (mGraph == 0)) { // if we're off or there's no input graph,
67  // just play silence...
68  for (unsigned i = 0; i < mNumInChannels; i++)
69  memset(outData[i], 0, (numSamples * sizeof(sample)));
70  return;
71  }
72  if (mNumInChannels > 0) { // if any input
73  if (mNumInChannels != numIns) {
74  logMsg(kLogError, "Wrong # in channels: expected %d got %d",
75  mNumInChannels, numIns);
76  return;
77  }
78  for (unsigned i = 0; i < mNumInChannels; i++)
79  mInputBuffer.setBuffer(i, (SampleBuffer) inData[i]);
80  mInputBuffer.mNumFrames = numSamples;
81  }
82  if (mNumOutChannels > 0) {
83  if (mNumOutChannels != numOuts) {
84  logMsg(kLogError, "Wrong # out channels: expected %d got %d",
85  mNumOutChannels, numOuts);
86  return;
87  }
88  for (unsigned i = 0; i < numOuts; i++)
89  mOutputBuffer.setBuffer(i, (SampleBuffer) outData[i]);
90  mOutputBuffer.mNumFrames = numSamples;
91  pullInput(mOutputBuffer, NULL);
92  mNumFramesPlayed += numSamples;
93  }
94  return;
95 
96 }
97 
98 
99 //void JUCEIO::audioDeviceAboutToStart (AudioIODevice * dev) {
100 //
101 //};
102 
103 //void JUCEIO::audioDeviceStopped() {
104 //
105 //};
sample * SampleBuffer
1-channel buffer data type, vector of (sample)
Definition: CSL_Types.h:194
void logMsg(const char *format,...)
These are the public logging messages.
Definition: CGestalt.cpp:292
unsigned mNumFrames
num frames used in each buffer
Definition: CSL_Core.h:113
virtual void setBuffer(unsigned bufNum, SampleBuffer sPtr)
Definition: CSL_Core.h:158
AdditiveInstrument.h – Sum-of-sines synthesis instrument class.
Definition: Accessor.h:17
void pullInput(Buffer &outBuffer, SampleBuffer out=0)
get a buffer from the CSL graph
Definition: CSL_Core.cpp:1425
void start()
start my timer thread
Definition: JUCEIO.cpp:52
JUCEIO(unsigned s_rate=CSL_mFrameRate, unsigned b_size=CSL_mBlockSize, int in_device=0, int out_device=0, unsigned in_chans=0, unsigned out_chans=2)
< Constructor (stereo by default)
Definition: JUCEIO.cpp:12
void close()
open/close start/stop methods
Definition: JUCEIO.cpp:48
juce::AudioDeviceManager audioDeviceManager
JUCE AudioDeviceManager.
Definition: JUCEIO.h:37
void audioDeviceIOCallback(const float **inputChannelData, int totalNumInputChannels, float **outputChannelData, int totalNumOutputChannels, int numSamples)
Definition: JUCEIO.cpp:63
UnitGenerator * mGraph
the root of my client DSP graph, often a mixer or panner
Definition: CSL_Core.h:777
float sample
(could be changed to int, or double)
Definition: CSL_Types.h:191
IO – the abstract I/O scheduling class; subclasses interface to specific I/O APIs.
Definition: CSL_Core.h:752
unsigned mNumFramesPlayed
counter of frames I've played
Definition: CSL_Core.h:784
virtual ~JUCEIO()
open/close start/stop methods
Definition: JUCEIO.cpp:38
unsigned mNumOutChannels
outputs
Definition: CSL_Core.h:788
IO_Status mStatus
status flag
Definition: CSL_Core.h:791
void open()
open/close start/stop methods
Definition: JUCEIO.cpp:44
Buffer mOutputBuffer
the output buffer I use (passed to nextBuffer calls)
Definition: CSL_Core.h:779
Buffer mInputBuffer
the most recent input buffer (if it's turned on)
Definition: CSL_Core.h:778
unsigned mNumInChannels
inputs
Definition: CSL_Core.h:787
void stop()
stop the timer thread
Definition: JUCEIO.cpp:57
Base class of CSL exceptions (written upper-case). Has a string message.