23 |
#ifndef __AUDIO_H__ |
#ifndef __AUDIO_H__ |
24 |
#define __AUDIO_H__ |
#define __AUDIO_H__ |
25 |
|
|
|
// We only support Alsa at the moment |
|
|
|
|
|
#include <string> |
|
|
#include <stdio.h> |
|
|
#include <stdlib.h> |
|
|
#include <string.h> |
|
|
#include <unistd.h> |
|
|
#include <alsa/asoundlib.h> |
|
|
#include <sched.h> |
|
|
#include <sys/mman.h> |
|
|
|
|
26 |
#include "global.h" |
#include "global.h" |
27 |
|
|
28 |
|
// just symbol prototyping |
29 |
|
class AudioThread; |
30 |
|
|
31 |
|
/** |
32 |
|
* Abstract class for audio output in LinuxSampler. This class will be |
33 |
|
* derived by specialized classes which implement the connection to a |
34 |
|
* specific audio output system (e.g. Alsa, Jack). |
35 |
|
*/ |
36 |
class AudioIO { |
class AudioIO { |
37 |
public: |
public: |
|
bool Initialized; |
|
|
int16_t* pOutputBuffer; ///< This is the buffer where the final mix will be copied to and send to the sound card |
|
|
uint Channels; |
|
|
uint Samplerate; |
|
|
uint Fragments; |
|
|
uint FragmentSize; ///< in sample points |
|
|
|
|
38 |
AudioIO(); |
AudioIO(); |
39 |
~AudioIO(); |
virtual ~AudioIO(); |
40 |
int Initialize(uint channels, uint samplerate, uint numfragments, uint fragmentsize); |
virtual void Activate() = 0; |
41 |
int Output(); |
virtual void Close() = 0; |
42 |
void Close(); |
virtual void* GetInterleavedOutputBuffer() = 0; |
43 |
private: |
virtual void* GetChannelOutputBufer(uint Channel) = 0; |
44 |
typedef std::string String; |
inline void AssignEngine(AudioThread* pAudioThread) { pEngine = pAudioThread; }; |
45 |
|
inline bool Initialized() { return bInitialized; }; |
46 |
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. |
inline bool Interleaved() { return bInterleaved; }; |
47 |
snd_pcm_t* pcm_handle; ///< Handle for the PCM device |
inline uint Channels() { return uiChannels; }; |
48 |
snd_pcm_stream_t stream; |
inline uint SampleRate() { return uiSamplerate; }; |
49 |
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. |
inline uint MaxSamplesPerCycle() { return uiMaxSamplesPerCycle; }; |
50 |
snd_pcm_sw_params_t* swparams; |
protected: |
51 |
|
bool bInitialized; |
52 |
bool HardwareParametersSupported(uint channels, int samplerate, uint numfragments, uint fragmentsize); |
bool bInterleaved; |
53 |
|
uint uiChannels; |
54 |
|
uint uiSamplerate; |
55 |
|
uint uiMaxSamplesPerCycle; ///< in sample points |
56 |
|
AudioThread* pEngine; |
57 |
}; |
}; |
58 |
|
|
59 |
#endif // __AUDIO_H__ |
#endif // __AUDIO_H__ |