Good catch!infiniteimprobability wrote:Looks like you are sending an int over but pwm is expecting a short..
regards
Al
Good catch!infiniteimprobability wrote:Looks like you are sending an int over but pwm is expecting a short..
Code: Select all
#include <platform.h>
#include <xs1.h>
#include "pwm.h"
#define SAMPLE_RATE 44100
port audio = XS1_PORT_1A;
long A=0x7e66;
long buf[3]={0,0x1209,0};
int val;
void sine (chanend pwm){
buf[ 0 ] = ((A * buf[ 1 ]) >> 14 ) - buf[ 2 ];
buf[ 2 ] = buf[ 1 ];
buf[ 1 ] = buf[ 0 ];
val = 32768 + buf[ 0 ];
pwm <: val;
delay_microseconds (10);
}
int main ( void )
{
chan pwm;
par {
sine(pwm);
pwm_server(pwm, audio, SAMPLE_RATE);
}
return 0;
}
Code: Select all
void sine (chanend pwm){
while(1){
buf[ 0 ] = ((A * buf[ 1 ]) >> 14 ) - buf[ 2 ];
buf[ 2 ] = buf[ 1 ];
buf[ 1 ] = buf[ 0 ];
val = 32768 + buf[ 0 ];
pwm <: val;
delay_microseconds (10);
}
}