//==============================================================================
    void initialise (const String& /*commandLine*/)
    {
        
        
        // MANAGER
        myAudioManager = new AudioDeviceManager();
        String error = myAudioManager->initialise(2, 2, 0, true);
        
        DBG("error string : " + String(error));
        
        myAudioProcessor = new MainAudioProcessor();
        myAudioProcessor->prepareToPlay(44100, 512);
        
        myProcessorPlayer = new AudioProcessorPlayer();
        myProcessorPlayer->setProcessor(myAudioProcessor);
        
        myAudioManager->addAudioCallback(myProcessorPlayer);
                
        
        theMainWindow = new MainDemoWindow(myAudioProcessor);
        theMainWindow->centreWithSize (700, 600);
        theMainWindow->setVisible (true);
      

    }
Beispiel #2
0
 void changeListenerCallback(void *something){
   printf("Some audio change thing.\n");
   if(audioDeviceManager.getCurrentAudioDevice()!=NULL){
     samplerate=audioDeviceManager.getCurrentAudioDevice()->getCurrentSampleRate();
     propertiesfile->setValue("audiodevicemanager",audioDeviceManager.createStateXml());
   }else{
     fprintf(stderr,"Gakkegakke\n");
   }
 }
//==============================================================================
ApplicationSettingsWindow::ApplicationSettingsWindow (OwlControlSettings& settings, AudioDeviceManager& deviceManager)
    : theSettings(settings)
{
    //[Constructor_pre] You can add your own custom stuff here..
    //[/Constructor_pre]

    addAndMakeVisible (audioSelector = new AudioDeviceSelectorComponent (deviceManager,0,0,0,0,true,true,false,false));
    audioSelector->setName ("new component");

    addAndMakeVisible (midiDeviceBox = new ComboBox ("new combo box"));
    midiDeviceBox->setEditableText (false);
    midiDeviceBox->setJustificationType (Justification::centredLeft);
    midiDeviceBox->setTextWhenNothingSelected (String());
    midiDeviceBox->setTextWhenNoChoicesAvailable (TRANS("(no choices)"));
    midiDeviceBox->addItem (TRANS("OMNI"), 1);
    midiDeviceBox->addItem (TRANS("1"), 2);
    midiDeviceBox->addItem (TRANS("2"), 3);
    midiDeviceBox->addItem (TRANS("3"), 4);
    midiDeviceBox->addItem (TRANS("4"), 5);
    midiDeviceBox->addItem (TRANS("5"), 6);
    midiDeviceBox->addItem (TRANS("6"), 7);
    midiDeviceBox->addItem (TRANS("7"), 8);
    midiDeviceBox->addItem (TRANS("8"), 9);
    midiDeviceBox->addItem (TRANS("9"), 10);
    midiDeviceBox->addItem (TRANS("10"), 11);
    midiDeviceBox->addItem (TRANS("11"), 12);
    midiDeviceBox->addItem (TRANS("12"), 13);
    midiDeviceBox->addItem (TRANS("13"), 14);
    midiDeviceBox->addItem (TRANS("14"), 15);
    midiDeviceBox->addItem (TRANS("15"), 16);
    midiDeviceBox->addItem (TRANS("16"), 17);
    midiDeviceBox->addListener (this);

    addAndMakeVisible (label = new Label ("new label",
                                          TRANS("MIDI Device")));
    label->setFont (Font (15.00f, Font::plain));
    label->setJustificationType (Justification::centredLeft);
    label->setEditable (false, false, false);
    label->setColour (TextEditor::textColourId, Colours::black);
    label->setColour (TextEditor::backgroundColourId, Colour (0x00000000));


    //[UserPreSize]

    //[/UserPreSize]

    setSize (600, 400);


    //[Constructor] You can add your own custom stuff here..
    PropertySet* properties = ApplicationConfiguration::getApplicationProperties();
    deviceManager.setDefaultMidiOutput(properties->getValue("midi-output"));
    deviceManager.setMidiInputEnabled(properties->getValue("midi-input"), 1);
    //[/Constructor]
}
Beispiel #4
0
vector<string> getDeviceNames(bool wantInputs = false) {
    vector<string> result;
    AudioDeviceManager manager;
    auto& types = manager.getAvailableDeviceTypes();
    for (auto& t: types) {
        t->scanForDevices();
        auto names = t->getDeviceNames(wantInputs);
        for (auto& name: names)
            result.push_back(name.trimEnd().toStdString());
    }
    return result;
}
Beispiel #5
0
  void play(){
    int num_channels=getSourceNumChannels();

    if(isinitialized==false || num_channels==0)
      return;

    if(isusingjack==false && audioDeviceManager.getCurrentAudioDevice()==NULL)
      return;

    stop();

    GUI_newprocess(source_init);
    //source_init();
    //fprintf(stderr,"GUI_newprocess finished\n");

#if 0      
    if(isusingjack==false){
      if(audioDeviceManager.getOutputChannels().countNumberOfSetBits()!=getSourceNumChannels()){
	if(num_channels==1)
	  num_channels=2;
	outchannels=new BitArray(0);
	for(int lokke=0;lokke<num_channels;lokke++)
	  outchannels->setBit(lokke);
	audioDeviceManager.setAudioDevice(
					  audioDeviceManager.getAvailableAudioDeviceNames()[0],
					  1024,
					  R,
					  new BitArray(0),
					  outchannels,
					false);
      }
    }
#endif  

    {
      int error;
      for(int i=0;i<num_src_states;i++)
	src_delete(src_states[i]);
      free(src_states);
      
      src_states=(SRC_STATE**)malloc(sizeof(SRC_STATE*)*num_channels);
      
      for(int ch=0;ch<num_channels;ch++)
	src_states[ch]=src_new(SRC_QUALITY,1,&error);
    }

    pleasestop=false;
    jp_playpos=0;
    mustrunonemore=false;
    jp_isplaying=true;
    isreadingdata=true;
  }
//==============================================================================
TargetFileComponent::TargetFileComponent (AudioDeviceManager& deviceManager)
    : deviceManager(deviceManager)
{
    addAndMakeVisible (viewport = new Viewport());
    viewport->setName ("viewport");

    addAndMakeVisible (container = new TargetContainer());
    container->setName ("container");

    addAndMakeVisible (playButton = new TextButton ("playButton"));
    playButton->setButtonText ("Play");
    playButton->addListener (this);

    addAndMakeVisible (stopButton = new TextButton ("stopButton"));
    stopButton->setButtonText ("Stop");
    stopButton->addListener (this);

    addAndMakeVisible (loadFileButton = new TextButton ("loadFileButton"));
    loadFileButton->setButtonText ("Load Target File");
    loadFileButton->addListener (this);
    loadFileButton->setColour (TextButton::buttonColourId, Colour (0xfffbfbfd));

    addAndMakeVisible (zoomLabel = new Label ("zoomLabel",
                                              "ZoomX"));
    zoomLabel->setFont (Font (15.00f, Font::plain));
    zoomLabel->setJustificationType (Justification::centredLeft);
    zoomLabel->setEditable (false, false, false);
    zoomLabel->setColour (TextEditor::textColourId, Colours::black);
    zoomLabel->setColour (TextEditor::backgroundColourId, Colour (0x00000000));

    addAndMakeVisible (zoomSlider = new Slider ("zoomSlider"));
    zoomSlider->setRange (1, 5, 0.1);
    zoomSlider->setSliderStyle (Slider::LinearHorizontal);
    zoomSlider->setTextBoxStyle (Slider::TextBoxLeft, true, 35, 20);
    zoomSlider->addListener (this);


    //[UserPreSize]
    //[/UserPreSize]

    setSize (600, 400);


    //[Constructor] You can add your own custom stuff here..

    viewport->setViewedComponent(container, false);

    isPlayable = false;
    setPlayable(isPlayable);

    deviceManager.addAudioCallback(&audioSourcePlayer);
    audioSourcePlayer.setSource(&audioTransport);

    container->addActionListener(this);

    currentFile = new SegaudioFile();


    //[/Constructor]
}
Beispiel #7
0
void init(base::lisp &gl) {
	fm.registerBasicFormats();
	thread.startThread(3);
	dm.addAudioCallback(&asp);
	asp.setSource(&ts);
	pl = new playbackListener(gl);
	ts.addChangeListener(pl);
}
Beispiel #8
0
void shutdown() {
	ts.removeAllChangeListeners();
	ts.setSource(nullptr);
	asp.setSource(nullptr);
	dm.removeAudioCallback(&asp);
	delete pl;
	pl = nullptr;
}
//==============================================================================
ApplicationSettingsWindow::ApplicationSettingsWindow (AudioDeviceManager& deviceManager)
{
    
    addAndMakeVisible (audioSelector = new AudioDeviceSelectorComponent (deviceManager,0,2,0,2,true,true,false,false));
    audioSelector->setName ("new component");
    
    //[UserPreSize]

    //[/UserPreSize]

    setSize (600, 400);

    //[Constructor] You can add your own custom stuff here..
    PropertySet* properties = ApplicationConfiguration::getApplicationProperties();
    deviceManager.setDefaultMidiOutput(properties->getValue("midi-output"));
    deviceManager.setMidiInputEnabled(properties->getValue("midi-input"), 1);
    //[/Constructor]
}
Beispiel #10
0
int main(int argc, char* argv[])
{
    {
        AudioDeviceManager manager;
        //manager.initialize();

        auto playbackDevice = manager.getDefaultPlaybackDevice();
        playbackDevice->initialize();

        //playbackDevice->

        auto captureDevice = manager.getDefaultCaptureDevice();
        captureDevice->initialize();

    }

    return 0;
}
Beispiel #11
0
  void initJuceAudio(void){
    XmlElement *settings=propertiesfile->getXmlValue("audiodevicemanager");
    const String error (audioDeviceManager.initialise (0, /* number of input channels */
						       8, /* number of output channels */
						       settings,
						       true  /* select default device on failure */));
    
    if (audioDeviceManager.getCurrentAudioDevice()==NULL || error.isNotEmpty())
      {
	AlertWindow::showMessageBox (AlertWindow::WarningIcon,
				     T("Mammut"),
				     T("Couldn't open an output device!\n\n") + error);
      }
    else
      {
	isinitialized=true;
	
	// start the IO device pulling its data from our callback..
	audioDeviceManager.setAudioCallback (this);
	
      }
  }
Beispiel #12
0
bool FCDProInput::openFCDAudio(const char* cardname)
{
    AudioDeviceManager *audioDeviceManager = DSPEngine::instance()->getAudioDeviceManager();
    const QList<QAudioDeviceInfo>& audioList = audioDeviceManager->getInputDevices();

    for (const auto &itAudio : audioList)
    {
        if (itAudio.deviceName().contains(QString(cardname)))
        {
            int fcdDeviceIndex = audioDeviceManager->getInputDeviceIndex(itAudio.deviceName());
            m_fcdAudioInput.start(fcdDeviceIndex, fcd_traits<Pro>::sampleRate);
            int fcdSampleRate = m_fcdAudioInput.getRate();
            qDebug("FCDProPlusInput::openFCDAudio: %s index %d at %d S/s",
                    itAudio.deviceName().toStdString().c_str(), fcdDeviceIndex, fcdSampleRate);
            m_fcdAudioInput.addFifo(&m_fcdFIFO);
            return true;
        }
    }

    qCritical("FCDProInput::openFCDAudio: device with name %s not found", cardname);
    return false;
}
Beispiel #13
0
    //==============================================================================
    void initialise (const String& commandLine)
    {
        DBG("Initialising OwlNest");
        ApplicationConfiguration::initialise();
        commands = new ApplicationCommandManager();
        commands->registerAllCommandsForTarget(this);
        commands->registerAllCommandsForTarget(&settings);
        commands->setFirstCommandTarget(&settings);

        // Initialize audio/midi device
        PropertySet* props = ApplicationConfiguration::getApplicationProperties();
        if(props->getBoolValue("hide-low-level-items") == true)
        {
        dm.initialise(0, 0, nullptr, true);
        }
        else
        {
        dm.initialise(2, 2, nullptr, true);
        }
        // start GUI
        mainWindow = new MainWindow(commands, settings, dm, updateGui);        
	mainWindow->addKeyListener(commands->getKeyMappings());
    }
Beispiel #14
0
static void initJuceDevicesIfNeeded()
{
    static AudioDeviceManager sDeviceManager;
    static bool needsInit = true;

    if (! needsInit)
        return;

    needsInit = false;
    new JuceCleanup();

    sDeviceManager.createAudioDeviceTypes(gDeviceTypes);

    // remove JACK from device list
    for (int i=0, count=gDeviceTypes.size(); i < count; ++i)
    {
        if (gDeviceTypes[i]->getTypeName() == "JACK")
        {
            gDeviceTypes.remove(i, true);
            break;
        }
    }
}
Beispiel #15
0
static void initJuceDevicesIfNeeded()
{
    static AudioDeviceManager sDeviceManager;

    if (gDeviceTypes.size() != 0)
        return;

    sDeviceManager.createAudioDeviceTypes(gDeviceTypes);

    CARLA_SAFE_ASSERT_RETURN(gDeviceTypes.size() != 0,);

    new JuceCleanup();

    // remove JACK from device list
    for (int i=0, count=gDeviceTypes.size(); i < count; ++i)
    {
        if (gDeviceTypes[i]->getTypeName() == "JACK")
        {
            gDeviceTypes.remove(i, true);
            break;
        }
    }
}
Beispiel #16
0
  JucePlayer(PropertiesFile *propertiesfile)
  {
    this->propertiesfile=propertiesfile;

    jp_isplaying=false;
    isreadingdata=false;
    pleasestop=false;
    isinitialized=false;
    isusingjack=false;

    {
      num_src_states=0;
      src_states=NULL;
    }

    {
      ov_callbacks ov_cb={oggread_func,oggseek_func,oggclose_func,oggtell_func};
      lastreadoggpos=-1;
      nextreadoggpos=-1;      
      if(ov_open_callbacks(&oggvorbisfile,&oggvorbisfile,NULL,0,ov_cb)==0)
	isplaying_ogg=true;
      else
	isplaying_ogg=false;
      N=getSourceLength();
      R=44100;
      oggsrc_state=src_callback_new(audio_getOggResampledData_callback,SRC_QUALITY,2,NULL,NULL);
    }


#ifdef HAVE_JACK
    samplerate=init_jack(audio_jack_callback);

    if(samplerate!=-1){
      isinitialized=true;
      isusingjack=true;
    }else
#endif
      initJuceAudio();


    audioDeviceManager.addChangeListener(this);
  }
Beispiel #17
0
  void prefs(){
      
    if(isusingjack==true){
      printerror("Can not change audio when using jack.");
      return;
    }

    AudioDeviceSelectorComponent audioSettingsComp (audioDeviceManager,
						    0, 0,
						    2, 8,
						    false);
    
    // ...and show it in a DialogWindow...
    audioSettingsComp.setSize (400, 170);
    
    DialogWindow::showModalDialog (T("Audio Settings"),
				   &audioSettingsComp,
				   NULL,Colour((uint8)0xb90,(uint8)0x60,(uint8)0x60,(uint8)0xd0),true);
    if(audioDeviceManager.getCurrentAudioDevice()==NULL && isreadingdata==true){
      isreadingdata=false;
    }
  }
Beispiel #18
0
//==============================================================================
int main( int argc, char* argv[] )
{
    AudioDeviceManager* dm = new AudioDeviceManager();
    auto callback = new SimpleCallback();

    const OwnedArray< AudioIODeviceType >* deviceTypes = &( dm->getAvailableDeviceTypes() );

    for ( auto& t : *( deviceTypes ) ) {
        DBG( "+-- device type  : ------------+" );
        DBG( "  " + t->getTypeName() );
        t->scanForDevices();
        if ( t->hasSeparateInputsAndOutputs() ) {
            DBG( "+-- inputs   : ------------+" );
            auto deviceNames = t->getDeviceNames( true );
            for ( auto& name : deviceNames ) {
                DBG( "    +-- device name  : ------------+" );
                DBG( "      " + name );
            }
            DBG( "+-- outputs  : ------------+" );
            deviceNames = t->getDeviceNames( false );
            for ( auto& name : deviceNames ) {
                DBG( "    +-- device name  : ------------+" );
                DBG( "      " + name );
            }
        } else {
        }
        DBG( "has separate inputs and outputs : " << t->hasSeparateInputsAndOutputs() );
    }

    // initialize audio with the following requirements:
    auto result =
      dm->initialise( /* num inputs */ 0, /* num outputs */ 2, /* xml settings file */ nullptr,
                      /* select default device on failure */ true );

    if ( !result.isEmpty() ) {
        DBG( "Error on initialize : " + result );
    }

    logMessage( "--------------------------------------" );
    logMessage( "Current audio device type: " +
                ( dm->getCurrentDeviceTypeObject() != nullptr
                    ? dm->getCurrentDeviceTypeObject()->getTypeName()
                    : "<none>" ) );

    if ( AudioIODevice* device = dm->getCurrentAudioDevice() ) {
        logMessage( "Current audio device: " + device->getName().quoted() );
        logMessage( "Sample rate: " + String( device->getCurrentSampleRate() ) + " Hz" );
        logMessage( "Block size: " + String( device->getCurrentBufferSizeSamples() ) + " samples" );
        logMessage( "Output Latency: " + String( device->getOutputLatencyInSamples() ) +
                    " samples" );
        logMessage( "Input Latency: " + String( device->getInputLatencyInSamples() ) + " samples" );
        logMessage( "Bit depth: " + String( device->getCurrentBitDepth() ) );
        logMessage( "Input channel names: " +
                    device->getInputChannelNames().joinIntoString( ", " ) );
        logMessage( "Active input channels: " +
                    getListOfActiveBits( device->getActiveInputChannels() ) );
        logMessage( "Output channel names: " +
                    device->getOutputChannelNames().joinIntoString( ", " ) );
        logMessage( "Active output channels: " +
                    getListOfActiveBits( device->getActiveOutputChannels() ) );
    } else {
        logMessage( "No audio device open" );
    }

    dm->addAudioCallback( callback );

    sleep( 3 ); // 3 seconds of audio
//    while ( true ) {
//    }

    dm->removeAudioCallback( callback );
    delete callback;

    delete dm;

    return 0;
}
Beispiel #19
0
// Play audio samples for this frame
void Frame::Play()
{
	// Check if samples are present
	if (!audio->getNumSamples())
		return;

	AudioDeviceManager deviceManager;
	deviceManager.initialise (0, /* number of input channels */
	        2, /* number of output channels */
	        0, /* no XML settings.. */
	        true  /* select default device on failure */);
	//deviceManager.playTestSound();

	AudioSourcePlayer audioSourcePlayer;
	deviceManager.addAudioCallback (&audioSourcePlayer);

	ScopedPointer<AudioBufferSource> my_source;
	my_source = new AudioBufferSource(audio.get());

	// Create TimeSliceThread for audio buffering
	TimeSliceThread my_thread("Audio buffer thread");

	// Start thread
	my_thread.startThread();

	AudioTransportSource transport1;
	transport1.setSource (my_source,
			5000, // tells it to buffer this many samples ahead
			&my_thread,
			(double) sample_rate,
			audio->getNumChannels()); // sample rate of source
	transport1.setPosition (0);
	transport1.setGain(1.0);


	// Create MIXER
	MixerAudioSource mixer;
	mixer.addInputSource(&transport1, false);
	audioSourcePlayer.setSource (&mixer);

	// Start transports
	transport1.start();

	while (transport1.isPlaying())
	{
		cout << "playing" << endl;
		Sleep(1);
	}

	cout << "DONE!!!" << endl;

	transport1.stop();
    transport1.setSource (0);
    audioSourcePlayer.setSource (0);
    my_thread.stopThread(500);
    deviceManager.removeAudioCallback (&audioSourcePlayer);
    deviceManager.closeAudioDevice();
    deviceManager.removeAllChangeListeners();
    deviceManager.dispatchPendingMessages();

	cout << "End of Play()" << endl;


}
Beispiel #20
0
namespace playback {
AudioDeviceManager dm;
AudioFormatManager fm;
AudioSourcePlayer asp;
AudioTransportSource ts;
ScopedPointer<AudioFormatReaderSource> frs;
TimeSliceThread thread("audio playback");

class playbackListener : public ChangeListener {
	base::lisp &gl;
public:
	base::string functionId;
	bool enabled;
	playbackListener(base::lisp &gli) : gl(gli), enabled(false) {}
	void changeListenerCallback(ChangeBroadcaster *source) override {
		if (source == &ts && enabled) {
			gl.eval(base::strs("(", functionId, ")"));
		}
	}
};

playbackListener *pl = nullptr;

void init(base::lisp &gl) {
	fm.registerBasicFormats();
	thread.startThread(3);
	dm.addAudioCallback(&asp);
	asp.setSource(&ts);
	pl = new playbackListener(gl);
	ts.addChangeListener(pl);
}

void shutdown() {
	ts.removeAllChangeListeners();
	ts.setSource(nullptr);
	asp.setSource(nullptr);
	dm.removeAudioCallback(&asp);
	delete pl;
	pl = nullptr;
}

//- LISP API -
// playback-set-file (string)fileName -> t/nil
base::cell_t set_file(base::lisp &gl, base::cell_t c, base::cells_t &) {
	if (base::lisp::validate(c, base::cell::list(1), base::cell::typeString)) {
		const auto &fname = c + 1;

		// stop current playback
		ts.stop();
		ts.setSource(nullptr);
		frs = nullptr;
		AudioFormatReader *r;

		// ectract CUE information (if any)
		std::regex cue("^(.*):(\\d+):(\\d+)$");
		std::smatch result;
		std::regex_search(fname->s, result, cue);
		if (result.size() == 4) {
			// is cue
			int32 start = base::fromStr<int32>(result[2].str());
			int32 end = base::fromStr<int32>(result[3].str());
			int32 duration = end - start;

			AudioFormatReader *tr = fm.createReaderFor(File(result[1].str()));

			// start, end are in frames (1 frame = 1/75 second) - convert to sample
			float samplesInOneSecond = tr->sampleRate; // AudioSubsectionReader will handle channels count
			float startSecond = (float)start / 75.0f;
			float durationSecond = (float)duration / 75.0f;
			float startSample = startSecond * samplesInOneSecond;
			float durationSamples = durationSecond * samplesInOneSecond;

			// some CUE may have 0 length (play to end)
			if (end <= start)
				durationSamples = tr->lengthInSamples;

			r = new AudioSubsectionReader(tr, (int)startSample, (int)durationSamples, true);
		}
		else {
			// regular file
			r = fm.createReaderFor(File(fname->s));
		}

		if (r) {
			frs = new AudioFormatReaderSource(r, true);
			ts.setSource(frs, 32768, &thread, r->sampleRate);
			return gl.t();
		}
		gl.signalError(base::strs("file not found or file format not supported: ", fname->s));
		return gl.nil();
	}
	gl.signalError("playback-set-file: invalid arguments, expected (string)");
	return gl.nil();
}

// playback-unload-file
base::cell_t unload_file(base::lisp &gl, base::cell_t, base::cells_t &) {
	ts.stop();
	ts.setSource(nullptr);
	frs = nullptr;
	return gl.nil();
}

// playback-start
base::cell_t start(base::lisp &gl, base::cell_t, base::cells_t &) {
	ts.start();
	return gl.nil();
}

// playback-stop
base::cell_t stop(base::lisp &gl, base::cell_t, base::cells_t &) {
	ts.stop();
	return gl.nil();
}

// playback-seek (float)posSeconds
base::cell_t seek(base::lisp &gl, base::cell_t c, base::cells_t &) {
	if (base::lisp::validate(c, base::cell::list(1), base::cell::typeFloat)) {
		const auto &pos = c + 1;
		ts.setPosition((double)pos->f);
		return gl.nil();
	}
	gl.signalError("playback-seek: invalid arguments, expected (float)");
	return gl.nil();
}

// playback-length -> (float)/total time in seconds/
base::cell_t length(base::lisp &gl, base::cell_t, base::cells_t &ret) {
	ret.push_back(base::cell(float(ts.getLengthInSeconds())));
	return ret.end();
}

// playback-get-pos -> (float)/playback position in seconds/
base::cell_t get_pos(base::lisp &gl, base::cell_t, base::cells_t &ret) {
	ret.push_back(base::cell(float(ts.getCurrentPosition())));
	return ret.end();
}

// playback-is-playing -> t/nil
base::cell_t is_playing(base::lisp &gl, base::cell_t, base::cells_t &) {
	if (ts.isPlaying())
		return gl.t();
	return gl.nil();
}

// playback-finished -> t/nil
base::cell_t finished_playing(base::lisp &gl, base::cell_t, base::cells_t &) {
	if (ts.hasStreamFinished())
		return gl.t();
	return gl.nil();
}

// (bind-playback (id)callback)
base::cell_t bind_playback(base::lisp &gl, base::cell_t c, base::cells_t &) {
	if (pl) {
		if (base::lisp::validate(c, base::cell::list(1), base::cell::typeIdentifier)) {
			const auto &fx = c + 1;
			pl->functionId = fx->s;
			pl->enabled = true;
			return gl.t();
		}
		pl->enabled = false;
		return gl.nil();
	}
	gl.signalError("bind-playback: invalid arguments, expected (id)");
	return gl.nil();
}

// (playback-gain (float|optional)gain) -> t/nil | gain
base::cell_t gain(base::lisp &gl, base::cell_t c, base::cells_t &ret) {
	if (pl) {
		if (base::lisp::validate(c, base::cell::listRange(1), base::cell::typeFloat)) {
			// setter
			ts.setGain((c + 1)->f);
			return gl.t();
		}
		else if (base::lisp::validate(c, base::cell::list(0))) {
			// getter
			ret.push_back(base::cell(ts.getGain()));
			return ret.end();
		}
		gl.signalError("playback-gain: invalid arguments, expected ((optional) float)");
	}
	return gl.nil();
}

// (unbind-playback)
base::cell_t unbind_playback(base::lisp &gl, base::cell_t, base::cells_t &) {
	if (pl) {
		pl->enabled = false;
		return gl.t();
	}
	return gl.nil();
}

}
Beispiel #21
0
void DSDDemod::applySettings(const DSDDemodSettings& settings, bool force)
{
    qDebug() << "DSDDemod::applySettings: "
            << " m_inputFrequencyOffset: " << settings.m_inputFrequencyOffset
            << " m_rfBandwidth: " << settings.m_rfBandwidth
            << " m_fmDeviation: " << settings.m_fmDeviation
            << " m_demodGain: " << settings.m_demodGain
            << " m_volume: " << settings.m_volume
            << " m_baudRate: " << settings.m_baudRate
            << " m_squelchGate" << settings.m_squelchGate
            << " m_squelch: " << settings.m_squelch
            << " m_audioMute: " << settings.m_audioMute
            << " m_enableCosineFiltering: " << settings.m_enableCosineFiltering
            << " m_syncOrConstellation: " << settings.m_syncOrConstellation
            << " m_slot1On: " << settings.m_slot1On
            << " m_slot2On: " << settings.m_slot2On
            << " m_tdmaStereo: " << settings.m_tdmaStereo
            << " m_pllLock: " << settings.m_pllLock
            << " m_highPassFilter: "<< settings.m_highPassFilter
            << " m_audioDeviceName: " << settings.m_audioDeviceName
            << " m_traceLengthMutliplier: " << settings.m_traceLengthMutliplier
            << " m_traceStroke: " << settings.m_traceStroke
            << " m_traceDecay: " << settings.m_traceDecay
            << " force: " << force;

    QList<QString> reverseAPIKeys;

    if ((settings.m_inputFrequencyOffset != m_settings.m_inputFrequencyOffset) || force) {
        reverseAPIKeys.append("inputFrequencyOffset");
    }
    if ((settings.m_demodGain != m_settings.m_demodGain) || force) {
        reverseAPIKeys.append("demodGain");
    }
    if ((settings.m_audioMute != m_settings.m_audioMute) || force) {
        reverseAPIKeys.append("audioMute");
    }
    if ((settings.m_syncOrConstellation != m_settings.m_syncOrConstellation) || force) {
        reverseAPIKeys.append("syncOrConstellation");
    }
    if ((settings.m_slot1On != m_settings.m_slot1On) || force) {
        reverseAPIKeys.append("slot1On");
    }
    if ((settings.m_slot2On != m_settings.m_slot2On) || force) {
        reverseAPIKeys.append("slot2On");
    }
    if ((settings.m_demodGain != m_settings.m_demodGain) || force) {
        reverseAPIKeys.append("demodGain");
    }
    if ((settings.m_traceLengthMutliplier != m_settings.m_traceLengthMutliplier) || force) {
        reverseAPIKeys.append("traceLengthMutliplier");
    }

    if ((settings.m_rfBandwidth != m_settings.m_rfBandwidth) || force)
    {
        reverseAPIKeys.append("rfBandwidth");
        m_settingsMutex.lock();
        m_interpolator.create(16, m_inputSampleRate, (settings.m_rfBandwidth) / 2.2);
        m_interpolatorDistanceRemain = 0;
        m_interpolatorDistance =  (Real) m_inputSampleRate / (Real) 48000;
        //m_phaseDiscri.setFMScaling((float) settings.m_rfBandwidth / (float) settings.m_fmDeviation);
        m_settingsMutex.unlock();
    }

    if ((settings.m_fmDeviation != m_settings.m_fmDeviation) || force)
    {
        reverseAPIKeys.append("fmDeviation");
        m_phaseDiscri.setFMScaling(48000.0f / (2.0f*settings.m_fmDeviation));
    }

    if ((settings.m_squelchGate != m_settings.m_squelchGate) || force)
    {
        reverseAPIKeys.append("squelchGate");
        m_squelchGate = 480 * settings.m_squelchGate; // gate is given in 10s of ms at 48000 Hz audio sample rate
        m_squelchCount = 0; // reset squelch open counter
    }

    if ((settings.m_squelch != m_settings.m_squelch) || force)
    {
        reverseAPIKeys.append("squelch");
        // input is a value in dB
        m_squelchLevel = std::pow(10.0, settings.m_squelch / 10.0);
    }

    if ((settings.m_volume != m_settings.m_volume) || force)
    {
        reverseAPIKeys.append("volume");
        m_dsdDecoder.setAudioGain(settings.m_volume);
    }

    if ((settings.m_baudRate != m_settings.m_baudRate) || force)
    {
        reverseAPIKeys.append("baudRate");
        m_dsdDecoder.setBaudRate(settings.m_baudRate);
    }

    if ((settings.m_enableCosineFiltering != m_settings.m_enableCosineFiltering) || force)
    {
        reverseAPIKeys.append("enableCosineFiltering");
        m_dsdDecoder.enableCosineFiltering(settings.m_enableCosineFiltering);
    }

    if ((settings.m_tdmaStereo != m_settings.m_tdmaStereo) || force)
    {
        reverseAPIKeys.append("tdmaStereo");
        m_dsdDecoder.setTDMAStereo(settings.m_tdmaStereo);
    }

    if ((settings.m_pllLock != m_settings.m_pllLock) || force)
    {
        reverseAPIKeys.append("pllLock");
        m_dsdDecoder.setSymbolPLLLock(settings.m_pllLock);
    }

    if ((settings.m_highPassFilter != m_settings.m_highPassFilter) || force)
    {
        reverseAPIKeys.append("highPassFilter");
        m_dsdDecoder.useHPMbelib(settings.m_highPassFilter);
    }

    if ((settings.m_audioDeviceName != m_settings.m_audioDeviceName) || force)
    {
        reverseAPIKeys.append("audioDeviceName");
        AudioDeviceManager *audioDeviceManager = DSPEngine::instance()->getAudioDeviceManager();
        int audioDeviceIndex = audioDeviceManager->getOutputDeviceIndex(settings.m_audioDeviceName);
        //qDebug("AMDemod::applySettings: audioDeviceName: %s audioDeviceIndex: %d", qPrintable(settings.m_audioDeviceName), audioDeviceIndex);
        audioDeviceManager->addAudioSink(&m_audioFifo1, getInputMessageQueue(), audioDeviceIndex);
        audioDeviceManager->addAudioSink(&m_audioFifo2, getInputMessageQueue(), audioDeviceIndex);
        uint32_t audioSampleRate = audioDeviceManager->getOutputSampleRate(audioDeviceIndex);

        if (m_audioSampleRate != audioSampleRate) {
            applyAudioSampleRate(audioSampleRate);
        }
    }

    if (settings.m_useReverseAPI)
    {
        bool fullUpdate = ((m_settings.m_useReverseAPI != settings.m_useReverseAPI) && settings.m_useReverseAPI) ||
                (m_settings.m_reverseAPIAddress != settings.m_reverseAPIAddress) ||
                (m_settings.m_reverseAPIPort != settings.m_reverseAPIPort) ||
                (m_settings.m_reverseAPIDeviceIndex != settings.m_reverseAPIDeviceIndex) ||
                (m_settings.m_reverseAPIChannelIndex != settings.m_reverseAPIChannelIndex);
        webapiReverseSendSettings(reverseAPIKeys, settings, fullUpdate || force);
    }

    m_settings = settings;
}