Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

Platform/Aperios1.3.2/SoundDataSender.cpp

Go to the documentation of this file.
00001 /**
00002  * @file Platform/Aperios1.3.2/SoundDataSender.cpp
00003  * This file contains the implementation of a sender for sound data.
00004  */
00005 
00006 #include "ProcessFramework.h"
00007 
00008 SoundDataSender::SoundDataSender(PlatformProcess* process,bool blocking)
00009 : SenderBase<SoundData>(process,"Sender.OSoundVectorData.S",blocking)
00010 {
00011   package[0] = 0;
00012 
00013   OPrimitiveID soundId;
00014   VERIFY(OPENR::OpenPrimitive(SystemCall::getRobotDesign() == RobotDesign::ERS210 
00015                               ? "PRM:/r1/c1/c2/c3/s1-Speaker:S1"
00016                               : "PRM:/s1-Speaker:S1",&soundId) == oSUCCESS);
00017   OSpeakerSoundType type = ospksndMONO8K8B;
00018   VERIFY(OPENR::ControlPrimitive(soundId,oprmreqSPEAKER_SET_SOUND_TYPE,&type,sizeof(type),0,0) == oSUCCESS);
00019   int vol = SystemCall::getRobotDesign() == RobotDesign::ERS210 ? 0xf400 : 0xf600;
00020   VERIFY(OPENR::ControlPrimitive(soundId,oprmreqSPEAKER_SET_VOLUME,&vol,sizeof(vol),0,0) == oSUCCESS);
00021 
00022   for(int i = 0; i < 2; ++i)
00023   {
00024     VERIFY(OPENR::NewSoundVectorData(1, 256, &memID[i], &soundVec[i]) == oSUCCESS);
00025     soundVec[i]->SetNumData(1);
00026     OSoundInfo* info = soundVec[i]->GetInfo(0);
00027     info->Set(odataSOUND_VECTOR,soundId,info->maxDataSize);
00028   }
00029 }
00030 
00031 SoundDataSender::~SoundDataSender()
00032 {
00033   for(int i = 0; i < 2; ++i)
00034     VERIFY(OPENR::DeleteSoundVectorData(memID[i]) == oSUCCESS);
00035 }
00036 
00037 void SoundDataSender::prepare(int i)
00038 {
00039   const SoundData& soundData = *static_cast<const SoundData*>(this);
00040   OSoundInfo* info = soundVec[i]->GetInfo(0);
00041   info->dataSize = info->frameSize;
00042   info->samplingRate  = 8000;
00043   info->bitsPerSample = 8;
00044   memcpy(soundVec[i]->GetData(0),soundData.pcmBuffer,256);
00045 }
00046 
00047 void SoundDataSender::preparePackage()
00048 {
00049   if(!package[0])
00050   {
00051     for(int i = 0; i < 2; ++i)
00052     {
00053       VERIFY(package[i] = new RCRegion(soundVec[i]->vectorInfo.memRegionID,
00054                                        soundVec[i]->vectorInfo.offset,
00055                                        (void*) soundVec[i],
00056                                        soundVec[i]->vectorInfo.totalSize));
00057       prepare(i);
00058     }
00059     index = -1;
00060   }
00061   else
00062     prepare(index);
00063 }
00064 
00065 void SoundDataSender::setPackage(const ObserverID& receiver)
00066 {
00067   for(int l = 0; l < 2; l++)
00068   {
00069     if (package[l]->NumberOfReference() == 1)
00070     {
00071       VERIFY(SetData(receiver,package[l]) == oSUCCESS);
00072     }
00073   }
00074 }
00075 
00076 /** @todo packages are not freed */
00077 void SoundDataSender::freePackage()
00078 {
00079   if(index == -1)
00080     index = 0;
00081   else
00082     index = 1 - index;
00083 }
00084 
00085 /*
00086  * Change log :
00087  * 
00088  * $Log: SoundDataSender.cpp,v $
00089  * Revision 1.1.1.1  2004/05/22 17:23:40  cvsadm
00090  * created new repository GT2004_WM
00091  *
00092  * Revision 1.2  2003/12/31 18:14:45  roefer
00093  * Sound for ERS-7
00094  *
00095  * Revision 1.1  2003/10/07 10:06:59  cvsadm
00096  * Created GT2004 (M.J.)
00097  *
00098  * Revision 1.1.1.1  2003/07/02 09:40:24  cvsadm
00099  * created new repository for the competitions in Padova from the 
00100  * tamara CVS (Tuesday 2:00 pm)
00101  *
00102  * removed unused solutions
00103  *
00104  * Revision 1.3  2002/12/02 11:00:13  dueffert
00105  * doxygen docu corrected
00106  *
00107  * Revision 1.2  2002/11/28 14:46:17  dueffert
00108  * doxygen docu corrected
00109  *
00110  * Revision 1.1  2002/11/28 14:22:01  hebbel
00111  * added SoundDataSender
00112  *
00113  * Revision 1.3  2002/08/26 21:04:26  hebbel
00114  * Changed method setPackage() to support double-buffering
00115  *
00116  * Revision 1.2  2002/08/14 17:11:00  dueffert
00117  * adapted by Thomas Roefer to OPENR_SDK-1.1.3-r1 and OPENR_SYS-007
00118  *
00119  * Revision 1.1  2002/07/13 10:54:58  roefer
00120  * New command and sound sender
00121  *
00122  *
00123  *
00124  */

Generated on Thu Sep 23 19:57:34 2004 for GT2004 by doxygen 1.3.6