annotate audioio/AudioTargetFactory.cpp @ 445:c48bc6ddfe17 tonioni

Remove some debug; set some gain values
author Chris Cannam
date Tue, 31 Mar 2015 13:06:29 +0100
parents ccd3c927638b
children
rev   line source
Chris@43 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@43 2
Chris@43 3 /*
Chris@43 4 Sonic Visualiser
Chris@43 5 An audio file viewer and annotation editor.
Chris@43 6 Centre for Digital Music, Queen Mary, University of London.
Chris@43 7 This file copyright 2006 Chris Cannam.
Chris@43 8
Chris@43 9 This program is free software; you can redistribute it and/or
Chris@43 10 modify it under the terms of the GNU General Public License as
Chris@43 11 published by the Free Software Foundation; either version 2 of the
Chris@43 12 License, or (at your option) any later version. See the file
Chris@43 13 COPYING included with this distribution for more information.
Chris@43 14 */
Chris@43 15
Chris@43 16 #include "AudioTargetFactory.h"
Chris@43 17
Chris@43 18 #include "AudioJACKTarget.h"
Chris@43 19 #include "AudioPortAudioTarget.h"
Chris@117 20 #include "AudioPulseAudioTarget.h"
Chris@43 21
Chris@149 22 #include "AudioCallbackPlayTarget.h"
Chris@149 23
Chris@126 24 #include <QCoreApplication>
Chris@126 25
Chris@43 26 #include <iostream>
Chris@43 27
Chris@126 28 AudioTargetFactory *
Chris@126 29 AudioTargetFactory::m_instance = 0;
Chris@126 30
Chris@126 31 AudioTargetFactory *
Chris@126 32 AudioTargetFactory::getInstance()
Chris@126 33 {
Chris@126 34 if (!m_instance) m_instance = new AudioTargetFactory();
Chris@126 35 return m_instance;
Chris@126 36 }
Chris@126 37
Chris@126 38 AudioTargetFactory::AudioTargetFactory()
Chris@126 39 {
Chris@126 40 }
Chris@126 41
Chris@126 42 std::vector<QString>
Chris@126 43 AudioTargetFactory::getCallbackTargetNames(bool includeAuto) const
Chris@126 44 {
Chris@126 45 std::vector<QString> names;
Chris@126 46 if (includeAuto) names.push_back("auto");
Chris@126 47
Chris@126 48 #ifdef HAVE_JACK
Chris@126 49 names.push_back("jack");
Chris@126 50 #endif
Chris@126 51
Chris@126 52 #ifdef HAVE_LIBPULSE
Chris@126 53 names.push_back("pulse");
Chris@126 54 #endif
Chris@126 55
Chris@126 56 #ifdef HAVE_PORTAUDIO_2_0
Chris@126 57 names.push_back("port");
Chris@126 58 #endif
Chris@126 59
Chris@126 60 return names;
Chris@126 61 }
Chris@126 62
Chris@126 63 QString
Chris@126 64 AudioTargetFactory::getCallbackTargetDescription(QString name) const
Chris@126 65 {
Chris@126 66 if (name == "auto") {
Chris@126 67 return QCoreApplication::translate("AudioTargetFactory",
Chris@126 68 "(auto)");
Chris@126 69 }
Chris@126 70 if (name == "jack") {
Chris@126 71 return QCoreApplication::translate("AudioTargetFactory",
Chris@126 72 "JACK Audio Connection Kit");
Chris@126 73 }
Chris@126 74 if (name == "pulse") {
Chris@126 75 return QCoreApplication::translate("AudioTargetFactory",
Chris@126 76 "PulseAudio Server");
Chris@126 77 }
Chris@126 78 if (name == "port") {
Chris@126 79 return QCoreApplication::translate("AudioTargetFactory",
Chris@126 80 "Default Soundcard Device");
Chris@126 81 }
Chris@126 82
Chris@126 83 return "(unknown)";
Chris@126 84 }
Chris@126 85
Chris@126 86 QString
Chris@126 87 AudioTargetFactory::getDefaultCallbackTarget() const
Chris@126 88 {
Chris@126 89 if (m_default == "") return "auto";
Chris@126 90 return m_default;
Chris@126 91 }
Chris@126 92
Chris@126 93 bool
Chris@126 94 AudioTargetFactory::isAutoCallbackTarget(QString name) const
Chris@126 95 {
Chris@126 96 return (name == "auto" || name == "");
Chris@126 97 }
Chris@126 98
Chris@126 99 void
Chris@126 100 AudioTargetFactory::setDefaultCallbackTarget(QString target)
Chris@126 101 {
Chris@126 102 m_default = target;
Chris@126 103 }
Chris@126 104
Chris@43 105 AudioCallbackPlayTarget *
Chris@43 106 AudioTargetFactory::createCallbackTarget(AudioCallbackPlaySource *source)
Chris@43 107 {
Chris@43 108 AudioCallbackPlayTarget *target = 0;
Chris@43 109
Chris@126 110 if (m_default != "" && m_default != "auto") {
Chris@126 111
Chris@126 112 #ifdef HAVE_JACK
Chris@126 113 if (m_default == "jack") target = new AudioJACKTarget(source);
Chris@126 114 #endif
Chris@126 115
Chris@126 116 #ifdef HAVE_LIBPULSE
Chris@126 117 if (m_default == "pulse") target = new AudioPulseAudioTarget(source);
Chris@126 118 #endif
Chris@126 119
Chris@126 120 #ifdef HAVE_PORTAUDIO_2_0
Chris@126 121 if (m_default == "port") target = new AudioPortAudioTarget(source);
Chris@126 122 #endif
Chris@126 123
Chris@126 124 if (!target || !target->isOK()) {
Chris@293 125 cerr << "WARNING: AudioTargetFactory::createCallbackTarget: Failed to open the requested target (\"" << m_default << "\")" << endl;
Chris@126 126 delete target;
Chris@126 127 return 0;
Chris@126 128 } else {
Chris@126 129 return target;
Chris@126 130 }
Chris@126 131 }
Chris@126 132
Chris@43 133 #ifdef HAVE_JACK
Chris@43 134 target = new AudioJACKTarget(source);
Chris@43 135 if (target->isOK()) return target;
Chris@43 136 else {
Chris@293 137 cerr << "WARNING: AudioTargetFactory::createCallbackTarget: Failed to open JACK target" << endl;
Chris@43 138 delete target;
Chris@43 139 }
Chris@43 140 #endif
Chris@117 141
Chris@117 142 #ifdef HAVE_LIBPULSE
Chris@117 143 target = new AudioPulseAudioTarget(source);
Chris@117 144 if (target->isOK()) return target;
Chris@117 145 else {
Chris@293 146 cerr << "WARNING: AudioTargetFactory::createCallbackTarget: Failed to open PulseAudio target" << endl;
Chris@117 147 delete target;
Chris@117 148 }
Chris@117 149 #endif
Chris@114 150
Chris@114 151 #ifdef HAVE_PORTAUDIO_2_0
Chris@43 152 target = new AudioPortAudioTarget(source);
Chris@43 153 if (target->isOK()) return target;
Chris@43 154 else {
Chris@293 155 cerr << "WARNING: AudioTargetFactory::createCallbackTarget: Failed to open PortAudio target" << endl;
Chris@43 156 delete target;
Chris@43 157 }
Chris@43 158 #endif
Chris@43 159
Chris@293 160 cerr << "WARNING: AudioTargetFactory::createCallbackTarget: No suitable targets available" << endl;
Chris@43 161 return 0;
Chris@43 162 }
Chris@43 163
Chris@43 164