Update of /cvsroot/playerstage/code/player/server/drivers/audio
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12945/server/drivers/audio

Modified Files:
        alsa.cc alsa.h 
Log Message:
Add documentation and sample support to the ALSA driver, making it far more 
useful. 

Index: alsa.h
===================================================================
RCS file: /cvsroot/playerstage/code/player/server/drivers/audio/alsa.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** alsa.h      4 Jun 2006 23:48:19 -0000       1.2
--- alsa.h      10 Jun 2006 08:03:09 -0000      1.3
***************
*** 24,27 ****
--- 24,59 ----
  
  
////////////////////////////////////////////////////////////////////////////////
+ // Detailed description of wave data
+ // This is more advanced than the player wave data structure: it can store
+ // actual sample rate values, etc, making it more flexible and so useful for
+ // locally loaded wave data
+ typedef struct WaveData
+ {
+       uint16_t numChannels;   // Number of channels in the data
+       uint32_t sampleRate;    // Number of samples per second
+       uint32_t byteRate;              // Number of bytes per second
+       uint16_t blockAlign;    // Number of bytes for one sample over all 
channels (i.e. frame size)
+       uint16_t bitsPerSample; // Number of bits per sample (eg 8, 16, 24, ...)
+       uint32_t numFrames;             // Number of frames (divide by 
sampleRate to get time)
+       uint32_t dataLength;    // Length of data in bytes
+       uint8_t *data;
+ } WaveData;
+ 
+ 
////////////////////////////////////////////////////////////////////////////////
+ // Describes an audio sample
+ typedef int SampleType;
+ const SampleType SAMPLE_TYPE_LOCAL = 0;               // Local samples are 
stored in a file
+ const SampleType SAMPLE_TYPE_REMOTE = 1;      // Remote samples are stored in 
memory
+ 
+ typedef struct AudioSample
+ {
+       SampleType type;                        // Type of sample - local file 
or stored in memory
+       char *localPath;                        // Path to local file if local
+       WaveData *memData;                      // Stored audio data if sample 
is memory
+       int index;                                      // Index of sample
+       struct AudioSample *next;       // Next sample in the linked list
+ } AudioSample;
+ 
+ 
////////////////////////////////////////////////////////////////////////////////
  // The class for the driver
  class Alsa : public Driver
***************
*** 37,55 ****
  
        private:
-               virtual void Main (void);
- 
-               // Command handling
-               int HandleWavePlayCmd (player_audio_wav_t *waveData);
- 
                // Driver options
                bool block;                                             // If 
should block while playing or return immediatly
!               unsigned int pbRate;                    // Sample rate for 
playback
!               int pbNumChannels;                              // Number of 
sound channels for playback
!               snd_pcm_uframes_t periodSize;   // Period size of the output 
buffer
  
                // ALSA variables
                snd_pcm_t *pcmHandle;                   // Handle to the PCM 
device
                snd_pcm_stream_t pbStream;              // Stream for playback
-               snd_pcm_hw_params_t *hwparams;  // Hardware parameters
                char *pcmName;                                  // Name of the 
sound interface
  };
--- 69,105 ----
  
        private:
                // Driver options
                bool block;                                             // If 
should block while playing or return immediatly
! //            uint32_t pbRate;                                // Sample rate 
for playback
! //            int pbNumChannels;                              // Number of 
sound channels for playback
!               AudioSample *samplesHead, *samplesTail; // Stored samples
  
                // ALSA variables
                snd_pcm_t *pcmHandle;                   // Handle to the PCM 
device
                snd_pcm_stream_t pbStream;              // Stream for playback
                char *pcmName;                                  // Name of the 
sound interface
+ 
+               // Other driver data
+               int nextSampleIdx;                              // Next free 
index to store a sample at
+ 
+               // Command and request handling
+               int HandleWavePlayCmd (player_audio_wav_t *waveData);
+               int HandleSamplePlayCmd (player_audio_sample_item_t *data);
+               int HandleSampleLoadReq (player_audio_sample_t *data, 
MessageQueue *resp_queue);
+               int HandleSampleRetrieveReq (player_audio_sample_t *data, 
MessageQueue *resp_queue);
+ 
+               // Internal functions
+               virtual void Main (void);
+               bool AddSample (AudioSample *newSample);
+               bool AddFileSample (const char *path);
+               bool AddMemorySample (player_audio_wav_t *sampleData);
+               AudioSample* GetSampleAtIndex (int index);
+               WaveData* LoadWaveFromFile (char *fileName);
+               bool WaveDataToPlayer (WaveData *source, player_audio_wav_t 
*dest);
+               bool PlayerToWaveData (player_audio_wav_t *source, WaveData 
*dest);
+               void PrintWaveData (WaveData *wave);
+ 
+               // Sound functions
+               bool SetHWParams (WaveData *wave);
+               bool PlayWave (WaveData *wave);
  };

Index: alsa.cc
===================================================================
RCS file: /cvsroot/playerstage/code/player/server/drivers/audio/alsa.cc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** alsa.cc     4 Jun 2006 23:48:19 -0000       1.2
--- alsa.cc     10 Jun 2006 08:03:09 -0000      1.3
***************
*** 25,32 ****
--- 25,108 ----
   */
  
+ /** @ingroup drivers */
+ /** @{ */
+ /** @defgroup driver_alsa alsa
+  * @brief Linux ALSA sound system driver
+ 
+ This driver provides access to sound playing and recording functionality 
through
+ the Advanced linux Sound Architecture (ALSA) system available on 2.6 series
[...1175 lines suppressed...]
        {
                HandleWavePlayCmd (reinterpret_cast<player_audio_wav_t*> 
(data));
                return 0;
        }
+       else if (Message::MatchMessage (hdr, PLAYER_MSGTYPE_CMD, 
PLAYER_AUDIO_SAMPLE_PLAY_CMD, this->device_addr))
+       {
+               HandleSamplePlayCmd 
(reinterpret_cast<player_audio_sample_item_t*> (data));
+               return 0;
+       }
+       // Requests
+       else if (Message::MatchMessage (hdr, PLAYER_MSGTYPE_REQ, 
PLAYER_AUDIO_SAMPLE_LOAD_REQ, this->device_addr))
+       {
+               return HandleSampleLoadReq 
(reinterpret_cast<player_audio_sample_t*> (data), resp_queue);
+       }
+       else if (Message::MatchMessage (hdr, PLAYER_MSGTYPE_REQ, 
PLAYER_AUDIO_SAMPLE_RETRIEVE_REQ, this->device_addr))
+       {
+               return HandleSampleRetrieveReq 
(reinterpret_cast<player_audio_sample_t*> (data), resp_queue);
+       }
  
        return -1;



_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to