CSL  6.0
Test_Audio.cpp
Go to the documentation of this file.
1 //
2 // Test_Audio.cpp -- Streaming audio IO tests
3 //
4 // See the copyright notice and acknowledgment of authors in the file COPYRIGHT
5 //
6 
7 #ifdef USE_JUCE
8  #include "Test_Support.h"
9  #include "JuceHeader.h"
10 #else
11  #define USE_TEST_MAIN // use the main() function in test_support.h
12  #include "Test_Support.cpp" // include all of CSL core and the test support functions
13 #endif
14 
15 using namespace csl;
16 
17 extern juce::AudioDeviceManager * gAudioDeviceManager; // global JUCE audio device mgr
18 
19 // dump io port-type & device names
20 
21 void audio_dump() {
22  for (unsigned i = 0; i < gAudioDeviceManager->getAvailableDeviceTypes().size(); i++) {
23  logMsg(" AudioIODeviceType %s",
24  (const char *) gAudioDeviceManager->getAvailableDeviceTypes().getUnchecked(i)->getTypeName().toUTF8());
25  juce::StringArray devs = gAudioDeviceManager->getAvailableDeviceTypes().getUnchecked(i)->getDeviceNames();
26  for (unsigned j = 0; j < devs.size(); j++) {
27  logMsg(" Device %s", (const char *) devs[j].toUTF8() );
28  }
29  }
30  juce::AudioIODevice * adm = gAudioDeviceManager->getCurrentAudioDevice();
31  logMsg("Current AudioIODevice = %s : %s", (const char *) adm->getTypeName().toUTF8(),
32  (const char *) adm->getName().toUTF8());
33 }
34 
35 // echo mic back using an InOut
36 
37 void mic_test() {
38 // CGestalt::setNumInChannels(2);
39  // set up InOut UGen to copy input to effect
40  InOut mio(theIO, 2, 2); // stereo i/o
41  logMsg("playing mic in unaltered...");
42  runTest(mio, 10); // 10 sec
43  logMsg("done.\n");
44 }
45 
46 // Apply a BPF to the input
47 
48 void filt_test() {
49  InOut mio(theIO, 2, 1); // mono input
50  Butter bpf(mio, BW_BAND_PASS, 1000.f, 100.f);
51  logMsg("playing filter on mic in...");
52  runTest(bpf, 10); // 10 sec
53  logMsg("done.\n");
54 }
55 
56 // Add echo to the input
57 
58 void echo_test() {
59  InOut mio(theIO, 2, 2); // stereo i/o
60  Stereoverb mReverb(mio); // stereo reverb
61  mReverb.setRoomSize(0.988); // long reverb time
62  logMsg("playing echo on mic in...");
63  runTest(mReverb, 10); // 10 sec
64  logMsg("done.\n");
65 }
66 
67 // pan the input
68 
69 void panner_test() {
70  InOut mio(theIO, 2, 1); // mono input
71  Osc lfo(0.5, 1, 0, CSL_PI); // position LFO
72  Panner pan(mio, lfo); // panner
73  logMsg("playing panner on mic in...");
74  runTest(pan, 10); // 10 sec
75  logMsg("done.\n");
76 }
77 
78 //////////////////////////////////////////////////////////////////////////////
79 
80 // make an Audio listener class -- implement update() and store in-coming audio
81 
82 //class AudioListener : public Observer {
83 //public:
84 // // update message prints to the log
85 // void update(void * arg) {
86 // }
87 // // constructor
88 // AudioListener(MIDIIn * in) : mIn(in) { };
89 // // data member for the input
90 // AudioListener * mIn;
91 //
92 //};
93 //
94 ///// Create a MIDI in and attach a filtering listener to it
95 //
96 void listener_test() {
97 // MIDIIn in;
98 // in.open(DEFAULT_MIDI_IN);
99 // MIDIListener lst(&in); // create a listener
100 //// lst.mPeriod = 0.25;
101 // lst.mKey = kNoteOn; // filter noteOn events
102 // in.attachObserver(&lst); // attach observer to input
103 // logMsg("Start MIDI listener");
104 // in.start();
105 //
106 // sleepSec(10);
107 //
108 // logMsg("done.");
109 // in.stop();
110 // in.close();
111 }
112 
113 // test list for Juce GUI
114 
116  "Dump audio ports", audio_dump, "Dump list of audio ports to stdout",
117  "Echo audio in", mic_test, "Play the microphone input back the output",
118  "Filter input", filt_test, "Apply a band-pass filter to the live input",
119  "Echo input", echo_test, "Add echo to the live input",
120  "Input panner", panner_test, "Stereo panner on the live input",
121  "Input listener", listener_test, "Demonstrate recording input listener",
122  NULL, NULL, NULL
123 };
void panner_test()
Definition: Test_Audio.cpp:69
InOut class copies the IO port's input buffer to the output buffer, possibly with channel remap and s...
Definition: InOut.h:37
void logMsg(const char *format,...)
These are the public logging messages.
Definition: CGestalt.cpp:292
IO * theIO
AdditiveInstrument.h – Sum-of-sines synthesis instrument class.
Definition: Accessor.h:17
void mic_test()
Definition: Test_Audio.cpp:37
struct used for the JUCE pop-up menu of tests (see the test files)
Definition: CSL_Types.h:265
#define CSL_PI
Definition: CSL_Types.h:334
#define BW_BAND_PASS
Definition: Filters.h:53
testStruct audioTestList[]
Definition: Test_Audio.cpp:115
#define Osc
Definition: CSL_Types.h:169
void setRoomSize(float size)
Definition: Freeverb.cpp:235
void runTest(UnitGenerator &vox, double dur)
juce::AudioDeviceManager * gAudioDeviceManager
void echo_test()
Definition: Test_Audio.cpp:58
Butterworth IIR (2nd order recursive) filter.
Definition: Filters.h:137
void listener_test()
Definition: Test_Audio.cpp:96
void filt_test()
Definition: Test_Audio.cpp:48
void audio_dump()
Definition: Test_Audio.cpp:21
The CSL mono-to-stereo L/R panner class.
Definition: Mixer.h:66