30 |
#include "../common/Thread.h" |
#include "../common/Thread.h" |
31 |
#include "AudioOutputDevice.h" |
#include "AudioOutputDevice.h" |
32 |
#include "AudioChannel.h" |
#include "AudioChannel.h" |
33 |
|
#include "../drivers/DeviceParameter.h" |
34 |
|
|
35 |
namespace LinuxSampler { |
namespace LinuxSampler { |
36 |
|
|
40 |
*/ |
*/ |
41 |
class AudioOutputDeviceAlsa : public AudioOutputDevice, protected Thread { |
class AudioOutputDeviceAlsa : public AudioOutputDevice, protected Thread { |
42 |
public: |
public: |
43 |
AudioOutputDeviceAlsa(uint Channels = 2, uint Samplerate = 44100, uint Fragments = 3, uint FragmentSize = 512, String Card = "0,0"); |
AudioOutputDeviceAlsa(std::map<String,String> Parameters); |
44 |
~AudioOutputDeviceAlsa(); |
~AudioOutputDeviceAlsa(); |
45 |
|
|
46 |
// derived abstract methods from class 'AudioOutputDevice' |
// derived abstract methods from class 'AudioOutputDevice' |
50 |
virtual void AcquireChannels(uint Channels); |
virtual void AcquireChannels(uint Channels); |
51 |
virtual uint MaxSamplesPerCycle(); |
virtual uint MaxSamplesPerCycle(); |
52 |
virtual uint SampleRate(); |
virtual uint SampleRate(); |
53 |
|
|
54 |
|
static String Description(); |
55 |
|
static String Version(); |
56 |
|
|
57 |
|
static std::map<String,DeviceCreationParameter*> AvailableParameters(); |
58 |
|
|
59 |
|
class ParameterCard : public DeviceCreationParameterString { |
60 |
|
public: |
61 |
|
ParameterCard(AudioOutputDevice* pDevice) { this->pDevice = pDevice; } |
62 |
|
ParameterCard(AudioOutputDevice* pDevice, String card) throw (LinuxSamplerException) : DeviceCreationParameterString(card) { this->pDevice = pDevice; } |
63 |
|
virtual String Description() { return "Sound card to be used"; } |
64 |
|
virtual bool Fix() { return true; } |
65 |
|
virtual bool Mandatory() { return false; } |
66 |
|
virtual std::map<String,DeviceCreationParameter*> DependsAsParameters() { return std::map<String,DeviceCreationParameter*>(); } |
67 |
|
virtual optional<String> Default(std::map<String,String> Parameters) { return "0,0"; /* first card by default */ } |
68 |
|
virtual std::vector<String> PossibilitiesAsString(std::map<String,String> Parameters) { return std::vector<String>(); /*TODO: return possible cards*/ } |
69 |
|
virtual void OnSetValue(String s) throw (LinuxSamplerException) { /* not posssible, as parameter is fix */ } |
70 |
|
protected: |
71 |
|
AudioOutputDevice* pDevice; |
72 |
|
}; |
73 |
|
|
74 |
|
class ParameterFragments : public DeviceCreationParameterInt { |
75 |
|
public: |
76 |
|
ParameterFragments(AudioOutputDevice* pDevice) { this->pDevice = pDevice; } |
77 |
|
ParameterFragments(AudioOutputDevice* pDevice, String val) throw (LinuxSamplerException) : DeviceCreationParameterInt(val) { this->pDevice = pDevice; } |
78 |
|
virtual String Description() { return "Number of buffer fragments"; } |
79 |
|
virtual bool Fix() { return true; } |
80 |
|
virtual bool Mandatory() { return false; } |
81 |
|
virtual std::map<String,DeviceCreationParameter*> DependsAsParameters() { return std::map<String,DeviceCreationParameter*>(); } //TODO: should return dependency to CARD |
82 |
|
virtual optional<int> DefaultAsInt(std::map<String,String> Parameters) { return optional<int>::nothing; } |
83 |
|
virtual optional<int> RangeMinAsInt(std::map<String,String> Parameters) { return optional<int>::nothing; } |
84 |
|
virtual optional<int> RangeMaxAsInt(std::map<String,String> Parameters) { return optional<int>::nothing; } |
85 |
|
virtual std::vector<int> PossibilitiesAsInt(std::map<String,String> Parameters) { return std::vector<int>(); } |
86 |
|
virtual void OnSetValue(int i) throw (LinuxSamplerException) { /* not posssible, as parameter is fix */ } |
87 |
|
protected: |
88 |
|
AudioOutputDevice* pDevice; |
89 |
|
}; |
90 |
|
|
91 |
|
class ParameterFragmentSize : public DeviceCreationParameterInt { |
92 |
|
public: |
93 |
|
ParameterFragmentSize(AudioOutputDevice* pDevice) { this->pDevice = pDevice; } |
94 |
|
ParameterFragmentSize(AudioOutputDevice* pDevice, String val) throw (LinuxSamplerException) : DeviceCreationParameterInt(val) { this->pDevice = pDevice; } |
95 |
|
virtual String Description() { return "Size of each buffer fragment"; } |
96 |
|
virtual bool Fix() { return true; } |
97 |
|
virtual bool Mandatory() { return false; } |
98 |
|
virtual std::map<String,DeviceCreationParameter*> DependsAsParameters() { return std::map<String,DeviceCreationParameter*>(); } //TODO: should return dependency to CARD |
99 |
|
virtual optional<int> DefaultAsInt(std::map<String,String> Parameters) { return optional<int>::nothing; } |
100 |
|
virtual optional<int> RangeMinAsInt(std::map<String,String> Parameters) { return optional<int>::nothing; } |
101 |
|
virtual optional<int> RangeMaxAsInt(std::map<String,String> Parameters) { return optional<int>::nothing; } |
102 |
|
virtual std::vector<int> PossibilitiesAsInt(std::map<String,String> Parameters) { return std::vector<int>(); } |
103 |
|
virtual void OnSetValue(int i) throw (LinuxSamplerException) { /* not posssible, as parameter is fix */ } |
104 |
|
protected: |
105 |
|
AudioOutputDevice* pDevice; |
106 |
|
}; |
107 |
|
|
108 |
protected: |
protected: |
109 |
int Main(); ///< Implementation of virtual method from class Thread |
int Main(); ///< Implementation of virtual method from class Thread |
110 |
|
AudioOutputDeviceAlsa(uint Channels = 2, uint Samplerate = 44100, uint Fragments = 2, uint FragmentSize = 128, String Card = "0,0"); |
111 |
|
|
112 |
|
std::map<String,DeviceCreationParameter*> CreateParameters(std::map<String,String> Parameters); |
113 |
private: |
private: |
114 |
uint uiAlsaChannels; |
uint uiAlsaChannels; |
115 |
uint uiSamplerate; |
uint uiSamplerate; |
122 |
snd_pcm_sw_params_t* swparams; |
snd_pcm_sw_params_t* swparams; |
123 |
|
|
124 |
int Output(); |
int Output(); |
125 |
bool HardwareParametersSupported(uint channels, int samplerate, uint numfragments, uint fragmentsize); |
bool HardwareParametersSupported(String card, uint channels, int samplerate, uint numfragments, uint fragmentsize); |
126 |
}; |
}; |
127 |
} |
} |
128 |
|
|