[an error occurred while processing this directive]
Дык, а что сложного на DSP сделать? Модулятор гораздо проще демодулятора. Всего-то что надо - LUT генератор синуса с изменяемой фазой. 25 строчек на C, на асме - пару часов работы. Вот неоптимизированная версия на C
(«Телесистемы»: Конференция «Цифровые сигнальные процессоры (DSP) и их применение»)

миниатюрный аудио-видеорекордер mAVR

Отправлено AntZ 27 марта 2003 г. 12:03
В ответ на: Ответ: отправлено Витёк 27 марта 2003 г. 11:24

***************************** sine.h ***************************
int Sine128[]=
{
0, /* 0 Pi */
1608, /* 1/64 Pi */
3212, /* 2/64 Pi */
4808,
6393,
7962,
9512,
11039,
12539,
14010,
15446,
16846,
18204,
19519,
20787,
22005,
23170,
24279,
25329,
26319,
27245,
28105,
28898,
29621,
30273,
30852,
31356,
31785,
32137,
32412,
32609,
32728,
32767,
32728,
32609,
32412,
32137,
31785,
31356,
30852,
30273,
29621,
28898,
28105,
27245,
26319,
25329,
24279,
23170,
22005,
20787,
19519,
18204,
16846,
15446,
14010,
12539,
11039,
9512,
7962,
6393,
4808,
3212,
1608,
0,
-1608,
-3212,
-4808,
-6393,
-7962,
-9512,
-11039,
-12539,
-14010,
-15446,
-16846,
-18204,
-19519,
-20787,
-22005,
-23170,
-24279,
-25329,
-26319,
-27245,
-28105,
-28898,
-29621,
-30273,
-30852,
-31356,
-31785,
-32137,
-32412,
-32609,
-32728,
-32767,
-32728,
-32609,
-32412,
-32137,
-31785,
-31356,
-30852,
-30273,
-29621,
-28898,
-28105,
-27245,
-26319,
-25329,
-24279,
-23170,
-22005,
-20787,
-19519,
-18204,
-16846,
-15446,
-14010,
-12539,
-11039,
-9512,
-7962,
-6393,
-4808,
-3212,
-1608 /* 127/64 Pi */
};

***************************** sine.cpp ***************************
include
#include "sine.h"

#define LUT_SIZE 128

/* The oscillator object is described by SDigitalSineOscillator struct */
typedef struct SDigitalSineOscillator
{
unsigned int Frequency; /* reference value to calc PhaseIncrement */
unsigned int SampleRate; /* reference value to calc PhaseIncrement */
unsigned int CurrentPhase; /* current phase of sine wave*/
unsigned int PhaseIncrement; /* increment of phase between two samples */
} TDigitalSineOscillator;

/* API interface of Digital Sine Oscillator*/
int SINE_SetSampleRate(TDigitalSineOscillator *DSO, int SampleRate);
int SINE_SetFrequency (TDigitalSineOscillator *DSO, int Frequency);
int SINE_SetPhase (TDigitalSineOscillator *DSO, int Phase);
int SINE_Process (TDigitalSineOscillator *DSO, int *Buffer, int BuffSize);

int main()
{
TDigitalSineOscillator DSO; // DSO struct object
int Buffer[80]; // 80 samples of sine wave

/* prepare oscillator */
SINE_SetSampleRate(&DSO,8000); // 8kHz sampling rate
SINE_SetFrequency(&DSO,1000); // 1kHz desired oscillaring frequency
SINE_SetPhase(&DSO,0); // set 0 as initial phase

/* generate 80 samples of sine wave*/
SINE_Process(&DSO,Buffer,80); // generate 80 points (0.01 sec)

/* next line requires to place breakpoint to plot the graph*/
printf("Application completed\n");

return 0;
}

int SINE_SetSampleRate(TDigitalSineOscillator *DSO, int SampleRate)
{
DSO->SampleRate=SampleRate;
/* recalculate Phase increment */
DSO->PhaseIncrement=((long)DSO->Frequency*128*512)/DSO->SampleRate;
/* printf("Phase increment is %d\n", DSO->PhaseIncrement); */
return 0;
}

int SINE_SetFrequency(TDigitalSineOscillator *DSO, int Frequency)
{
DSO->Frequency=Frequency;
/* recalculate Phase increment */
DSO->PhaseIncrement=((long)DSO->Frequency*128*512)/DSO->SampleRate;
/* printf("Phase increment is %d\n", DSO->PhaseIncrement); */
return 0;
}

int SINE_SetPhase(TDigitalSineOscillator *DSO, int Phase)
{
DSO->CurrentPhase=Phase;
return 0;
}

int SINE_Process(TDigitalSineOscillator *DSO, int *Buffer, int BuffSize)
{
int Cnt;

for(Cnt=0; Cnt {
Buffer[Cnt]=
Sine128[(int)(((long)DSO->CurrentPhase*LUT_SIZE/65536))];
DSO->CurrentPhase += DSO->PhaseIncrement;
}
return 0;
}


Составить ответ  |||  Конференция  |||  Архив

Ответы


Отправка ответа

Имя (обязательно): 
Пароль: 
E-mail: 

Тема (обязательно):
Сообщение:

Ссылка на URL: 
Название ссылки: 

URL изображения: 


Перейти к списку ответов  |||  Конференция  |||  Архив  |||  Главная страница  |||  Содержание  |||  Без кадра

E-mail: info@telesys.ru