Help understanding the demo


#1

I’ve dug through the Audio demo trying to pick out what I need for a simple note sound system.

I’m trying to make a program that will turn a note on/off every second. I’m just trying to make a basic demo and will extend that later.

I’ve got my main class extending Timer to do this. My problem is audio, I just can’t get output. I’ve looked over the source code a bunch of times and it’s really hard to pick out what I need and what I don’t.

Anyways here’s my .h file:

[code]#ifndef MIDIPLAYER_H
#define MIDIPLAYER_H

#include “…/…/juce.h”
#include “SynthAudioSource.cpp”

class MIDIPlayer : public JUCEApplication,
public Timer
{
public:
MIDIPlayer();
~MIDIPlayer();

void initialise(const String&);
void shutdown();
const String getApplicationName();

void timerCallback();

private:
long myTime;
bool isOff;

//AudioDeviceManager myAudioDeviceManager;

MidiMessageCollector myMidiMessageCollector;

AudioSourcePlayer myAudioSourcePlayer;
MixerAudioSource myMixerSource;
SynthAudioSource *mySynthSource;

};

#endif
[/code]

I suppose I should mention that I have included a few of the classes from the demo in separate .cpp files. I slightly modified SynthAudioSource to accept my own MidiMessageCollector which I pass notes to. They’re all working in there ok, but I’m not sure what I’m missing for output. Here’s my cpp file:

[code]#include
#include “MIDIPlayer.h”

MIDIPlayer::MIDIPlayer(){
std::cout << “0\n”;
myTime = 0;
mySynthSource = new SynthAudioSource(&myMidiMessageCollector);
}

MIDIPlayer::~MIDIPlayer(){
delete mySynthSource;
}

void MIDIPlayer::initialise(const String& commandLine){
std::cout << “Starting Up” << std::endl;

myMidiMessageCollector.reset(44000.);
myMixerSource.addInputSource(mySynthSource, false);
myAudioSourcePlayer.setSource(&myMixerSource);

AudioDeviceManager myAudioDeviceManager;

myAudioDeviceManager.initialise (1, /* number of input channels */
				 2, /* number of output channels */
				 0, /* no XML settings.. */
				 true  /* select default device on failure */);
myAudioDeviceManager.setAudioCallback (&myAudioSourcePlayer);

Logger::outputDebugString(myAudioDeviceManager.getCurrentAudioDeviceName());

startTimer(1000);

}

void MIDIPlayer::shutdown(){
std::cout << “Shutting Down” << std::endl;
}

const String MIDIPlayer::getApplicationName(){
return T(“MIDI Player”);
}

void MIDIPlayer::timerCallback(){
MidiMessage m(1, 2, 3);
myTime++;
if (isOff){
isOff = false;
float one = 1.;
m = MidiMessage::noteOn(1, 60, one);
m.setTimeStamp(myTime);
myMidiMessageCollector.addMessageToQueue(m);
} else {
isOff = true;
m = MidiMessage::noteOff(1, 60);
m.setTimeStamp(myTime);
myMidiMessageCollector.addMessageToQueue(m);
}
std::cout << "myTime: " << myTime << “\n”;
}

START_JUCE_APPLICATION (MIDIPlayer)
[/code]

Any help getting output / explaining what’s wrong would be much appreciated.


#2

It looks ok - what I’d do would be to put some breakpoints in the synth’s audio callback and see if it’s getting called at all, and if so, try to figure out why it’s not making any sound. I’m sure it’ll just be something simple that’s wrong.


#3