audio_codec.h

説明を見る。
00001 // -*-c++-*-
00002 
00008 /*
00009  *Copyright:
00010 
00011  Copyright (C) Hidehisa AKIYAMA
00012 
00013  This code is free software; you can redistribute it and/or
00014  modify it under the terms of the GNU Lesser General Public
00015  License as published by the Free Software Foundation; either
00016  version 2.1 of the License, or (at your option) any later version.
00017 
00018  This library is distributed in the hope that it will be useful,
00019  but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00021  Lesser General Public License for more details.
00022 
00023  You should have received a copy of the GNU Lesser General Public
00024  License along with this library; if not, write to the Free Software
00025  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026 
00027  *EndCopyright:
00028  */
00029 
00031 
00032 #ifndef RCSC_PLAYER_AUDIO_CODEC_H
00033 #define RCSC_PLAYER_AUDIO_CODEC_H
00034 
00035 #include <rcsc/geom/vector_2d.h>
00036 
00037 #include <boost/cstdint.hpp>
00038 #include <map>
00039 #include <vector>
00040 #include <string>
00041 #include <cmath>
00042 
00043 namespace rcsc {
00044 
00049 class AudioCodec {
00050 public:
00051     typedef std::map< char, int > CharToIntCont;
00052     typedef std::vector< char > IntToCharCont;
00053 
00055     static const double ERROR_VALUE;
00056 
00058     static const double X_NORM_FACTOR;
00060     static const double Y_NORM_FACTOR;
00062     static const double SPEED_NORM_FACTOR;
00063 
00065     static const double COORD_STEP_L2;
00067     static const double SPEED_STEP_L1;
00068 
00069     enum BitMask {
00070         MASK_1 = 0x00000001,
00071         MASK_2 = 0x00000003,
00072         MASK_3 = 0x00000007,
00073         MASK_4 = 0x0000000F,
00074         MASK_5 = 0x0000001F,
00075         MASK_6 = 0x0000003F,
00076         MASK_7 = 0x0000007F,
00077         MASK_8 = 0x000000FF,
00078         MASK_9 = 0x000001FF,
00079         MASK_10 = 0x000003FF,
00080         MASK_11 = 0x000007FF,
00081         MASK_12 = 0x00000FFF,
00082         MASK_13 = 0x00001FFF,
00083         MASK_14 = 0x00003FFF,
00084         MASK_15 = 0x00007FFF,
00085         MASK_16 = 0x0000FFFF,
00086         MASK_17 = 0x0001FFFF,
00087         MASK_18 = 0x0003FFFF,
00088         MASK_19 = 0x0007FFFF,
00089         MASK_20 = 0x000FFFFF,
00090         MASK_21 = 0x001FFFFF,
00091         MASK_22 = 0x003FFFFF,
00092         MASK_23 = 0x007FFFFF,
00093         MASK_24 = 0x00FFFFFF,
00094         MASK_25 = 0x01FFFFFF,
00095         MASK_26 = 0x03FFFFFF,
00096         MASK_27 = 0x07FFFFFF,
00097         MASK_28 = 0x0FFFFFFF,
00098         MASK_29 = 0x1FFFFFFF,
00099         MASK_30 = 0x3FFFFFFF,
00100         MASK_31 = 0x7FFFFFFF,
00101         MASK_32 = 0xFFFFFFFF,
00102     };
00103 
00104 private:
00105 
00107     CharToIntCont M_char_to_int_map;
00108 
00110     IntToCharCont M_int_to_char_map;
00111 
00112 public:
00113 
00114     static const std::string CHAR_SET; 
00115     static const int CHAR_SIZE; 
00116 
00117 private:
00121     AudioCodec();
00122 
00123 public:
00124 
00129     static
00130     const
00131     AudioCodec & i();
00132 
00133 private:
00134 
00140     boost::int32_t posToBit18( const Vector2D & pos ) const;
00141 
00147     void bit18ToPos( const boost::int32_t & val,
00148                      Vector2D * pos ) const;
00149 
00155     boost::int32_t posToBit19( const Vector2D & pos ) const;
00156 
00162     void bit19ToPos( const boost::int32_t & val,
00163                      Vector2D * pos ) const;
00164 
00171     boost::int32_t posVelToBit31( const Vector2D & pos,
00172                                   const Vector2D & vel ) const;
00173 
00180     void bit31ToPosVel( const boost::int32_t & val,
00181                         Vector2D * pos,
00182                         Vector2D * vel ) const;
00183 
00184 public:
00185 
00190     const
00191     CharToIntCont & charToIntMap() const
00192       {
00193           return M_char_to_int_map;
00194       }
00195 
00200     const
00201     IntToCharCont & intToCharMap() const
00202       {
00203           return M_int_to_char_map;
00204       }
00205 
00213     bool encodeInt64ToStr( const boost::int64_t & ival,
00214                            const int len,
00215                            std::string & to ) const;
00216 
00223     bool decodeStrToInt64( const std::string & from,
00224                            boost::int64_t * to ) const;
00225 
00226 
00233     char encodePercentageToChar( const double & value ) const;
00234 
00241     double decodeCharToPercentage( const char ch ) const;
00242 
00252     bool encodePosVelToStr5( const Vector2D & pos,
00253                              const Vector2D & vel,
00254                              std::string & to ) const;
00255 
00265     bool decodeStr5ToPosVel( const std::string & from,
00266                              Vector2D * pos,
00267                              Vector2D * vel ) const;
00268 
00277     bool encodePosToStr3( const Vector2D & pos,
00278                           std::string & to ) const;
00279 
00288     bool decodeStr3ToPos( const std::string & from,
00289                           Vector2D * pos ) const;
00290 
00291 
00301     bool encodeUnumPosToStr4( const int unum,
00302                               const Vector2D & pos,
00303                               std::string & to ) const;
00304 
00314     bool decodeStr4ToUnumPos( const std::string & from,
00315                               int * unum,
00316                               Vector2D * pos ) const;
00317 
00332     std::string encodeCoordToStr2( const double & xy,
00333                                    const double & norm_factor ) const;
00334 
00345     double decodeStr2ToCoord( const char ch1,
00346                               const char ch2,
00347                               const double & norm_factor ) const;
00348 
00355     std::string encodePosToStr4( const Vector2D & pos ) const;
00356 
00362     Vector2D decodeStr4ToPos( const std::string & from ) const;
00363 
00371     char encodeSpeedToChar( const double & xy ) const;
00372 
00378     double decodeCharToSpeed( const char ch ) const;
00379 
00385     static
00386     char unum2hex( const int unum );
00387 
00388 
00394     static
00395     int hex2unum( const char hex );
00396 };
00397 
00398 }
00399 
00400 #endif

librcscに対してThu May 1 15:41:20 2008に生成されました。  doxygen 1.5.0