changeset 101:04f894424a8c

Merge
author Giulio Moro <giuliomoro@yahoo.it>
date Mon, 27 Jul 2015 12:46:55 +0100
parents b697e82ebb25 (diff) c529505203ee (current diff)
children 31ca45939a0c
files
diffstat 6 files changed, 162 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/core/I2c_Codec.cpp	Thu Jul 23 23:32:47 2015 +0100
+++ b/core/I2c_Codec.cpp	Mon Jul 27 12:46:55 2015 +0100
@@ -117,6 +117,44 @@
 	return 0;
 }
 
+//set the numerator multiplier for the PLL
+int I2c_Codec::setPllK(float k){
+	short unsigned int j=(int)k;
+	unsigned int d=(k-j+0.5)*10000; //fractionary part, between 0 and 9999
+	if(setPllJ(j)>0)
+		return 1;
+	if(setPllD(d)>0)
+		return 2;
+	return 0;
+}
+
+
+//set integer part of the numerator mutliplier of the PLL
+int I2c_Codec::setPllJ(short unsigned int j){
+	if(j>=64 || j<1){
+			return 1;
+	}
+	if(writeRegister(0x04, j<<2)){	// PLL register B: j<<2
+		printf("I2C error while writing PLL j: %d", j);
+		return 1;
+	}
+	return 0;
+}
+
+//set fractional part(between 0 and 9999) of the numerator mutliplier of the PLL
+int I2c_Codec::setPllD(unsigned int d){
+	if(d<0 || d>9999)
+		return 1;
+	if(writeRegister(0x05, (d>>6)&255)){ // PLL register C: part 1 : 8 most significant bytes of a 14bit integer
+		printf("I2C error while writing PLL d part 1 : %d", d);
+		return 1;
+	}
+	if(writeRegister(0x06, (d<<2)&255)){	// PLL register D: D=5264, part 2
+		printf("I2C error while writing PLL d part 2 : %d", d);
+		return 1;
+	}
+	return 0;
+}
 // Set the volume of the DAC output
 int I2c_Codec::setDACVolume(int halfDbSteps)
 {
--- a/include/I2c_Codec.h	Thu Jul 23 23:32:47 2015 +0100
+++ b/include/I2c_Codec.h	Mon Jul 27 12:46:55 2015 +0100
@@ -28,6 +28,9 @@
 	int startAudio(int dual_rate);
 	int stopAudio();
 
+	int setPllJ(short unsigned int j);
+	int setPllD(unsigned int d);
+	int setPllK(float k);
 	int setDACVolume(int halfDbSteps);
 	int writeDACVolumeRegisters(bool mute);
 	int setADCVolume(int halfDbSteps);
--- a/include/pru_rtaudio_bin.h	Thu Jul 23 23:32:47 2015 +0100
+++ b/include/pru_rtaudio_bin.h	Mon Jul 27 12:46:55 2015 +0100
@@ -630,7 +630,8 @@
      0x79000002,
      0x0b10eee7,
      0xf1c03d82,
-     0xcf05e2ff,
+     0xd500e29d,
+     0xcf05e2fe,
      0x10e7e7fb,
      0x240208fc,
      0x00fcfdfc,
@@ -751,13 +752,13 @@
      0x0104f3f3,
      0x1504f8f8,
      0x0101e1e1,
-     0x6ee9e178,
+     0x6ee9e177,
      0x79000004,
      0x1504f8f8,
      0x0102e1e1,
-     0x6ee9e174,
+     0x6ee9e173,
      0x0101eaea,
-     0x6eebea71,
+     0x6eebea70,
      0x10f0f0e2,
      0x10f1f1f0,
      0x10e2e2f1,
@@ -786,7 +787,7 @@
      0x00e1e3e3,
      0xe1002382,
      0xf1003982,
-     0x5700e244,
+     0x5700e243,
      0x240000fb,
      0xe1443d9b,
      0xc901f80c,
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/projects/bucket_brigade_chorus/render.cpp	Mon Jul 27 12:46:55 2015 +0100
@@ -0,0 +1,112 @@
+#include <BeagleRT.h> 
+#include <Scope.h>
+#include <cmath>
+#include <Utilities.h>
+
+float gPhase1, gPhase2;
+float gFrequency1, gFrequency2;
+float gInverseSampleRate;
+
+Scope scope;    //create a scope object
+
+// initialise_render() is called once before the audio rendering starts.
+// Use it to perform any initialisation and allocation which is dependent
+// on the period size or sample rate.
+//
+// userData holds an opaque pointer to a data structure that was passed
+// in from the call to initAudio().
+//
+// Return true on success; returning false halts the program.
+#include <I2c_Codec.h>
+#include <PRU.h>
+extern I2c_Codec *gAudioCodec;
+extern PRU *gPRU;
+float D=5264;
+#define delayLength 512
+float delay[delayLength];
+int writePointer=0;
+int readPointer=writePointer+1;
+AuxiliaryTask updatePll;
+
+void updatePllFunction(){
+//	rt_printf("now\n");
+	gPRU->setGPIOTestPin();
+	gAudioCodec->setPllD(D);
+	gPRU->clearGPIOTestPin();
+}
+
+bool setup(BeagleRTContext *context, void *userData)
+{
+	scope.setup(context->audioSampleRate);  //call this once in setup to initialise the scope
+	 
+	gInverseSampleRate = 1.0/context->audioSampleRate;
+	
+	gPhase1 = 0.0;
+	gPhase2 = 0.0;
+	
+	gFrequency1 = 200.0;
+	gFrequency2 = 201.0;
+	updatePll=BeagleRT_createAuxiliaryTask(&updatePllFunction, 98, "update PLL");
+	for(int n=0; n<delayLength; n++){
+		delay[n]=0;
+	}
+	return true; 
+}
+
+// render() is called regularly at the highest priority by the audio engine.
+// Input and output are given from the audio hardware and the other
+// ADCs and DACs (if available). If only audio is available, numMatrixFrames
+// will be 0.
+
+void render(BeagleRTContext *context, void *userData)
+{
+	static int count=0;
+	static float lfoPhase=0;
+	static float feedback=0;
+	int updateRate=8;
+	if((count&(updateRate-1))==0 && digitalReadFrame(context,0,P8_07)==GPIO_HIGH){
+		float amplitude=context->analogIn[0]/0.84*4990;
+		float rate=context->analogIn[1]*20+0.1;
+		lfoPhase+=rate*2*M_PI*updateRate*context->analogFrames/context->audioSampleRate;
+		D=amplitude+amplitude*sinf(lfoPhase);
+		BeagleRT_scheduleAuxiliaryTask(updatePll);
+		if((count&255)==0){
+			rt_printf("gpio: %d\n",digitalReadFrame(context,0,P8_07));
+			rt_printf("D: %.0f\n", D);
+			rt_printf("rate: %f\n", rate/2);
+			rt_printf("amplitude: %.3f\n", amplitude);
+			rt_printf("feedback: %.3f\n\n", feedback);
+		}
+	}
+	count++;
+
+	for(unsigned int n = 0; n < context->audioFrames; n++) {
+		feedback=context->analogIn[n/2*context->analogChannels+2]/0.84*1.2;
+		if(digitalReadFrame(context,n,P8_08)==GPIO_LOW)
+			feedback=0;
+	    delay[writePointer++]=context->audioIn[n*context->audioChannels+0] + delay[readPointer]*feedback;
+		context->audioOut[n*context->audioChannels+0]=context->audioIn[n*context->audioChannels+0]+delay[readPointer++];
+//		context->audioOut[n*context->audioChannels+1]=sinf(gPhase1);
+		context->analogOut[n/2*context->analogChannels+0]=D/10000;
+		if(writePointer>=delayLength)
+			writePointer-=delayLength;
+		if(readPointer>=delayLength)
+			readPointer-=delayLength;
+
+		gPhase1 += 2.0 * M_PI * gFrequency1 * gInverseSampleRate;
+	    gPhase2 += 2.0 * M_PI * gFrequency2 * gInverseSampleRate;
+		if(gPhase1 > 2.0 * M_PI)
+			gPhase1 -= 2.0 * M_PI;
+		if(gPhase2 > 2.0 * M_PI)
+			gPhase2 -= 2.0 * M_PI;
+		
+	}
+}
+
+// cleanup_render() is called once at the end, after the audio has stopped.
+// Release any resources that were allocated in initialise_render().
+
+void cleanup(BeagleRTContext *context, void *userData)
+{
+    
+}
--- a/pru_rtaudio.p	Thu Jul 23 23:32:47 2015 +0100
+++ b/pru_rtaudio.p	Mon Jul 27 12:46:55 2015 +0100
@@ -145,6 +145,7 @@
 #define MCASP_RFIFOCTL			0x1008
 #define MCASP_RFIFOSTS			0x100C
 
+#define MCASP_XSTAT_XUNDRN_BIT          0        // Bit to test if there was an underrun
 #define MCASP_XSTAT_XDATA_BIT           5        // Bit to test for transmit ready
 #define MCASP_RSTAT_RDATA_BIT           5        // Bit to test for receive ready 
 	
@@ -853,6 +854,7 @@
       // Wait for McASP XSTAT[XDATA] to set indicating we can write more data
 MCASP_WAIT_XSTAT:
       LBBO r2, reg_mcasp_addr, MCASP_XSTAT, 4
+      QBBS START, r2, MCASP_XSTAT_XUNDRN_BIT // if underrun occurred, reset the PRU
       QBBC MCASP_WAIT_XSTAT, r2, MCASP_XSTAT_XDATA_BIT
 
       MCASP_REG_WRITE_EXT MCASP_XBUF, r7
--- a/scripts/setup-ssh.sh	Thu Jul 23 23:32:47 2015 +0100
+++ b/scripts/setup-ssh.sh	Mon Jul 27 12:46:55 2015 +0100
@@ -78,7 +78,7 @@
 # StrictHostKeyChecking=no below will prevent the following message upon the first connection:
 # "The authenticity of host '192.168.1.2' can't be established."
 # which would require the user to type 'yes'
-cat ${PRIVATE_KEY_FILENAME}.pub | (ssh -q -o StrictHostKeyChecking=no bbb 'mkdir -p .ssh; cat > .ssh/authorized_keys')
+cat ${PRIVATE_KEY_FILENAME}.pub | (ssh -q -o StrictHostKeyChecking=no bbb 'mkdir -p .ssh; cat >> .ssh/authorized_keys')
 if [ $? -ne 0 ] ; then
   printf "ERROR: An error occurred while copying the public key  to the BBB\n"
   exit 3