osc.cpp

説明を見る。
00001 /** \file
00002 * 発振器クラスの定義 
00003 */
00004 
00005 #include "osc.h"
00006 namespace osc{
00007         // すべての発振器クラスが共用するコンストラクタ
00008     COscillator::COscillator( int freq )
00009     {
00010         this->setFreq( freq );
00011         this->setPhase( 0 );
00012     }
00013     
00014         // すべての発振器クラスが共用する周波数設定プログラム
00015     void COscillator::setFreq( int freq )
00016     {
00017         this->frequency = freq;
00018     }
00019     
00020         // すべての発振器クラスが共用する位相設定プログラム 
00021     void COscillator::setPhase( unsigned int phase )
00022     {
00023         this->phase = phase;
00024     }
00025 
00026 
00027 
00028     void CTableLookup::run( shortfract i[], shortfract q[], int count )
00029     {
00030         for ( int j=0; j<count; j++ ){
00031                 // 32bitの位相の内、上位16bitのみを使う。
00032             unsigned int hi = ( this->phase >> 24 ) & 0xFF;     // 16bit位相の上位8bit
00033             unsigned int lo = ( this->phase >> 16 ) & 0xFF;     //  8bit位相の下位8bit
00034 #if 0       
00035                 // 加法定理 cos(A+B) = cos(A)cos(B) - sin(A)sin(B)
00036             i[j] = co_h[hi]*co_l[lo] - si_h[hi]*si_l[lo];
00037                 // 加法定理 sin(A+B) = sin(A)cos(B) + cos(A)sin(B)
00038             q[j] = si_h[hi]*co_l[lo] + co_h[hi]*si_l[lo];
00039 #else           
00040                     // アセンブリ言語による実装
00041             asm(    "a0 = %2*%3;\n"         // cos_h*cos_l
00042                     "%0=(a0-=%4*%5);\n"     // sin_h*sin_l
00043                     "a0 = %4*%3;\n"         // sin_h*cos_l
00044                     "%1=(a0+=%2*%5);\n"     // cos_h*sin_l
00045                     : "=&l"(i[j].v), "=&l"(q[j].v)
00046                     : "l"(co_h[hi].v), "l"(co_l[lo].v), "l"(si_h[hi].v), "l"(si_l[lo].v)
00047                     : "a0"
00048                     );  
00049 #endif  
00050                 // 位相の更新
00051             this->phase += this->frequency;
00052         }
00053     }
00054 
00055     void CTableLookup::run( shortfract i[], int count )
00056     {
00057         for ( int j=0; j<count; j++ ){
00058                 // 32bitの位相の内、上位16bitのみを使う。
00059             unsigned int hi = ( this->phase >> 24 ) & 0xFF;     // 16bit位相の上位8bit
00060             unsigned int lo = ( this->phase >> 16 ) & 0xFF;     //  8bit位相の下位8bit
00061             
00062                 // 加法定理 cos(A+B) = cos(A)cos(B) - sin(A)sin(B)
00063 #if 0
00064             i[j] = co_h[hi]*co_l[lo] - si_h[hi]*si_l[lo];
00065 #else
00066                     // アセンブリ言語による実装
00067             asm(    "a0 = %1*%2;\n" 
00068                     "%0=(a0-=%3*%4);\n" 
00069                     : "=l"(i[j].v)
00070                     : "l"(co_h[hi].v), "l"(co_l[lo].v), "l"(si_h[hi].v), "l"(si_l[lo].v)
00071                     : "a0"
00072                     );      
00073 #endif  
00074                 // 位相の更新
00075             this->phase += this->frequency;
00076 
00077         }
00078     }
00079 
00080     void CTableLookup::run( shortfract i[], int deviation[], int count )
00081     {
00082         for ( int j=0; j<count; j++ ){
00083                 // 32bitの位相の内、上位16bitのみを使う。
00084             unsigned int hi = ( this->phase >> 24 ) & 0xFF;     // 16bit位相の上位8bit
00085             unsigned int lo = ( this->phase >> 16 ) & 0xFF;     //  8bit位相の下位8bit
00086             
00087                 // 加法定理 cos(A+B) = cos(A)cos(B) - sin(A)sin(B)
00088                     // アセンブリ言語による実装
00089             asm(    "a0 = %1*%2;\n" 
00090                     "%0=(a0-=%3*%4);\n" 
00091                     : "=l"(i[j].v)
00092                     : "l"(co_h[hi].v), "l"(co_l[lo].v), "l"(si_h[hi].v), "l"(si_l[lo].v)
00093                     : "a0"
00094                     );      
00095                 // 位相の更新
00096             this->phase += this->frequency + deviation[j];
00097 
00098         }
00099     }
00100 };
00101 

Overflowに対してSat Jul 14 16:32:32 2007に生成されました。  doxygen 1.5.2