NESDev and Strangulation Records messageboards
Forum Index | FAQ | New User | Login | Search

Previous ThreadView All ThreadsNext ThreadShow in Flat Mode*


SubjectRe: Sound Question  
Posted byDisch
Posted on7/29/03 9:03 PM
From IP66.127.105.177  



It seems like it would be tricky. I'm in the area of making NSF players... not full emus... so I don't have to deal with as precise of timing as you might have to.

All I can say is you definatly -SHOULDN'T- round off to the nearest whole number... as that will throw notes off key (especially notes with lower wavelengths)

Anyway... how I have my player running... is I keep track of how many cycles are needed per sample (as a floating point variable). Then I keep another floating point var as a sort of counter. The counter is decreased by the number of CPU cycles executed... when the counter goes under 0, a new sample is generated, and the counter is incrimented by the CyclesPerSample variable.

Hard to explain... so here's sample code as a description... hope you know C/C++

---------------------------


float fTicksPerSample; //number of cpu cycles between generated samples (40.5844)
float fSampleCounter = fTicksPerSample; //the counter

void DoAPUTicks( int ticks ) //ticks is the number of cycles to do
{
  int doticks;

  while(ticks > 0)
  {
    // make it so we only do one sample at a time
    doticks = (int)fSampleCounter + 1;
    if(doticks > ticks) doticks = ticks;

    // in my player, I clock other stuff here, like the frame counter


    // here... clock all the sound channels 'doticks' cycles

    fSampleCounter -= ticks;
    if(fSampleCounter <= 0)
    {
      fSampleCounter += fTicksPerSample;
      //add another sample to the sound buffer
    }
  }
}



---------------------------

hope that kind of makes sense. That's similar to how I do it and it's peachy. If you round off though, it WILL go off key... I tried it before.



-
Entire Thread
Subject  Posted byPosted On
*Sound Question  Laughy7/29/03 6:16 PM
.*Re: Sound Question  Laughy7/29/03 8:36 PM
..*Re: Sound Question  Disch7/29/03 9:09 PM
..*Re: Sound Question  Laughy7/29/03 8:55 PM
.*Re: Sound Question  Disch7/29/03 7:28 PM
..*Re: Sound Question  Laughy7/29/03 8:11 PM
....Re: Sound Question  Disch7/29/03 9:03 PM
....*Re: Sound Question  Disch7/29/03 9:05 PM
.....*Re: Sound Question  Laughy7/29/03 10:28 PM
......*Re: Sound Question  Disch7/30/03 00:05 AM
.......*Re: Sound Question  Laughy7/30/03 00:16 AM
........*Re: Sound Question  Laughy7/30/03 00:41 AM
.........*Re: Sound Question  Disch7/30/03 01:48 AM
Jump to

Memblers' homepage             Contact Me

Forums powered by WWWThreads Demo