[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[Fwd: Program only runs when esd is unnice]



A student of mine came up with this one.  Can anybody see what's wrong
with it (I can't!)

When playing a sinewave through esd on a PowerPC Debian System (A Mac
G4), the output is interrupted at random intervals.  If esd is run "nice
--5 esd" as root, the system will just about play uninterrupted.

I am a bit suprised at this because the very old P200 in my office has
only slight problems with exactly the same code.  Is there some
fundamental problem with the scheduler here?  I'd've really expected a
machine with a processor like the G4 to keep up with 44k1 16-bit mono.
Does anyone have any comments here (sorry if it's bad form sending
source to the list: it's only short!)

Nick/


--- Begin Message ---
The following source runs fine on a (very old) i386 box, but won't work
without interruptions in the sound generated on the Mac G4s in the Music
Technology lab.  Can you see what is going on?

Greg.


#include <esd.h>
#include "sine.h"
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <linux/soundcard.h>

int main()
{
  int count;
  int out_sock;
  int play_format = ESD_MONO | ESD_BITS16 | ESD_STREAM | ESD_PLAY;
  short table[88200];
  short *cycle;

  gen(table);
 
  
  /* tries to use esd uses /dev/dsp if necessary*/
  
  out_sock = esd_play_stream_fallback(play_format,
				      44100,
				      NULL,
				      "sinewave ");
  if (out_sock <= 0)
    {
      fprintf(stderr,"oh dear, its broken");
    } 
  else 
    {

	  printf("%d\n",write(out_sock, table ,88200*sizeof(short) ));
    }
  close (out_sock);
}
void gen(short *cycle);
#include <stdio.h>
#include <math.h>

void gen(short *cycle)
     
{
  int count;
  double wave;
  
  for(count=0;count<88200;count++)  
    {
      wave = sin(fmod((count*M_PI)/50,(2*M_PI)));
      *cycle=30000*(wave);
      /* printf (" %i\n  ",*cycle)*/;
      cycle++;
    }
}

--- End Message ---

Reply to: