/[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 123 - (show annotations) (download) (as text)
Mon Jun 14 19:33:16 2004 UTC (19 years, 10 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 9634 byte(s)
* src/common: added template class 'optional<>' which can be used e.g. as
  return type whenever a value might be returned, but don't has to; this
  template class pretty much acts like a pointer of the given type, but is
  much more safer than a simple pointer
* src/audiodriver: added static class AudioDeviceFactory to create audio
  devices at runtime by using a string and to obtain driver informations
  of drivers at runtime, driver classes should simply use the macro
  REGISTER_AUDIO_OUTPUT_DRIVER(DriverName,DriverClass) in their cpp file
  to register the driver to LinuxSampler (no changes needed anymore in the
  LS code to add a new audio output driver)
* src/drivers: added classes to dynamically manage driver parameters; there
  are two different kinds of parameters: parameters which are need to
  create a new device (DeviceCreationParameterX) used to e.g. create an
  audio output device or a MIDI input device and parameters which are only
  available at runtime, means when a device is already created
  (DeviceRuntimeParameterX) which will be e.g. used as audio channel
  parameters and MIDI port parameters
* src/linuxsampler.cpp: all registered audio output drivers will be shown
  on the console on startup
* src/network: implemented configuration of audio output devices via LSCP

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 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:
109 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:
114 uint uiAlsaChannels;
115 uint uiSamplerate;
116 uint FragmentSize;
117 int16_t* pAlsaOutputBuffer; ///< This is the buffer where the final mix will be copied to and send to the sound card
118 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.
119 snd_pcm_t* pcm_handle; ///< Handle for the PCM device
120 snd_pcm_stream_t stream;
121 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.
122 snd_pcm_sw_params_t* swparams;
123
124 int Output();
125 bool HardwareParametersSupported(String card, uint channels, int samplerate, uint numfragments, uint fragmentsize);
126 };
127 }
128
129 #endif // __LS_AUDIOOUTPUTDEVICEALSA_H__

  ViewVC Help
Powered by ViewVC