alsa.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <alsa/asoundlib.h>
00024
00025 #include "audio_sample.h"
00026
00028
00029 typedef struct StoredSample
00030 {
00031 AudioSample *sample;
00032 int index;
00033 struct StoredSample *next;
00034 } StoredSample;
00035
00037
00038 typedef struct QueueItem
00039 {
00040 AudioSample *sample;
00041 bool temp;
00042 struct QueueItem *next;
00043 } QueueItem;
00044
00046
00047 typedef uint32_t ElemCap;
00048 const ElemCap ELEMCAP_CAN_PLAYBACK = 0x0001;
00049 const ElemCap ELEMCAP_CAN_CAPTURE = 0x0002;
00050 const ElemCap ELEMCAP_COMMON = 0x0004;
00051 const ElemCap ELEMCAP_PLAYBACK_VOL = 0x0008;
00052 const ElemCap ELEMCAP_CAPTURE_VOL = 0x0010;
00053 const ElemCap ELEMCAP_COMMON_VOL = 0x0020;
00054 const ElemCap ELEMCAP_PLAYBACK_SWITCH = 0x0040;
00055 const ElemCap ELEMCAP_CAPTURE_SWITCH = 0x0080;
00056 const ElemCap ELEMCAP_COMMON_SWITCH = 0x0100;
00057
00058
00059
00060
00061 typedef struct MixerElement
00062 {
00063 snd_mixer_elem_t *elem;
00064 long minPlayVol, curPlayVol, maxPlayVol;
00065 long minCapVol, curCapVol, maxCapVol;
00066 long minComVol, curComVol, maxComVol;
00067 int playSwitch, capSwitch, comSwitch;
00068 char *name;
00069 ElemCap caps;
00070 } MixerElement;
00071
00073
00074 typedef uint8_t PBState;
00075 const PBState PB_STATE_STOPPED = 0;
00076 const PBState PB_STATE_PLAYING = 1;
00077 const PBState PB_STATE_DRAIN = 2;
00078 const PBState PB_STATE_RECORDING = 3;
00079
00081
00082 class Alsa : public Driver
00083 {
00084 public:
00085 Alsa (ConfigFile* cf, int section);
00086 ~Alsa (void);
00087
00088 virtual int Setup (void);
00089 virtual int Shutdown (void);
00090
00091 virtual int ProcessMessage (QueuePointer &resp_queue, player_msghdr *hdr, void *data);
00092
00093 private:
00094
00095 bool useQueue;
00096 uint8_t debugLevel;
00097 char **mixerFilters;
00098 bool mixerFilterExact;
00099 char *pbDevice;
00100 char *mixerDevice;
00101 char *recDevice;
00102 uint32_t cfgPBPeriodTime;
00103 uint32_t cfgPBBufferTime;
00104 uint32_t silenceTime;
00105 uint32_t cfgRecBufferTime;
00106 uint32_t cfgRecStoreTime;
00107 uint32_t cfgRecPeriodTime;
00108 uint8_t recNumChannels;
00109 uint32_t recSampleRate;
00110 uint8_t recBits;
00111
00112
00113
00114 snd_pcm_t *pbHandle;
00115 int numPBFDs;
00116 struct pollfd *pbFDs;
00117 uint32_t actPBBufferTime;
00118 uint32_t actPBPeriodTime;
00119 snd_pcm_uframes_t pbPeriodSize;
00120 uint8_t *periodBuffer;
00121
00122 snd_pcm_t *recHandle;
00123 int numRecFDs;
00124 struct pollfd *recFDs;
00125 uint32_t actRecBufferTime;
00126 uint32_t actRecPeriodTime;
00127 snd_pcm_uframes_t recPeriodSize;
00128
00129 snd_mixer_t *mixerHandle;
00130 MixerElement *mixerElements;
00131 uint32_t numElements;
00132
00133
00134 int nextSampleIdx;
00135 StoredSample *samplesHead, *samplesTail;
00136 QueueItem *queueHead, *queueTail;
00137 PBState playState;
00138 PBState recState;
00139 uint32_t recDataLength;
00140 uint32_t recDataOffset;
00141 uint8_t *recData;
00142 int recDest;
00143
00144
00145
00146 virtual void Main (void);
00147 void SendStateMessage (void);
00148
00149
00150 bool AddStoredSample (StoredSample *newSample);
00151 bool AddStoredSample (player_audio_wav_t *waveData);
00152 bool AddStoredSample (const char *filePath);
00153 StoredSample* GetSampleAtIndex (int index);
00154
00155
00156 void ClearQueue (void);
00157 bool AddToQueue (QueueItem *newItem);
00158 bool AddToQueue (player_audio_wav_t *waveData);
00159 bool AddToQueue (AudioSample *sample);
00160 bool AddSilence (uint32_t time, AudioSample *format);
00161 void AdvanceQueue (void);
00162
00163
00164
00165
00166 bool SetupPlayBack (void);
00167 bool SetPBParams (AudioSample *sample);
00168 void PlaybackCallback (int numFrames);
00169
00170
00171 bool SetupRecord (void);
00172 bool SetRecParams (void);
00173 bool SetupRecordBuffer (uint32_t length);
00174 void RecordCallback (int numFrames);
00175 void HandleRecordedData (void);
00176 void PublishRecordedData (void);
00177
00178
00179 void StartPlayback (void);
00180 void StopPlayback (void);
00181 void StartRecording (void);
00182 void StopRecording (void);
00183
00184
00185 bool SetupMixer (void);
00186 bool EnumMixerElements (void);
00187 bool EnumElementCaps (MixerElement *element);
00188 MixerElement* SplitElements (MixerElement *elements, uint32_t &count);
00189 MixerElement* FilterElements (MixerElement *elements, uint32_t &count);
00190 void CleanUpMixerElements (MixerElement *elements, uint32_t count);
00191 void MixerDetailsToPlayer (player_audio_mixer_channel_list_detail_t *dest);
00192 void MixerLevelsToPlayer (player_audio_mixer_channel_list_t *dest);
00193 void SetElementLevel (uint32_t index, float level);
00194 void SetElementSwitch (uint32_t index, player_bool_t active);
00195 void PublishMixerData (void);
00196 float LevelToPlayer (long min, long max, long level);
00197 long LevelFromPlayer (long min, long max, float level);
00198 void PrintMixerElements (MixerElement *elements, uint32_t count);
00199
00200
00201 int HandleWavePlayCmd (player_audio_wav_t *waveData);
00202 int HandleSamplePlayCmd (player_audio_sample_item_t *data);
00203 int HandleRecordCmd (player_bool_t *data);
00204 int HandleMixerChannelCmd (player_audio_mixer_channel_list_t *data);
00205 int HandleSampleLoadReq (player_audio_sample_t *data, QueuePointer &resp_queue);
00206 int HandleSampleRetrieveReq (player_audio_sample_t *data, QueuePointer &resp_queue);
00207 int HandleSampleRecordReq (player_audio_sample_rec_req_t *data, QueuePointer &resp_queue);
00208 int HandleMixerChannelListReq (player_audio_mixer_channel_list_detail_t *data, QueuePointer &resp_queue);
00209 int HandleMixerChannelLevelReq (player_audio_mixer_channel_list_t *data, QueuePointer &resp_queue);
00210 };
Last updated 12 September 2005 21:38:45
|