Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages | Examples

aibosound.h

Go to the documentation of this file.
00001 // ***************************************************************************
00002 //                           aibonet.h
00003 //
00004 //    copyright            : (C) 2003 by tbaier
00005 //    email                : tbaier@informatik.uni-hamburg.de
00006 // ***************************************************************************
00007 #ifndef AIBOSOUND_H
00008 #define AIBOSOUND_H
00009  
00010 
00011 
00012 //std includes
00013 #include <stdio.h>
00014 #include <stdlib.h>
00015 
00016 //AIBO includes
00017 #include <OPENR/ODataFormats.h>
00018 #include <OPENR/OPENRAPI.h>
00019 #include <OPENR/OSyslog.h>
00020 #include <OPENR/OObject.h>
00021 #include <Types.h>
00022 
00023 #include "WAV.h"
00024 
00026 static const char* const SPEAKER = "PRM:/r1/c1/c2/c3/s1-Speaker:S1";
00028 static const char* const MIC     = "PRM:/r1/c1/c2/c3/m1-Mic:M1";
00029 
00031 enum MIC_MODE{
00032   UNI, 
00033   OMNI 
00034 };
00035 
00037 enum WAVE_TYPE{
00038   mono8bit  = 0, 
00039   mono16bit = 3  
00040 };
00041 
00086 class AiboSound{
00087   
00088   public:
00090   AiboSound();
00091   
00093   virtual ~AiboSound(){};
00094   
00099 
00101   void OpenSpeaker();
00102 
00106   OPrimitiveID GetSpeakerID();
00107 
00111   bool IsAllRegionFree();
00112 
00114   void NewSoundVectorData();
00115 
00116 
00123   RCRegion* GetCommandVector(int index = 0);
00124   
00129   WAVError CopyWAVToRegion(RCRegion *region, int index);
00130 
00135   WAVError CopyWAVToRegion(RCRegion *region, WAV wave);
00136  
00142   WAVError CopyWAVToRegion(int regionIndex = 0, int waveIndex = 0);
00143 
00144 
00148   RCRegion* FindFreeRegion() const;
00149   
00153   int FindFreeRegionIndex() const;
00154 
00159   RCRegion* GetRegion(int index);
00160 
00165   void LoadWAV(char *sound);
00166 
00170   void RewindWAV(int index);
00171 
00172 
00176   void SetVolume(OSpeakerVolume vol);
00177 
00181   void SetMute(bool mute);
00182   
00186   void SetWaveType(int index = 0);
00187 
00191   void SetWaveType(WAVE_TYPE typ);
00192 
00197   int GetValidRegions();
00198 
00202   int GetValidWaves();
00203   
00208   WAV GetWAV(int index);
00209 
00211   void DeleteWaves();
00212 
00214 
00215   // MIC METHODS---------------------------------------------------------------
00216 
00222   
00226   void OpenMic(MIC_MODE mode=OMNI);
00227 
00231   void NewSoundBuffer(int numSeconds);
00232 
00236   void NewSoundBufferFrames(int numFrames);
00237 
00239   void ResetSoundBuffer();
00240 
00242   void DeleteSoundBuffer();
00243 
00247   void CopyToSoundBuffer(OSoundVectorData *vec);
00248 
00252   void SaveBuffer(char *file);
00253 
00257   void SetMicMode(MIC_MODE mode);
00258 
00262   void SetMicMode(OPrimitiveRequest req);
00263 
00267   void SetMicALC(bool alc);
00268 
00272   size_t GetBufferSize();
00273 
00277   size_t GetNumberOfFrames();
00278 
00280 
00281 
00282   protected:
00283 
00285   OPrimitiveID   SpeakerID;
00286   
00288   static const int MaxSoundRegions = 2;
00289 
00291   static const int MaxWaves = 10;
00292 
00294   RCRegion*       Region[MaxSoundRegions];
00295   
00297   WAV            Waves[MaxWaves];
00298   
00300   ODesignDataID  WavID[MaxWaves];
00301   
00303   int ValidWaves;
00304 
00308   static const size_t SOUND_UNIT_SIZE_8  = 256; // bytes / 32ms
00309 
00313   static const size_t SOUND_UNIT_SIZE_16  = 1024; // bytes / 32ms
00314 
00315 
00317   OPrimitiveID   MicID;
00318 
00320   byte           *SoundBuf;
00322   byte           *SoundBufPtr;
00323 
00325   size_t SoundBufSize;
00326   
00328   size_t NumberOfFrames;
00329    
00331   static const size_t SOUND_REC_SIZE16 = 2048; 
00333   static const size_t SOUND_REC_SIZE16_1SEC = 65536; 
00334   //
00335 
00337   static const size_t WAVE_HEADER_SIZE  = 4 + 8 + 16 + 8;
00339   static const size_t FMTSIZE_WITHOUT_EXTINFO = 16;
00340 
00341 };
00342 
00343 
00344 // ******************************************
00345 // **                                      **
00346 // ******************************************
00347 inline int AiboSound::GetValidRegions()
00348 {
00349   return MaxSoundRegions;
00350 };
00351 
00352 
00353 // ******************************************
00354 // **                                      **
00355 // ******************************************
00356 inline int AiboSound::GetValidWaves()
00357 {
00358   return ValidWaves;
00359 };
00360 
00361 
00362 // ******************************************
00363 // **                                      **
00364 // ******************************************
00365 inline RCRegion* AiboSound::GetCommandVector(int index)
00366 {
00367   return Region[index];
00368 };
00369 
00370 
00371 // ******************************************
00372 // **                                      **
00373 // ******************************************
00374 inline RCRegion* AiboSound::GetRegion(int index)
00375 {
00376   return Region[index];
00377 };
00378 
00379 
00380 // ******************************************
00381 // **                                      **
00382 // ******************************************
00383 inline void AiboSound::RewindWAV(int index)
00384 {
00385   Waves[index].Rewind();
00386 };
00387 
00388 
00389 // ******************************************
00390 // **                                      **
00391 // ******************************************
00392 inline WAV AiboSound::GetWAV(int index)
00393 {
00394   return Waves[index];
00395 };
00396 
00397 
00398 // MIC Methods---------------------------------------------
00399 // ******************************************
00400 // **                                      **
00401 // ******************************************
00402 inline void AiboSound::ResetSoundBuffer()
00403 {
00404    SoundBufPtr = SoundBuf; 
00405 };
00406 
00407 
00408 // ******************************************
00409 // **                                      **
00410 // ******************************************
00411 inline size_t AiboSound::GetBufferSize()
00412 {
00413   return SoundBufSize;
00414 };
00415 
00416 
00417 // ******************************************
00418 // **                                      **
00419 // ******************************************
00420 inline size_t AiboSound::GetNumberOfFrames()
00421 {
00422   return NumberOfFrames;
00423 };
00424 
00425 #endif //define AIBOSOUND_H


tams Tim Baier AiboLib v0.2.4
Generated Thu Jan 19 11:54:29 2006 by doxygen 1.4.3