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

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

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

revision 227 by schoenebeck, Thu Aug 26 22:05:44 2004 UTC revision 513 by schoenebeck, Thu May 5 17:29:37 2005 UTC
# Line 25  Line 25 
25    
26  namespace LinuxSampler {  namespace LinuxSampler {
27    
     REGISTER_AUDIO_OUTPUT_DRIVER(AudioOutputDeviceAlsa);  
   
     /* Common parameters for now they'll have to be registered here. */  
     REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterActive);  
     REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterSampleRate);  
     REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterChannels);  
   
     /* Driver specific parameters */  
     REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterCard);  
     REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterFragments);  
     REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterFragmentSize);  
   
   
   
28  // *************** ParameterCard ***************  // *************** ParameterCard ***************
29  // *  // *
30    
# Line 148  namespace LinuxSampler { Line 134  namespace LinuxSampler {
134          // obtain information from given sound card          // obtain information from given sound card
135          String pcm_name       = "hw:" + Parameters["CARD"];          String pcm_name       = "hw:" + Parameters["CARD"];
136          snd_pcm_t* pcm_handle = NULL;          snd_pcm_t* pcm_handle = NULL;
137          if (snd_pcm_open(&pcm_handle, pcm_name.c_str(), SND_PCM_STREAM_PLAYBACK, 0) < 0) return optional<int>::nothing;          if (snd_pcm_open(&pcm_handle, pcm_name.c_str(), SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK) < 0) return optional<int>::nothing;
138          snd_pcm_hw_params_t* hwparams;          snd_pcm_hw_params_t* hwparams;
139          snd_pcm_hw_params_alloca(&hwparams);          snd_pcm_hw_params_alloca(&hwparams);
140          if (snd_pcm_hw_params_any(pcm_handle, hwparams) < 0) {          if (snd_pcm_hw_params_any(pcm_handle, hwparams) < 0) {
# Line 171  namespace LinuxSampler { Line 157  namespace LinuxSampler {
157          // obtain information from given sound card          // obtain information from given sound card
158          String pcm_name       = "hw:" + Parameters["CARD"];          String pcm_name       = "hw:" + Parameters["CARD"];
159          snd_pcm_t* pcm_handle = NULL;          snd_pcm_t* pcm_handle = NULL;
160          if (snd_pcm_open(&pcm_handle, pcm_name.c_str(), SND_PCM_STREAM_PLAYBACK, 0) < 0) return optional<int>::nothing;          if (snd_pcm_open(&pcm_handle, pcm_name.c_str(), SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK) < 0) return optional<int>::nothing;
161          snd_pcm_hw_params_t* hwparams;          snd_pcm_hw_params_t* hwparams;
162          snd_pcm_hw_params_alloca(&hwparams);          snd_pcm_hw_params_alloca(&hwparams);
163          if (snd_pcm_hw_params_any(pcm_handle, hwparams) < 0) {          if (snd_pcm_hw_params_any(pcm_handle, hwparams) < 0) {
# Line 241  namespace LinuxSampler { Line 227  namespace LinuxSampler {
227          // obtain information from given sound card          // obtain information from given sound card
228          String pcm_name       = "hw:" + Parameters["CARD"];          String pcm_name       = "hw:" + Parameters["CARD"];
229          snd_pcm_t* pcm_handle = NULL;          snd_pcm_t* pcm_handle = NULL;
230          if (snd_pcm_open(&pcm_handle, pcm_name.c_str(), SND_PCM_STREAM_PLAYBACK, 0) < 0) return optional<int>::nothing;          if (snd_pcm_open(&pcm_handle, pcm_name.c_str(), SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK) < 0) return optional<int>::nothing;
231          snd_pcm_hw_params_t* hwparams;          snd_pcm_hw_params_t* hwparams;
232          snd_pcm_hw_params_alloca(&hwparams);          snd_pcm_hw_params_alloca(&hwparams);
233          if (snd_pcm_hw_params_any(pcm_handle, hwparams) < 0) {          if (snd_pcm_hw_params_any(pcm_handle, hwparams) < 0) {
# Line 264  namespace LinuxSampler { Line 250  namespace LinuxSampler {
250          // obtain information from given sound card          // obtain information from given sound card
251          String pcm_name       = "hw:" + Parameters["CARD"];          String pcm_name       = "hw:" + Parameters["CARD"];
252          snd_pcm_t* pcm_handle = NULL;          snd_pcm_t* pcm_handle = NULL;
253          if (snd_pcm_open(&pcm_handle, pcm_name.c_str(), SND_PCM_STREAM_PLAYBACK, 0) < 0) return optional<int>::nothing;          if (snd_pcm_open(&pcm_handle, pcm_name.c_str(), SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK) < 0) return optional<int>::nothing;
254          snd_pcm_hw_params_t* hwparams;          snd_pcm_hw_params_t* hwparams;
255          snd_pcm_hw_params_alloca(&hwparams);          snd_pcm_hw_params_alloca(&hwparams);
256          if (snd_pcm_hw_params_any(pcm_handle, hwparams) < 0) {          if (snd_pcm_hw_params_any(pcm_handle, hwparams) < 0) {
# Line 304  namespace LinuxSampler { Line 290  namespace LinuxSampler {
290       * @param Parameters - optional parameters       * @param Parameters - optional parameters
291       * @throws AudioOutputException  if output device cannot be opened       * @throws AudioOutputException  if output device cannot be opened
292       */       */
293      AudioOutputDeviceAlsa::AudioOutputDeviceAlsa(std::map<String,DeviceCreationParameter*> Parameters) : AudioOutputDevice(Parameters), Thread(true, 1, 0) {      AudioOutputDeviceAlsa::AudioOutputDeviceAlsa(std::map<String,DeviceCreationParameter*> Parameters) : AudioOutputDevice(Parameters), Thread(true, true, 1, 0) {
294          pcm_handle           = NULL;          pcm_handle           = NULL;
295          stream               = SND_PCM_STREAM_PLAYBACK;          stream               = SND_PCM_STREAM_PLAYBACK;
296          this->uiAlsaChannels = ((DeviceCreationParameterInt*)Parameters["CHANNELS"])->ValueAsInt();          this->uiAlsaChannels = ((DeviceCreationParameterInt*)Parameters["CHANNELS"])->ValueAsInt();
# Line 313  namespace LinuxSampler { Line 299  namespace LinuxSampler {
299          uint Fragments       = ((DeviceCreationParameterInt*)Parameters["FRAGMENTS"])->ValueAsInt();          uint Fragments       = ((DeviceCreationParameterInt*)Parameters["FRAGMENTS"])->ValueAsInt();
300          String Card          = ((DeviceCreationParameterString*)Parameters["CARD"])->ValueAsString();          String Card          = ((DeviceCreationParameterString*)Parameters["CARD"])->ValueAsString();
301    
302          dmsg(1,("Checking if hw parameters supported...\n"));          dmsg(2,("Checking if hw parameters supported...\n"));
303          if (HardwareParametersSupported(Card, uiAlsaChannels, uiSamplerate, Fragments, FragmentSize)) {          if (HardwareParametersSupported(Card, uiAlsaChannels, uiSamplerate, Fragments, FragmentSize)) {
304              pcm_name = "hw:" + Card;              pcm_name = "hw:" + Card;
305          }          }
306          else {          else {
307              printf("Warning: your soundcard doesn't support chosen hardware parameters; ");              fprintf(stderr, "Warning: your soundcard doesn't support chosen hardware parameters; ");
308              printf("trying to compensate support lack with plughw...");              fprintf(stderr, "trying to compensate support lack with plughw...");
309              fflush(stdout);              fflush(stdout);
310              pcm_name = "plughw:" + Card;              pcm_name = "plughw:" + Card;
311          }          }
312          dmsg(1,("HW check completed.\n"));          dmsg(2,("HW check completed.\n"));
313    
314          int err;          int err;
315    
# Line 336  namespace LinuxSampler { Line 322  namespace LinuxSampler {
322          /* PCM device will return immediately. If SND_PCM_ASYNC is    */          /* PCM device will return immediately. If SND_PCM_ASYNC is    */
323          /* specified, SIGIO will be emitted whenever a period has     */          /* specified, SIGIO will be emitted whenever a period has     */
324          /* been completely processed by the soundcard.                */          /* been completely processed by the soundcard.                */
325          if ((err = snd_pcm_open(&pcm_handle, pcm_name.c_str(), stream, 0)) < 0) {          if ((err = snd_pcm_open(&pcm_handle, pcm_name.c_str(), stream, SND_PCM_NONBLOCK)) < 0) {
326              throw AudioOutputException(String("Error opening PCM device ") + pcm_name + ": " + snd_strerror(err));              throw AudioOutputException(String("Error opening PCM device ") + pcm_name + ": " + snd_strerror(err));
327          }          }
328    
# Line 444  namespace LinuxSampler { Line 430  namespace LinuxSampler {
430       *  Checks if sound card supports the chosen parameters.       *  Checks if sound card supports the chosen parameters.
431       *       *
432       *  @returns  true if hardware supports it       *  @returns  true if hardware supports it
433         *  @throws AudioOutputException - if device cannot be accessed
434       */       */
435      bool AudioOutputDeviceAlsa::HardwareParametersSupported(String card, uint channels, int samplerate, uint numfragments, uint fragmentsize) {      bool AudioOutputDeviceAlsa::HardwareParametersSupported(String card, uint channels, int samplerate, uint numfragments, uint fragmentsize) throw (AudioOutputException) {
436          pcm_name = "hw:" + card;          pcm_name = "hw:" + card;
437          if (snd_pcm_open(&pcm_handle, pcm_name.c_str(), stream, 0) < 0) return false;          int err;
438            if ((err = snd_pcm_open(&pcm_handle, pcm_name.c_str(), stream, SND_PCM_NONBLOCK)) < 0) {
439                throw AudioOutputException(String("Error opening PCM device ") + pcm_name + ": " + snd_strerror(err));
440            }
441          snd_pcm_hw_params_alloca(&hwparams);          snd_pcm_hw_params_alloca(&hwparams);
442          if (snd_pcm_hw_params_any(pcm_handle, hwparams) < 0) {          if (snd_pcm_hw_params_any(pcm_handle, hwparams) < 0) {
443              snd_pcm_close(pcm_handle);              snd_pcm_close(pcm_handle);
# Line 526  namespace LinuxSampler { Line 516  namespace LinuxSampler {
516      }      }
517    
518      String AudioOutputDeviceAlsa::Version() {      String AudioOutputDeviceAlsa::Version() {
519         String s = "$Revision: 1.15 $";         String s = "$Revision: 1.19 $";
520         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
521      }      }
522    

Legend:
Removed from v.227  
changed lines
  Added in v.513

  ViewVC Help
Powered by ViewVC