CSL  5.2
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 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  AlertWindow::showMessageBox (AlertWindow::WarningIcon,
26  T("CSL Test"),
27  T("Couldn't open an output device!\n\n") + errorMsg);
28  }
29 // audioDeviceManager.setAudioCallback(0); // start the IO device callback later
30 
31  AudioIODevice * dev = audioDeviceManager.getCurrentAudioDevice();
32  printf("Audio IO rate %g; block size %d\n", dev->getCurrentSampleRate(),
33  dev->getDefaultBufferSize());
34 
35 }
36 
38  audioDeviceManager.removeAudioCallback(this);
39 }
40 
41 ///< open/close start/stop methods
42 
43 void JUCEIO::open() throw(CException) {
44 
45 }
46 
47 void JUCEIO::close() throw(CException) {
48 
49 }
50 
51 void JUCEIO::start() throw(CException) {
52  audioDeviceManager.addAudioCallback(this);
53 
54 }
55 
56 void JUCEIO::stop() throw(CException) {
57  audioDeviceManager.removeAudioCallback(this);
58 }
59 
60 // Audio playback callback & utilities
61 
62 void JUCEIO::audioDeviceIOCallback (const float** inData, int numIns,
63  float** outData, int numOuts,
64  int numSamples) {
65  if ((mStatus != kIORunning) || (mGraph == 0)) { // if we're off or there's no input graph,
66  // just play silence...
67  for (unsigned i = 0; i < mNumInChannels; i++)
68  memset(outData[i], 0, (numSamples * sizeof(sample)));
69  return;
70  }
71  if (mNumInChannels > 0) { // if any input
72  if (mNumInChannels != numIns) {
73  logMsg(kLogError, "Wrong # in channels: expected %d got %d",
74  mNumInChannels, numIns);
75  return;
76  }
77  for (unsigned i = 0; i < mNumInChannels; i++)
78  mInputBuffer.setBuffer(i, (SampleBuffer) inData[i]);
79  mInputBuffer.mNumFrames = numSamples;
80  }
81  if (mNumOutChannels > 0) {
82  if (mNumOutChannels != numOuts) {
83  logMsg(kLogError, "Wrong # out channels: expected %d got %d",
84  mNumOutChannels, numOuts);
85  return;
86  }
87  for (unsigned i = 0; i < numOuts; i++)
88  mOutputBuffer.setBuffer(i, (SampleBuffer) outData[i]);
89  mOutputBuffer.mNumFrames = numSamples;
90  pullInput(mOutputBuffer, NULL);
91  mNumFramesPlayed += numSamples;
92  }
93  return;
94 
95 }
96 
97 
98 //void JUCEIO::audioDeviceAboutToStart (AudioIODevice * dev) {
99 //
100 //};
101 //
102 //
103 //void JUCEIO::audioDeviceStopped() {
104 //
105 //};