/[svn]/linuxsampler/trunk/src/drivers/audio/AudioOutputDeviceAsio.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/drivers/audio/AudioOutputDeviceAsio.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1950 by persson, Sun Jul 19 11:12:13 2009 UTC revision 1951 by persson, Wed Jul 29 15:31:09 2009 UTC
# Line 50  struct DriverInfo { Line 50  struct DriverInfo {
50    
51      // ASIOGetSampleRate()      // ASIOGetSampleRate()
52      ASIOSampleRate sampleRate;      ASIOSampleRate sampleRate;
     int            numSampleRates;  
53      std::vector<int> sampleRates;      std::vector<int> sampleRates;
54    
55      // ASIOOutputReady()      // ASIOOutputReady()
# Line 86  struct DriverInfo { Line 85  struct DriverInfo {
85  extern AsioDrivers* asioDrivers;  extern AsioDrivers* asioDrivers;
86  extern bool loadAsioDriver(char* name);  extern bool loadAsioDriver(char* name);
87    
 static ASIODriverInfo MyAsioDriverInfo;  
88  static DriverInfo asioDriverInfo = { { 0 }, 0 };  static DriverInfo asioDriverInfo = { { 0 }, 0 };
89    
90  static bool asioDriverOpened = false;  static bool asioDriverOpened = false;
# Line 145  static bool ASIO_loadAsioDriver(const ch Line 143  static bool ASIO_loadAsioDriver(const ch
143      return loadAsioDriver(const_cast<char*>(name));      return loadAsioDriver(const_cast<char*>(name));
144  }  }
145    
146  void ASIO_OpenAndQueryDeviceInfo(String driverName, DriverInfo* driverInfo,  int ASIO_OpenAndQueryDeviceInfo(String driverName, DriverInfo* driverInfo) {
                                  ASIODriverInfo* asioDriverInfo) throw (AudioOutputException) {  
     static const char* errmsg = "Error: ASIO Initalization Error";  
   
147      ASIOSampleRate possibleSampleRates[] =      ASIOSampleRate possibleSampleRates[] =
148          { 8000.0, 9600.0, 11025.0, 12000.0, 16000.0, 22050.0, 24000.0,          { 8000.0, 9600.0, 11025.0, 12000.0, 16000.0, 22050.0, 24000.0,
149            32000.0, 44100.0, 48000.0, 88200.0, 96000.0 };            32000.0, 44100.0, 48000.0, 88200.0, 96000.0 };
# Line 177  void ASIO_OpenAndQueryDeviceInfo(String Line 172  void ASIO_OpenAndQueryDeviceInfo(String
172          // if the given ASIO driver name == current ASIO driver name          // if the given ASIO driver name == current ASIO driver name
173          // and the driver was already opened then do nothing          // and the driver was already opened then do nothing
174          if (asioDriverOpened) {          if (asioDriverOpened) {
175              dmsg(2,("asioDriver ALREADY OPENED, DOING NOTHING !\n"));              dmsg(2,("asioDriver already opened, doing nothing\n"));
176              return;              return 0;
177          }          }
178      }      }
179      else {      else {
180          dmsg(2,("driverName != currentAsioDriverName, new asio driver specified, opening device ....\n"));          dmsg(2,("driverName != currentAsioDriverName, new asio driver specified, opening device...\n"));
181          // if a new ASIO driver name was specified then first check if          // if a new ASIO driver name was specified then first check if
182          // we need to close the old one          // we need to close the old one
183          if (asioDriverOpened) {          if (asioDriverOpened) {
184              dmsg(2,("different asioDriver ALREADY OPENED, closing old one !\n"));              dmsg(2,("different asioDriver already opened, closing old one\n"));
185              asioDriverOpened = false;              asioDriverOpened = false;
186              ASIOExit(); // close the old ASIO driver              ASIOExit(); // close the old ASIO driver
187          }          }
188      }      }
189      currentAsioDriverName = driverName;      currentAsioDriverName = driverName;
190    
191      memset((void*)asioDriverInfo, 0, sizeof(ASIODriverInfo));      memset(&driverInfo->driverInfo, 0, sizeof(ASIODriverInfo));
192      asioDriverInfo->asioVersion = 1;      driverInfo->driverInfo.asioVersion = 1;
193      asioDriverInfo->sysRef = NULL;      driverInfo->driverInfo.sysRef = NULL;
194    
195      // MUST BE CHECKED : to force fragments loading on Mac      // MUST BE CHECKED : to force fragments loading on Mac
196      // ASIO_loadAsioDriver("dummy");      // ASIO_loadAsioDriver("dummy");
# Line 203  void ASIO_OpenAndQueryDeviceInfo(String Line 198  void ASIO_OpenAndQueryDeviceInfo(String
198      dmsg(2,("Before ASIO_loadAsioDriver('%s')\n", driverName.c_str()));      dmsg(2,("Before ASIO_loadAsioDriver('%s')\n", driverName.c_str()));
199      if (!ASIO_loadAsioDriver(driverName.c_str())) {      if (!ASIO_loadAsioDriver(driverName.c_str())) {
200          dmsg(2,("ASIO_OpenAndQueryDeviceInfo could not loadAsioDriver %s\n", driverName.c_str()));          dmsg(2,("ASIO_OpenAndQueryDeviceInfo could not loadAsioDriver %s\n", driverName.c_str()));
201          throw AudioOutputException(errmsg);          return -1;
202      }      }
203      dmsg(2,("Before ASIOInit()\n"));      dmsg(2,("Before ASIOInit()\n"));
204      if ((asioError = ASIOInit(asioDriverInfo)) != ASE_OK) {      if ((asioError = ASIOInit(&driverInfo->driverInfo)) != ASE_OK) {
205          dmsg(1,("ASIO_OpenAndQueryDeviceInfo: ASIOInit returned %d for %s\n",          dmsg(2,("ASIO_OpenAndQueryDeviceInfo: ASIOInit returned %d for %s\n",
206                  int(asioError), driverName.c_str()));                  int(asioError), driverName.c_str()));
207          throw AudioOutputException(errmsg);          return asioError;
208      }      }
209      dmsg(2,("Before ASIOGetChannels()\n"));      dmsg(2,("Before ASIOGetChannels()\n"));
210      if ((asioError = ASIOGetChannels(&driverInfo->numInputChannels,      if ((asioError = ASIOGetChannels(&driverInfo->numInputChannels,
211                                       &driverInfo->numOutputChannels)) != ASE_OK) {                                       &driverInfo->numOutputChannels)) != ASE_OK) {
212          dmsg(1,("ASIO_OpenAndQueryDeviceInfo could not ASIOGetChannels for %s: %d\n",          dmsg(1,("ASIO_OpenAndQueryDeviceInfo could not ASIOGetChannels for %s: %d\n",
213                  driverName.c_str(), int(asioError)));                  driverName.c_str(), int(asioError)));
214          throw AudioOutputException(errmsg);          return asioError;
215      }      }
216    
217      dmsg(2,("Before ASIOGetBufferSize()\n"));      dmsg(2,("Before ASIOGetBufferSize()\n"));
# Line 226  void ASIO_OpenAndQueryDeviceInfo(String Line 221  void ASIO_OpenAndQueryDeviceInfo(String
221                                         &driverInfo->bufGranularity)) != ASE_OK) {                                         &driverInfo->bufGranularity)) != ASE_OK) {
222          dmsg(1,("ASIO_OpenAndQueryDeviceInfo could not ASIOGetBufferSize for %s: %d\n",          dmsg(1,("ASIO_OpenAndQueryDeviceInfo could not ASIOGetBufferSize for %s: %d\n",
223                  driverName.c_str(), int(asioError)));                  driverName.c_str(), int(asioError)));
224          throw AudioOutputException(errmsg);          return asioError;
225      }      }
226    
227      dmsg(2,("ASIO_OpenAndQueryDeviceInfo: InputChannels = %ld\n", driverInfo->numInputChannels));      dmsg(2,("ASIO_OpenAndQueryDeviceInfo: InputChannels = %ld\n", driverInfo->numInputChannels));
# Line 234  void ASIO_OpenAndQueryDeviceInfo(String Line 229  void ASIO_OpenAndQueryDeviceInfo(String
229    
230      // Loop through the possible sampling rates and check each to see      // Loop through the possible sampling rates and check each to see
231      // if the device supports it.      // if the device supports it.
     driverInfo->numSampleRates = 0;  
232      driverInfo->sampleRates.clear();      driverInfo->sampleRates.clear();
233      for (int index = 0; index < MAX_NUMSAMPLINGRATES; index++) {      for (int index = 0; index < MAX_NUMSAMPLINGRATES; index++) {
234          if (ASIOCanSampleRate(possibleSampleRates[index]) != ASE_NoClock) {          if (ASIOCanSampleRate(possibleSampleRates[index]) != ASE_NoClock) {
235              dmsg(2,("ASIOCanSampleRate: possible sample rate = %ld\n",              dmsg(2,("ASIOCanSampleRate: possible sample rate = %ld\n",
236                      (long)possibleSampleRates[index]));                      (long)possibleSampleRates[index]));
237              driverInfo->sampleRates.push_back((int)possibleSampleRates[index]);              driverInfo->sampleRates.push_back((int)possibleSampleRates[index]);
             driverInfo->numSampleRates++;  
238          }          }
239      }      }
240    
# Line 256  void ASIO_OpenAndQueryDeviceInfo(String Line 249  void ASIO_OpenAndQueryDeviceInfo(String
249    
250      dmsg(2,("ASIO_OpenAndQueryDeviceInfo: driver opened.\n"));      dmsg(2,("ASIO_OpenAndQueryDeviceInfo: driver opened.\n"));
251      asioDriverOpened = true;      asioDriverOpened = true;
252        return ASE_OK;
253  }  }
254    
255    
# Line 292  std::vector<String> getAsioDriverNames() Line 286  std::vector<String> getAsioDriverNames()
286  #if 1  #if 1
287          asioDriverList.push_back(names[i]);          asioDriverList.push_back(names[i]);
288  #else  #else
         int asioError;  
289          // FIXME: We currently try what is the best method to exclude          // FIXME: We currently try what is the best method to exclude
290          // not connected devices or not working drivers. The code          // not connected devices or not working drivers. The code
291          // below is for testing only, it tries to load each ASIO          // below is for testing only, it tries to load each ASIO
292          // driver and if it gives an error it is not included in the          // driver and if it gives an error it is not included in the
293          // list of available drivers (asioDriverList).          // list of available drivers (asioDriverList).
294          if (ASIO_loadAsioDriver(names[i])) {          if (ASIO_loadAsioDriver(names[i])) {
295              if ((asioError = ASIOInit(&MyAsioDriverInfo)) == ASE_OK) {              ASIOError asioError;
296                if ((asioError = ASIOInit(&asioDriverInfo.driverInfo)) == ASE_OK) {
297                  asioDriverList.push_back(names[i]);                  asioDriverList.push_back(names[i]);
298              }              }
299              else {              else {
300                  dmsg(2,("getDriverList: ASIOInit of driver %s gave Error %d! ignoring it.\n",                  dmsg(2,("getDriverList: ASIOInit of driver %s gave Error %d! ignoring it.\n",
301                          names[i], asioError));                          names[i], int(asioError)));
302              }              }
303          }          }
304          else {          else {
# Line 486  void AudioOutputDeviceAsio::bufferSwitch Line 480  void AudioOutputDeviceAsio::bufferSwitch
480      // timeInfo needs to be created, though it will only set the      // timeInfo needs to be created, though it will only set the
481      // timeInfo.samplePosition and timeInfo.systemTime fields and the      // timeInfo.samplePosition and timeInfo.systemTime fields and the
482      // according flags.      // according flags.
483      ASIOTime  timeInfo;      ASIOTime timeInfo;
484      memset(&timeInfo, 0, sizeof(timeInfo));      memset(&timeInfo, 0, sizeof(timeInfo));
485    
486      // Get the time stamp of the buffer. Not necessary if no      // Get the time stamp of the buffer. Not necessary if no
# Line 602  std::map<String,DeviceCreationParameter* Line 596  std::map<String,DeviceCreationParameter*
596  optional<String> AudioOutputDeviceAsio::ParameterCard::DefaultAsString(std::map<String,String> Parameters) {  optional<String> AudioOutputDeviceAsio::ParameterCard::DefaultAsString(std::map<String,String> Parameters) {
597      std::vector<String> cards = PossibilitiesAsString(Parameters);      std::vector<String> cards = PossibilitiesAsString(Parameters);
598      if (cards.empty()) throw Exception("AudioOutputDeviceAsio: Can't find any card");      if (cards.empty()) throw Exception("AudioOutputDeviceAsio: Can't find any card");
     dmsg(2,("AudioOutputDeviceAsio::ParameterCard::DefaultAsString='%s'\n", cards[0].c_str()));  
599    
600      // If currentAsioDriverName is empty then return the first card,      // If currentAsioDriverName is empty then return the first card,
601      // otherwise return the currentAsioDriverName. This avoids closing      // otherwise return the currentAsioDriverName. This avoids closing
# Line 611  optional<String> AudioOutputDeviceAsio:: Line 604  optional<String> AudioOutputDeviceAsio::
604      // would load the default card (without this check it would always      // would load the default card (without this check it would always
605      // be the same which would cause the above problem).      // be the same which would cause the above problem).
606      if (currentAsioDriverName == "") {      if (currentAsioDriverName == "") {
607            dmsg(2,("AudioOutputDeviceAsio::ParameterCard::DefaultAsString='%s' (first card by default)\n", cards[0].c_str()));
608          return cards[0]; // first card by default          return cards[0]; // first card by default
609      }      }
610      else {      else {
611            dmsg(2,("AudioOutputDeviceAsio::ParameterCard::DefaultAsString='%s'\n", currentAsioDriverName.c_str()));
612          return currentAsioDriverName;          return currentAsioDriverName;
613      }      }
614    
# Line 652  std::map<String,DeviceCreationParameter* Line 647  std::map<String,DeviceCreationParameter*
647    
648  optional<int> AudioOutputDeviceAsio::ParameterSampleRate::DefaultAsInt(std::map<String,String> Parameters) {  optional<int> AudioOutputDeviceAsio::ParameterSampleRate::DefaultAsInt(std::map<String,String> Parameters) {
649      if (!Parameters.count("CARD")) {      if (!Parameters.count("CARD")) {
650          dmsg(2,("AudioOutputDeviceAsio::ParameterSampleRate::DefaultAsInt returning optional<int>::nothing  (parameter CARD not supplied)\n"));          dmsg(2,("AudioOutputDeviceAsio::ParameterSampleRate::DefaultAsInt returning optional<int>::nothing (parameter CARD not supplied)\n"));
651          return optional<int>::nothing;          return optional<int>::nothing;
652      }      }
653    
654      // return the default samplerate. first try 44100 then 48000, then      // return the default samplerate. first try 44100 then 48000, then
655      // the first samplerate found in the list      // the first samplerate found in the list
656      ParameterCard card(Parameters["CARD"]);      ParameterCard card(Parameters["CARD"]);
657      ASIO_OpenAndQueryDeviceInfo(card.ValueAsString(), &asioDriverInfo, &MyAsioDriverInfo);      if (ASIO_OpenAndQueryDeviceInfo(card.ValueAsString(), &asioDriverInfo) != 0) return optional<int>::nothing;
658      for (uint i = 0; i < asioDriverInfo.sampleRates.size(); i++) {      for (uint i = 0; i < asioDriverInfo.sampleRates.size(); i++) {
659          if (asioDriverInfo.sampleRates[i] == 44100) {          if (asioDriverInfo.sampleRates[i] == 44100) {
             return 44100;  
660              dmsg(2,("AudioOutputDeviceAsio::ParameterSampleRate::DefaultAsInt returning 44100\n"));              dmsg(2,("AudioOutputDeviceAsio::ParameterSampleRate::DefaultAsInt returning 44100\n"));
661                return 44100;
662          }          }
663          if (asioDriverInfo.sampleRates[i] == 48000) {          if (asioDriverInfo.sampleRates[i] == 48000) {
664              dmsg(2,("AudioOutputDeviceAsio::ParameterSampleRate::DefaultAsInt returning 48000\n"));              dmsg(2,("AudioOutputDeviceAsio::ParameterSampleRate::DefaultAsInt returning 48000\n"));
# Line 678  optional<int> AudioOutputDeviceAsio::Par Line 673  optional<int> AudioOutputDeviceAsio::Par
673  std::vector<int> AudioOutputDeviceAsio::ParameterSampleRate::PossibilitiesAsInt(std::map<String,String> Parameters) {  std::vector<int> AudioOutputDeviceAsio::ParameterSampleRate::PossibilitiesAsInt(std::map<String,String> Parameters) {
674      dmsg(2,("AudioOutputDeviceAsio::ParameterSampleRate::PossibilitiesAsInt\n"));      dmsg(2,("AudioOutputDeviceAsio::ParameterSampleRate::PossibilitiesAsInt\n"));
675      if (!Parameters.count("CARD")) {      if (!Parameters.count("CARD")) {
676          dmsg(2,("AudioOutputDeviceAsio::ParameterSampleRate::PossibilitiesAsInt returning empty vector  (parameter CARD not supplied)\n"));          dmsg(2,("AudioOutputDeviceAsio::ParameterSampleRate::PossibilitiesAsInt returning empty vector (parameter CARD not supplied)\n"));
677          return std::vector<int>();          return std::vector<int>();
678      }      }
679    
680      ParameterCard card(Parameters["CARD"]);      ParameterCard card(Parameters["CARD"]);
681      ASIO_OpenAndQueryDeviceInfo(card.ValueAsString(), &asioDriverInfo, &MyAsioDriverInfo);      if (ASIO_OpenAndQueryDeviceInfo(card.ValueAsString(), &asioDriverInfo) != 0) return std::vector<int>();
682    
683      for (uint i = 0; i < asioDriverInfo.sampleRates.size(); i++) {      for (uint i = 0; i < asioDriverInfo.sampleRates.size(); i++) {
684          dmsg(2,("AudioOutputDeviceAsio::ParameterSampleRate::PossibilitiesAsInt samplerate[%d]=%d\n", i, asioDriverInfo.sampleRates[i]));          dmsg(2,("AudioOutputDeviceAsio::ParameterSampleRate::PossibilitiesAsInt samplerate[%d]=%d\n", i, asioDriverInfo.sampleRates[i]));
# Line 721  optional<int> AudioOutputDeviceAsio::Par Line 716  optional<int> AudioOutputDeviceAsio::Par
716      }      }
717    
718      ParameterCard card(Parameters["CARD"]);      ParameterCard card(Parameters["CARD"]);
719      ASIO_OpenAndQueryDeviceInfo(card.ValueAsString(), &asioDriverInfo, &MyAsioDriverInfo);      if (ASIO_OpenAndQueryDeviceInfo(card.ValueAsString(), &asioDriverInfo) != 0) return optional<int>::nothing;
720      dmsg(2,("AudioOutputDeviceAsio::ParameterChannels::DefaultAsInt returning %ld\n",      dmsg(2,("AudioOutputDeviceAsio::ParameterChannels::DefaultAsInt returning %ld\n",
721              asioDriverInfo.numOutputChannels));              asioDriverInfo.numOutputChannels));
722      return asioDriverInfo.numOutputChannels;      return asioDriverInfo.numOutputChannels;
723  }  }
724    
725  optional<int> AudioOutputDeviceAsio::ParameterChannels::RangeMinAsInt(std::map<String,String> Parameters) {  optional<int> AudioOutputDeviceAsio::ParameterChannels::RangeMinAsInt(std::map<String,String> Parameters) {
726      dmsg(2,("AudioOutputDeviceAsio::ParameterChannels::RangeMinAsInt!\n"));      dmsg(2,("AudioOutputDeviceAsio::ParameterChannels::RangeMinAsInt\n"));
727      if (!Parameters.count("CARD")) {      if (!Parameters.count("CARD")) {
728          dmsg(2,("AudioOutputDeviceAsio::ParameterChannels::RangeMinAsInt returning optional<int>::nothing (CARD parameter not supplied)\n"));          dmsg(2,("AudioOutputDeviceAsio::ParameterChannels::RangeMinAsInt returning optional<int>::nothing (CARD parameter not supplied)\n"));
729          return optional<int>::nothing;          return optional<int>::nothing;
# Line 738  optional<int> AudioOutputDeviceAsio::Par Line 733  optional<int> AudioOutputDeviceAsio::Par
733  }  }
734    
735  optional<int> AudioOutputDeviceAsio::ParameterChannels::RangeMaxAsInt(std::map<String,String> Parameters) {  optional<int> AudioOutputDeviceAsio::ParameterChannels::RangeMaxAsInt(std::map<String,String> Parameters) {
736      dmsg(2,("AudioOutputDeviceAsio::ParameterChannels::RangeMaxAsInt!\n"));      dmsg(2,("AudioOutputDeviceAsio::ParameterChannels::RangeMaxAsInt\n"));
737      if (!Parameters.count("CARD")) {      if (!Parameters.count("CARD")) {
738          dmsg(2,("AudioOutputDeviceAsio::ParameterChannels::RangeMaxAsInt returning optional<int>::nothing (CARD parameter not supplied)\n"));          dmsg(2,("AudioOutputDeviceAsio::ParameterChannels::RangeMaxAsInt returning optional<int>::nothing (CARD parameter not supplied)\n"));
739          return optional<int>::nothing;          return optional<int>::nothing;
740      }      }
741    
742      ParameterCard card(Parameters["CARD"]);      ParameterCard card(Parameters["CARD"]);
743      ASIO_OpenAndQueryDeviceInfo(card.ValueAsString(), &asioDriverInfo, &MyAsioDriverInfo);      if (ASIO_OpenAndQueryDeviceInfo(card.ValueAsString(), &asioDriverInfo) != 0) return optional<int>::nothing;
744      dmsg(2,("AudioOutputDeviceAsio::ParameterChannels::RangeMaxAsInt returning %ld\n",      dmsg(2,("AudioOutputDeviceAsio::ParameterChannels::RangeMaxAsInt returning %ld\n",
745              asioDriverInfo.numOutputChannels));              asioDriverInfo.numOutputChannels));
746      return asioDriverInfo.numOutputChannels;      return asioDriverInfo.numOutputChannels;
# Line 783  std::map<String,DeviceCreationParameter* Line 778  std::map<String,DeviceCreationParameter*
778  }  }
779    
780  optional<int> AudioOutputDeviceAsio::ParameterFragmentSize::DefaultAsInt(std::map<String,String> Parameters) {  optional<int> AudioOutputDeviceAsio::ParameterFragmentSize::DefaultAsInt(std::map<String,String> Parameters) {
781      dmsg(2,("AudioOutputDeviceAsio::ParameterFragmentSize::DefaultAsInt!\n"));      dmsg(2,("AudioOutputDeviceAsio::ParameterFragmentSize::DefaultAsInt\n"));
782      if (!Parameters.count("CARD")) {      if (!Parameters.count("CARD")) {
783          dmsg(2,("AudioOutputDeviceAsio::ParameterFragmentSize::DefaultAsInt returning optional<int>::nothing (no CARD parameter supplied\n"));          dmsg(2,("AudioOutputDeviceAsio::ParameterFragmentSize::DefaultAsInt returning optional<int>::nothing (no CARD parameter supplied\n"));
784          return optional<int>::nothing;          return optional<int>::nothing;
785      }      }
786    
787      ParameterCard card(Parameters["CARD"]);      ParameterCard card(Parameters["CARD"]);
788      ASIO_OpenAndQueryDeviceInfo(card.ValueAsString(), &asioDriverInfo, &MyAsioDriverInfo);      if (ASIO_OpenAndQueryDeviceInfo(card.ValueAsString(), &asioDriverInfo) != 0) return optional<int>::nothing;
789      dmsg(2,("AudioOutputDeviceAsio::ParameterFragmentSize::DefaultAsInt returning %ld\n",      dmsg(2,("AudioOutputDeviceAsio::ParameterFragmentSize::DefaultAsInt returning %ld\n",
790              asioDriverInfo.preferredBufSize));              asioDriverInfo.preferredBufSize));
791      return asioDriverInfo.preferredBufSize;      return asioDriverInfo.preferredBufSize;
792  }  }
793    
794  optional<int> AudioOutputDeviceAsio::ParameterFragmentSize::RangeMinAsInt(std::map<String,String> Parameters) {  optional<int> AudioOutputDeviceAsio::ParameterFragmentSize::RangeMinAsInt(std::map<String,String> Parameters) {
795      dmsg(2,("AudioOutputDeviceAsio::ParameterFragmentSize::RangeMinAsInt!\n"));      dmsg(2,("AudioOutputDeviceAsio::ParameterFragmentSize::RangeMinAsInt\n"));
796      if (!Parameters.count("CARD")) {      if (!Parameters.count("CARD")) {
797          dmsg(2,("AudioOutputDeviceAsio::ParameterFragmentSize::RangeMinAsInt returning optional<int>::nothing (no CARD parameter supplied\n"));          dmsg(2,("AudioOutputDeviceAsio::ParameterFragmentSize::RangeMinAsInt returning optional<int>::nothing (no CARD parameter supplied\n"));
798          return optional<int>::nothing;          return optional<int>::nothing;
799      }      }
800    
801      ParameterCard card(Parameters["CARD"]);      ParameterCard card(Parameters["CARD"]);
802      ASIO_OpenAndQueryDeviceInfo(card.ValueAsString(), &asioDriverInfo, &MyAsioDriverInfo);      if (ASIO_OpenAndQueryDeviceInfo(card.ValueAsString(), &asioDriverInfo) != 0) return optional<int>::nothing;
803      dmsg(2,("AudioOutputDeviceAsio::ParameterFragmentSize::RangeMinAsInt returning %ld\n",      dmsg(2,("AudioOutputDeviceAsio::ParameterFragmentSize::RangeMinAsInt returning %ld\n",
804              asioDriverInfo.minBufSize));              asioDriverInfo.minBufSize));
805      return asioDriverInfo.minBufSize;      return asioDriverInfo.minBufSize;
806  }  }
807    
808  optional<int> AudioOutputDeviceAsio::ParameterFragmentSize::RangeMaxAsInt(std::map<String,String> Parameters) {  optional<int> AudioOutputDeviceAsio::ParameterFragmentSize::RangeMaxAsInt(std::map<String,String> Parameters) {
809      dmsg(2,("AudioOutputDeviceAsio::ParameterFragmentSize::RangeMaxAsInt!\n"));      dmsg(2,("AudioOutputDeviceAsio::ParameterFragmentSize::RangeMaxAsInt\n"));
810      if (!Parameters.count("CARD")) {      if (!Parameters.count("CARD")) {
811          dmsg(2,("AudioOutputDeviceAsio::ParameterFragmentSize::RangeMaxAsInt returning optional<int>::nothing (no CARD parameter supplied\n"));          dmsg(2,("AudioOutputDeviceAsio::ParameterFragmentSize::RangeMaxAsInt returning optional<int>::nothing (no CARD parameter supplied\n"));
812          return optional<int>::nothing;          return optional<int>::nothing;
813      }      }
814    
815      ParameterCard card(Parameters["CARD"]);      ParameterCard card(Parameters["CARD"]);
816      ASIO_OpenAndQueryDeviceInfo(card.ValueAsString(), &asioDriverInfo, &MyAsioDriverInfo);      if (ASIO_OpenAndQueryDeviceInfo(card.ValueAsString(), &asioDriverInfo) != 0) return optional<int>::nothing;
817      dmsg(2,("AudioOutputDeviceAsio::ParameterFragmentSize::RangeMaxAsInt returning %ld\n",      dmsg(2,("AudioOutputDeviceAsio::ParameterFragmentSize::RangeMaxAsInt returning %ld\n",
818              asioDriverInfo.maxBufSize));              asioDriverInfo.maxBufSize));
819      return asioDriverInfo.maxBufSize;      return asioDriverInfo.maxBufSize;
820  }  }
821    
822  std::vector<int> AudioOutputDeviceAsio::ParameterFragmentSize::PossibilitiesAsInt(std::map<String,String> Parameters) {  std::vector<int> AudioOutputDeviceAsio::ParameterFragmentSize::PossibilitiesAsInt(std::map<String,String> Parameters) {
823      dmsg(2,("AudioOutputDeviceAsio::ParameterFragmentSize::PossibilitiesAsInt!\n"));      dmsg(2,("AudioOutputDeviceAsio::ParameterFragmentSize::PossibilitiesAsInt\n"));
824      return std::vector<int>();      return std::vector<int>();
825  }  }
826    
# Line 851  String AudioOutputDeviceAsio::ParameterF Line 846  String AudioOutputDeviceAsio::ParameterF
846  AudioOutputDeviceAsio::AudioOutputDeviceAsio(std::map<String,DeviceCreationParameter*> Parameters) : AudioOutputDevice(Parameters) {  AudioOutputDeviceAsio::AudioOutputDeviceAsio(std::map<String,DeviceCreationParameter*> Parameters) : AudioOutputDevice(Parameters) {
847      if (AudioOutputDeviceAsioInstantiated) throw Exception("AudioOutputDeviceAsio: Sorry, only one ASIO card at time can be opened");      if (AudioOutputDeviceAsioInstantiated) throw Exception("AudioOutputDeviceAsio: Sorry, only one ASIO card at time can be opened");
848      AudioOutputDeviceAsioInstantiated = true;      AudioOutputDeviceAsioInstantiated = true;
     asioDriverOpened = false;  
849      this->uiAsioChannels = ((DeviceCreationParameterInt*)Parameters["CHANNELS"])->ValueAsInt();      this->uiAsioChannels = ((DeviceCreationParameterInt*)Parameters["CHANNELS"])->ValueAsInt();
850      this->uiSamplerate   = ((DeviceCreationParameterInt*)Parameters["SAMPLERATE"])->ValueAsInt();      this->uiSamplerate   = ((DeviceCreationParameterInt*)Parameters["SAMPLERATE"])->ValueAsInt();
851      this->FragmentSize   = ((DeviceCreationParameterInt*)Parameters["FRAGMENTSIZE"])->ValueAsInt();      this->FragmentSize   = ((DeviceCreationParameterInt*)Parameters["FRAGMENTSIZE"])->ValueAsInt();
852      String card          = ((DeviceCreationParameterString*)Parameters["CARD"])->ValueAsString();      String card          = ((DeviceCreationParameterString*)Parameters["CARD"])->ValueAsString();
853    
854    
855      dmsg(2,("AudioOutputDeviceAsio::AudioOutputDeviceAsio constructor\n"));      dmsg(2,("AudioOutputDeviceAsio::AudioOutputDeviceAsio constructor channels=%d samplerate=%d fragmentsize=%d card=%s\n",
856                uiAsioChannels, uiSamplerate, FragmentSize, card.c_str()));
857    
858      asioIsPlaying = false;      asioIsPlaying = false;
859    
860      ASIO_OpenAndQueryDeviceInfo(card, &asioDriverInfo, &MyAsioDriverInfo);      if (ASIO_OpenAndQueryDeviceInfo(card, &asioDriverInfo) != 0) {
861            throw AudioOutputException("Error: ASIO Initialization error");
862        }
863      dmsg(2,("AudioOutputDeviceAsio::AudioOutputDeviceAsio: after ASIO_OpenAndQueryDeviceInfo\n"));      dmsg(2,("AudioOutputDeviceAsio::AudioOutputDeviceAsio: after ASIO_OpenAndQueryDeviceInfo\n"));
864    
865      if (ASIOSetSampleRate(uiSamplerate) != ASE_OK) {      ASIOError asioError;
866        if ((asioError = ASIOSetSampleRate(uiSamplerate)) != ASE_OK) {
867            dmsg(1,("AudioOutputDeviceAsio::AudioOutputDeviceAsio: ASIOSetSampleRate failed: %d\n", int(asioError)));
868          throw AudioOutputException("Error: ASIOSetSampleRate: cannot set samplerate.");          throw AudioOutputException("Error: ASIOSetSampleRate: cannot set samplerate.");
869      }      }
870      dmsg(2,("AudioOutputDeviceAsio::AudioOutputDeviceAsio: after ASIOSetSampleRate\n"));      dmsg(2,("AudioOutputDeviceAsio::AudioOutputDeviceAsio: after ASIOSetSampleRate\n"));
871    
872      if (ASIOOutputReady() == ASE_OK) asioDriverInfo.ASIOOutputReadySupported = true;      asioDriverInfo.ASIOOutputReadySupported = (ASIOOutputReady() == ASE_OK);
873      else asioDriverInfo.ASIOOutputReadySupported = false;      dmsg(2,("AudioOutputDeviceAsio::AudioOutputDeviceAsio: after ASIOOutputReady: %d\n",
874      dmsg(2,("AudioOutputDeviceAsio::AudioOutputDeviceAsio: after ASIOOutputReady\n"));               asioDriverInfo.ASIOOutputReadySupported));
875    
876      asioDriverInfo.numInputBuffers = 0;      asioDriverInfo.numInputBuffers = 0;
877      asioDriverInfo.numOutputBuffers = uiAsioChannels;      asioDriverInfo.numOutputBuffers = uiAsioChannels;
# Line 888  AudioOutputDeviceAsio::AudioOutputDevice Line 887  AudioOutputDeviceAsio::AudioOutputDevice
887      asioCallbacks.asioMessage = &asioMessages;      asioCallbacks.asioMessage = &asioMessages;
888      asioCallbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfo;      asioCallbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfo;
889    
890      if (ASIOCreateBuffers(asioDriverInfo.bufferInfos,      if ((asioError = ASIOCreateBuffers(asioDriverInfo.bufferInfos,
891                            asioDriverInfo.numOutputBuffers,                                         asioDriverInfo.numOutputBuffers,
892                            asioDriverInfo.chosenBufSize = FragmentSize,                                         asioDriverInfo.chosenBufSize,
893                            &asioCallbacks) != ASE_OK) {                                         &asioCallbacks)) != ASE_OK) {
894            dmsg(1,("AudioOutputDeviceAsio::AudioOutputDeviceAsio: ASIOCreateBuffers failed: %d\n", int(asioError)));
895          throw AudioOutputException("AudioOutputDeviceAsio: Error: ASIOCreateBuffers failed.");          throw AudioOutputException("AudioOutputDeviceAsio: Error: ASIOCreateBuffers failed.");
896      }      }
897      dmsg(2,("AudioOutputDeviceAsio::AudioOutputDeviceAsio: after ASIOCreateBuffers\n"));      dmsg(2,("AudioOutputDeviceAsio::AudioOutputDeviceAsio: after ASIOCreateBuffers\n"));
# Line 918  AudioOutputDeviceAsio::~AudioOutputDevic Line 918  AudioOutputDeviceAsio::~AudioOutputDevic
918  }  }
919    
920  void AudioOutputDeviceAsio::Play() {  void AudioOutputDeviceAsio::Play() {
921      dmsg(2,("AudioOutputDeviceAsio::Play() !\n"));      dmsg(2,("AudioOutputDeviceAsio::Play()\n"));
922      if (ASIOStart() != ASE_OK) {      ASIOError asioError;
923        if ((asioError = ASIOStart()) != ASE_OK) {
924          asioIsPlaying = false;          asioIsPlaying = false;
925          throw AudioOutputException("AudioOutputDeviceAsio: Error: ASIOStart failed.");          dmsg(1,("AudioOutputDeviceAsio::Play: ASIOStart failed: %d\n", int(asioError)));
926            throw AudioOutputException("AudioOutputDeviceAsio: Error: ASIOStart failed");
927      }      }
928      else asioIsPlaying = true;      else asioIsPlaying = true;
929  }  }
# Line 931  bool AudioOutputDeviceAsio::IsPlaying() Line 933  bool AudioOutputDeviceAsio::IsPlaying()
933  }  }
934    
935  void AudioOutputDeviceAsio::Stop() {  void AudioOutputDeviceAsio::Stop() {
936      dmsg(2,("AudioOutputDeviceAsio::Stop() !\n"));      dmsg(2,("AudioOutputDeviceAsio::Stop()\n"));
937      ASIOStop();      ASIOStop();
938      asioIsPlaying = false;      asioIsPlaying = false;
939  }  }
940    
941  AudioChannel* AudioOutputDeviceAsio::CreateChannel(uint ChannelNr) {  AudioChannel* AudioOutputDeviceAsio::CreateChannel(uint ChannelNr) {
942      dmsg(2,("AudioOutputDeviceAsio::CreateChannel value=%d  uiAsioChannels=%d\n",      dmsg(2,("AudioOutputDeviceAsio::CreateChannel value=%d uiAsioChannels=%d\n",
943              ChannelNr, uiAsioChannels));              ChannelNr, uiAsioChannels));
944      // just create a mix channel      // just create a mix channel
945      return new AudioChannel(ChannelNr, Channel(ChannelNr % uiAsioChannels));      return new AudioChannel(ChannelNr, Channel(ChannelNr % uiAsioChannels));
# Line 966  String AudioOutputDeviceAsio::Descriptio Line 968  String AudioOutputDeviceAsio::Descriptio
968  }  }
969    
970  String AudioOutputDeviceAsio::Version() {  String AudioOutputDeviceAsio::Version() {
971      String s = "$Revision: 1.5 $";      String s = "$Revision: 1.6 $";
972      return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword      return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword
973  }  }
974    

Legend:
Removed from v.1950  
changed lines
  Added in v.1951

  ViewVC Help
Powered by ViewVC