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 }