// Sample.c
// 04/02/05

#include "Sample.h"
#include "NokiaLCD.h"

#define NB_SAMPLES 72 // Nb samples

UInt8 SamplesA [NB_SAMPLES];
UInt8 SamplesB [NB_SAMPLES];
UInt8 IndexSamples;
void InitSamples () {
  UInt8 i;
  IndexSamples=0;
  for (i=0; i < NB_SAMPLES; ++i) {
    SamplesA[i]=0xFF;
    SamplesB[i]=0xFF;
  }
}

void AddSample (UInt8 aSampleA, UInt8 aSampleB) {
  //printf ("AddSample (%d)\n", aSample);

  SamplesA [IndexSamples]=aSampleA;
  SamplesB [IndexSamples]=aSampleB;
  IndexSamples++;
  if (IndexSamples >=NB_SAMPLES) IndexSamples=0;
}

UInt8 GetSampleA (UInt8 aIndex) {
  UInt8 local;
  local = aIndex+IndexSamples;
  
  if (local>= NB_SAMPLES) local-=NB_SAMPLES;
  // printf ("GetSample (%d) => %d\n",aIndex, Samples[local]);
  return SamplesA[local];
}

UInt8 GetSampleB (UInt8 aIndex) {
  UInt8 local;
  local = aIndex+IndexSamples;
  
  if (local>= NB_SAMPLES) local-=NB_SAMPLES;
  // printf ("GetSample (%d) => %d\n",aIndex, Samples[local]);
  return SamplesB[local];
}

void DrawSamples () {
  UInt8 i, j, sample;

  for (j=0;j<5;j++) {
    LcdGotoXY ( 2, j );
    for (i=0;i<12;i++) LcdChr ( FONT_1X, '(');
  }
  
  // Draw the samples
  for (i=0; i<NB_SAMPLES; i++) {
    sample=GetSampleA(i);
    if (sample != 0xFF) LcdPixel( i+12, sample, PIXEL_ON );
    sample=GetSampleB(i);
    if (sample != 0xFF) LcdPixel( i+12, sample, PIXEL_ON );
  }
}

// End of file
