00001
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
00032 unsigned int hi = ( this->phase >> 24 ) & 0xFF;
00033 unsigned int lo = ( this->phase >> 16 ) & 0xFF;
00034 #if 0
00035
00036 i[j] = co_h[hi]*co_l[lo] - si_h[hi]*si_l[lo];
00037
00038 q[j] = si_h[hi]*co_l[lo] + co_h[hi]*si_l[lo];
00039 #else
00040
00041 asm( "a0 = %2*%3;\n"
00042 "%0=(a0-=%4*%5);\n"
00043 "a0 = %4*%3;\n"
00044 "%1=(a0+=%2*%5);\n"
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
00059 unsigned int hi = ( this->phase >> 24 ) & 0xFF;
00060 unsigned int lo = ( this->phase >> 16 ) & 0xFF;
00061
00062
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
00084 unsigned int hi = ( this->phase >> 24 ) & 0xFF;
00085 unsigned int lo = ( this->phase >> 16 ) & 0xFF;
00086
00087
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