Forum Replies Created
-
AuthorPosts
-
VincentMember
This is how I’ve done it:
You have to create sine tables for both the pilot and 38kHz modulator.
code :#define SINE_LENGTH 192
float fPilot[SINE_LENGTH];
float fMod[SINE_LENGTH];for( int i = 0; i < SINE_LENGTH; i++ )
{
fPilot[i] = (float)sin(2 * PI * i * 19000.0f/192000.0f);
fMod[i] = (float)sin(2 * PI * i * 38000.0f/192000.0f);
}Depending on the interface you use, you should do the following in the function that is called when a new block of data is available.
In my code, a callback function is called directly from the ASIO driver. It has a pointer to both the input and output buffers and the length of the buffer.
code :static int Callback( const void *inputBuffer, void *outputBuffer,
unsigned long framesPerBuffer,
const PaStreamCallbackTimeInfo* timeInfo,
PaStreamCallbackFlags statusFlags,
void *userData )
{const float *in = (const float *) inputBuffer;
float *out = (float *) outputBuffer;float fLeft, fRight;
float fRmL, fRpL;
float fMpx;int iPhase = 0;
for( int i = 0; i < framesPerBuffer; i++ )
{fLeft = *in++;
fRight = *in++;fRmL = fRight - fLeft;
fRpL = fRight + fLeft;fMpx = (( 0.45 * fRpL ) + (0.090 * fPilot[iPhase])) + ( 0.45 * fRmL * fMod[iPhase] );
*out++ = fMpx; //left output = MPX
*out++ = fMpx;//right output = MPXif( ++iPhase == SINE_LENGTH )
{
iPhase = 0;
}}
return 0;
}Well, that was easy! Note that this is the stereo encoding part only. You have to add preemphasis, low pass filtering and clipping.
Low pass filters are easy to implement. There are a lot of programs that calculate the cofs for a IIR filter (including the filter function itself) like Winfilter. Writing the preemphasis is difficult (if you don’t understand the math).
VincentMemberThanks for the info Jesse,
The last few days I have build my own DPO using OpenGL. I have written the DPO algorithm myself using a 3 dimensional buffer with x,y,z values.
Z represents a 16 level deep brightness buffer. Each time a waveform is captured it is stored in the 3 dimensional buffer.
Each time a pixel is hit the Z value increases. A separated thread clears the Z buffers and fades out the captured waveforms.The first version used GDI with double buffering but it was way to slow! The SetPixel function was eating the CPU power.
The LineTo function could not be used in a real DPO. With OpenGL the problem was fixed.
I have set the framerate to 10mS and the CPU is only using 3% on my Pentium 3000 with 2GB RAM.VincentMemberHmm.. I can’t believe the scope is drawn by the GPU because both GDI and GDI+ does all the tricky parts by CPU (Software rendering) (antialiasing, blending, etc,etc) DirecX (Direct2d, Direct3d) and OpenGL does all the tricky stuff inside the GPU (if available). But if GDI or GDI+ does all the drawing and the drawed bitmap is BitBlit from Memory DC to the Window DC then the drawing is purely done by the CPU.
Even though the drawing takes a big amount of processing power, I’m totally surprised that GDI+ performs so well. It runs very smoothly!
Well done!
-
AuthorPosts