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

Contents of /linuxsampler/trunk/src/drivers/audio/AudioOutputDeviceAlsa.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 200 - (show annotations) (download) (as text)
Tue Jul 13 22:04:16 2004 UTC (19 years, 9 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 9317 byte(s)
moved directory '/src/audiodriver' -> '/src/drivers/audio'

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 "../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,DeviceCreationParameter*> 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 Name();
57
58 static String Description();
59 static String Version();
60
61 class ParameterCard : public DeviceCreationParameterString {
62 public:
63 ParameterCard( void ) : DeviceCreationParameterString () { InitWithDefault(); }
64 ParameterCard( String s ) : DeviceCreationParameterString (s) {}
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 static String Name( void ) { return "card"; }
73 };
74
75 class ParameterFragments : public DeviceCreationParameterInt {
76 public:
77 ParameterFragments( void ) : DeviceCreationParameterInt () { InitWithDefault(); }
78 ParameterFragments( String s ) : DeviceCreationParameterInt (s) {}
79 virtual String Description() { return "Number of buffer fragments"; }
80 virtual bool Fix() { return true; }
81 virtual bool Mandatory() { return false; }
82 virtual std::map<String,DeviceCreationParameter*> DependsAsParameters() { return std::map<String,DeviceCreationParameter*>(); } //TODO: should return dependency to CARD
83 virtual optional<int> DefaultAsInt(std::map<String,String> Parameters) { return 2; /* until done */ }
84 virtual optional<int> RangeMinAsInt(std::map<String,String> Parameters) { return optional<int>::nothing; }
85 virtual optional<int> RangeMaxAsInt(std::map<String,String> Parameters) { return optional<int>::nothing; }
86 virtual std::vector<int> PossibilitiesAsInt(std::map<String,String> Parameters) { return std::vector<int>(); }
87 virtual void OnSetValue(int i) throw (LinuxSamplerException) { /* not posssible, as parameter is fix */ }
88 static String Name( void ) { return "fragments"; }
89 };
90
91 class ParameterFragmentSize : public DeviceCreationParameterInt {
92 public:
93 ParameterFragmentSize( void ) : DeviceCreationParameterInt () { InitWithDefault(); }
94 ParameterFragmentSize( String s ) : DeviceCreationParameterInt (s) {}
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 128; /* until done */ }
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 static String Name( void ) { return "fragmentsize"; }
105 };
106
107 protected:
108 int Main(); ///< Implementation of virtual method from class Thread
109
110 private:
111 uint uiAlsaChannels;
112 uint uiSamplerate;
113 uint FragmentSize;
114 int16_t* pAlsaOutputBuffer; ///< This is the buffer where the final mix will be copied to and send to the sound card
115 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.
116 snd_pcm_t* pcm_handle; ///< Handle for the PCM device
117 snd_pcm_stream_t stream;
118 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.
119 snd_pcm_sw_params_t* swparams;
120
121 int Output();
122 bool HardwareParametersSupported(String card, uint channels, int samplerate, uint numfragments, uint fragmentsize);
123 };
124 }
125
126 #endif // __LS_AUDIOOUTPUTDEVICEALSA_H__

  ViewVC Help
Powered by ViewVC