/[svn]/linuxsampler/trunk/src/audiodriver/AudioOutputDeviceAlsa.h
ViewVC logotype

Contents of /linuxsampler/trunk/src/audiodriver/AudioOutputDeviceAlsa.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 143 - (show annotations) (download) (as text)
Wed Jun 23 18:54:08 2004 UTC (19 years, 10 months ago) by capela
File MIME type: text/x-c++hdr
File size: 9728 byte(s)
* SET CHANNEL AUDIO_OUTPUT_TYPE <chan> <driver> command is back!
  creates an audio output device instance of the given driver type
  ('Jack' or 'Alsa') with default parameters if none exists,
  otherwise it just picks the first available device and assign
  it to the intended sampler channel.

* The AudioOutputDevice class get's a new pure virtual method,
  Driver(), which is implemented on both of the existing inherited
  classes, AudioOutputDeviceAlsa and AudioOutputDeviceJack, with
  the sole purpose to return the driver type name as a String
  ('Alsa' and 'Jack', respectively).

* The quoting on the filename argument for the LOAD INSTRUMENT
  command has been made optional; you can have both ways, with
  single quotes or none, keeping compability with older LSCP
  specification.

* An additional sanity check is made on LOAD INSTRUMENT, whether
  the sampler channel has an audio output device assigned, thus
  preventing the server from crashing on instrument file load.

* The GET AUDIO_OUTPUT_DEVICE INFO now includes the missing
  'driver' item, as predicted by the draft protocol document.

1 /***************************************************************************
2 * *
3 * LinuxSampler - modular, streaming capable sampler *
4 * *
5 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the Free Software *
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
20 * MA 02111-1307 USA *
21 ***************************************************************************/
22
23 #ifndef __LS_AUDIOOUTPUTDEVICEALSA_H__
24 #define __LS_AUDIOOUTPUTDEVICEALSA_H__
25
26 #include <string.h>
27 #include <alsa/asoundlib.h>
28
29 #include "../common/global.h"
30 #include "../common/Thread.h"
31 #include "AudioOutputDevice.h"
32 #include "AudioChannel.h"
33 #include "../drivers/DeviceParameter.h"
34
35 namespace LinuxSampler {
36
37 /** ALSA audio output driver
38 *
39 * Implements audio output to the Advanced Linux Sound Architecture (ALSA).
40 */
41 class AudioOutputDeviceAlsa : public AudioOutputDevice, protected Thread {
42 public:
43 AudioOutputDeviceAlsa(std::map<String,String> Parameters);
44 ~AudioOutputDeviceAlsa();
45
46 // derived abstract methods from class 'AudioOutputDevice'
47 virtual void Play();
48 virtual bool IsPlaying();
49 virtual void Stop();
50 virtual void AcquireChannels(uint Channels);
51 virtual uint MaxSamplesPerCycle();
52 virtual uint SampleRate();
53
54 virtual String Driver();
55
56 static String Description();
57 static String Version();
58
59 static std::map<String,DeviceCreationParameter*> AvailableParameters();
60
61 class ParameterCard : public DeviceCreationParameterString {
62 public:
63 ParameterCard(AudioOutputDevice* pDevice) { this->pDevice = pDevice; InitWithDefault();}
64 ParameterCard(AudioOutputDevice* pDevice, String card) throw (LinuxSamplerException) : DeviceCreationParameterString(card) { this->pDevice = pDevice; }
65 virtual String Description() { return "Sound card to be used"; }
66 virtual bool Fix() { return true; }
67 virtual bool Mandatory() { return false; }
68 virtual std::map<String,DeviceCreationParameter*> DependsAsParameters() { return std::map<String,DeviceCreationParameter*>(); }
69 virtual optional<String> Default(std::map<String,String> Parameters) { return "0,0"; /* first card by default */ }
70 virtual std::vector<String> PossibilitiesAsString(std::map<String,String> Parameters) { return std::vector<String>(); /*TODO: return possible cards*/ }
71 virtual void OnSetValue(String s) throw (LinuxSamplerException) { /* not posssible, as parameter is fix */ }
72 protected:
73 AudioOutputDevice* pDevice;
74 };
75
76 class ParameterFragments : public DeviceCreationParameterInt {
77 public:
78 ParameterFragments(AudioOutputDevice* pDevice) { this->pDevice = pDevice; InitWithDefault();}
79 ParameterFragments(AudioOutputDevice* pDevice, String val) throw (LinuxSamplerException) : DeviceCreationParameterInt(val) { this->pDevice = pDevice; }
80 virtual String Description() { return "Number of buffer fragments"; }
81 virtual bool Fix() { return true; }
82 virtual bool Mandatory() { return false; }
83 virtual std::map<String,DeviceCreationParameter*> DependsAsParameters() { return std::map<String,DeviceCreationParameter*>(); } //TODO: should return dependency to CARD
84 virtual optional<int> DefaultAsInt(std::map<String,String> Parameters) { return 2; /* until done */ }
85 virtual optional<int> RangeMinAsInt(std::map<String,String> Parameters) { return optional<int>::nothing; }
86 virtual optional<int> RangeMaxAsInt(std::map<String,String> Parameters) { return optional<int>::nothing; }
87 virtual std::vector<int> PossibilitiesAsInt(std::map<String,String> Parameters) { return std::vector<int>(); }
88 virtual void OnSetValue(int i) throw (LinuxSamplerException) { /* not posssible, as parameter is fix */ }
89 protected:
90 AudioOutputDevice* pDevice;
91 };
92
93 class ParameterFragmentSize : public DeviceCreationParameterInt {
94 public:
95 ParameterFragmentSize(AudioOutputDevice* pDevice) { this->pDevice = pDevice; InitWithDefault();}
96 ParameterFragmentSize(AudioOutputDevice* pDevice, String val) throw (LinuxSamplerException) : DeviceCreationParameterInt(val) { this->pDevice = pDevice; }
97 virtual String Description() { return "Size of each buffer fragment"; }
98 virtual bool Fix() { return true; }
99 virtual bool Mandatory() { return false; }
100 virtual std::map<String,DeviceCreationParameter*> DependsAsParameters() { return std::map<String,DeviceCreationParameter*>(); } //TODO: should return dependency to CARD
101 virtual optional<int> DefaultAsInt(std::map<String,String> Parameters) { return 128; /* until done */ }
102 virtual optional<int> RangeMinAsInt(std::map<String,String> Parameters) { return optional<int>::nothing; }
103 virtual optional<int> RangeMaxAsInt(std::map<String,String> Parameters) { return optional<int>::nothing; }
104 virtual std::vector<int> PossibilitiesAsInt(std::map<String,String> Parameters) { return std::vector<int>(); }
105 virtual void OnSetValue(int i) throw (LinuxSamplerException) { /* not posssible, as parameter is fix */ }
106 protected:
107 AudioOutputDevice* pDevice;
108 };
109
110 protected:
111 int Main(); ///< Implementation of virtual method from class Thread
112 //AudioOutputDeviceAlsa(uint Channels = 2, uint Samplerate = 44100, uint Fragments = 2, uint FragmentSize = 128, String Card = "0,0");
113
114 std::map<String,DeviceCreationParameter*> CreateParameters(std::map<String,String> Parameters);
115 private:
116 uint uiAlsaChannels;
117 uint uiSamplerate;
118 uint FragmentSize;
119 int16_t* pAlsaOutputBuffer; ///< This is the buffer where the final mix will be copied to and send to the sound card
120 String pcm_name; ///< Name of the PCM device, like plughw:0,0 the first number is the number of the soundcard, the second number is the number of the device.
121 snd_pcm_t* pcm_handle; ///< Handle for the PCM device
122 snd_pcm_stream_t stream;
123 snd_pcm_hw_params_t* hwparams; ///< This structure contains information about the hardware and can be used to specify the configuration to be used for the PCM stream.
124 snd_pcm_sw_params_t* swparams;
125
126 int Output();
127 bool HardwareParametersSupported(String card, uint channels, int samplerate, uint numfragments, uint fragmentsize);
128 };
129 }
130
131 #endif // __LS_AUDIOOUTPUTDEVICEALSA_H__

  ViewVC Help
Powered by ViewVC