/[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 880 - (show annotations) (download) (as text)
Tue Jun 27 22:57:37 2006 UTC (17 years, 10 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 7175 byte(s)
just some refactoring work:
- renamed class LinuxSamplerException -> Exception
- encapsulated LS API relevant files into LS namespace
- removed unnecessary header inclusions

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

  ViewVC Help
Powered by ViewVC