Commits

clee  committed 7a53e65 Draft

have more string synthesis stuff going, started upload_play

  • Participants
  • Parent commits 6253af1

Comments (0)

Files changed (3)

File karplus_string_synthesis/karplus_string_synthesis.pde

 
 // timer1 interrupt routine - all data processed here
 // ISR(TIMER1_COMPA_vect, ISR_NAKED) { // dont store any registers
-void AudioCodec_interrupt()
+void AudioCodec_interrupt() // use this for Maple vs ISR for arduino
 {
 
   // &'s are necessary on data_in variables

File sine_generator_plus_serial3/sine_generator_plus_serial3.pde

 // try faster 9600, 19200, 14400, 38400, 57600, 56000,
 // 115200, 128000, 230400,460800, 153600, 256000,921600
 // the FTDI 232R datasheet says it can go to 3 Mbaud
-#define BAUDRATE 1500000
+// the stm32F103 data sheet mentioned a minimum of 2.25 Mbits/s or one at 4 Mbits/s
+// #define BAUDRATE 1500000
+#define BAUDRATE 2250000
+
 
 #define N_SENDSERIAL 100 // send a serial value every N steps through the loop   
 // include necessary libraries

File upload_play/upload_play.pde

+/*
+ (MAPLE)
+
+Based upon sine_generator in examples with addition of writing to USART while audio_codec is running too. Just outputs a count of the main loop iterations every N steps while an interupt generates the sine tone outupt.
+
+
+guest openmusiclabs 7.13.11
+this program creates a sinewave of variable frequency and
+amplitude, presented at both left and right outputs. there
+isnt any interpolation, so you only get 256 discrete frequencies
+across the span of 44Hz to 10kHz.
+
+Additional it shows how to use Serial3 USART to communicate with the board during
+processing.
+
+Hardware connections
+--------------------
+From the the maple documentaiton the USART Pin Map
+         Tx     Rx      Ck      cts     rts
+Serial3	D29	D30	D31	D32	D33
+(this also applies to the Maple RET6 edition)
+These pins are also listed as being ***5V tolerant***
+
+
+I chose Serial3 because these pins are on the 2x8 header "EXT" block which aren't
+connected to the audio codec shield.
+
+
+So I connected 3 wires to my FTDI basic board:
+   D29 (Tx) to the Rx on the FTDI basic board
+   D30 (Rx) to the Tx on the FTDI basic board
+        GND to GND on on the FTDI basic board
+
+
+
+	
+*/
+
+// setup codec parameters
+// must be done before #includes
+// see readme file in libraries folder for explanations
+#define SAMPLE_RATE 44 // 44.1kHz sample rate
+#define ADCS 2 // use both ADCs
+
+// try faster 9600, 19200, 14400, 38400, 57600, 56000,
+// 115200, 128000, 230400,460800, 153600, 256000,921600
+// the FTDI 232R datasheet says it can go to 3 Mbaud
+// the stm32F103 data sheet mentioned a minimum of 2.25 Mbits/s or one at 4 Mbits/s
+// #define BAUDRATE 1500000
+#define BAUDRATE 2250000
+
+
+#define N_SENDSERIAL 100 // send a serial value every N steps through the loop   
+// include necessary libraries
+// note the Maple library
+#include <AudioCodec_Maple.h>
+
+// create data variables for audio transfer
+// even though there is no input needed, the codec requires stereo data
+// note the uint16 typedef, there is no "unsigned int16" type
+int16 left_in = 0; // in from codec (LINE_IN)
+int16 right_in = 0;
+int16 left_out = 0; // out to codec (HP_OUT)
+int16 right_out = 0;
+
+// create variables for ADC results
+// it only has positive values -> unsigned
+uint16 mod0_value = 0;
+uint16 mod1_value = 0;
+
+// create sinewave lookup table
+// note the int16, ints are 32b in Maple land
+int16 sinewave[] __FLASH__ = {
+  // this file is stored in AudioCodec_Maple.h and is a 1024 value
+  // sinewave lookup table of signed 16bit integers
+  // you can replace it with your own waveform if you like
+  #include <sinetable.inc>
+};
+uint16 location; // lookup table value location
+unsigned int g_count = 0;
+
+void setup() {
+  Serial3.begin(BAUDRATE);
+  SerialUSB.end(); // usb conflicts with the codec in this mode
+                   // a different operating mode which allows both
+                   // is in the works
+  // setup codec and microcontroller registers
+  AudioCodec_init(); // call this last if you are setting up other things
+}
+
+// void fast_gpio(int maple_pin) {
+//     gpio_dev *dev = PIN_MAP[maple_pin].gpio_device;
+//     uint32 bit = PIN_MAP[maple_pin].gpio_bit;
+
+//     gpio_write_bit(dev, bit, 1);
+//     gpio_toggle_bit(dev, bit);
+//     gpio_toggle_bit(dev, bit);
+//     gpio_toggle_bit(dev, bit);
+//     gpio_toggle_bit(dev, bit);
+//     gpio_toggle_bit(dev, bit);
+//     gpio_toggle_bit(dev, bit);
+//     gpio_toggle_bit(dev, bit);
+//     gpio_toggle_bit(dev, bit);
+//     gpio_toggle_bit(dev, bit);
+//     gpio_toggle_bit(dev, bit);
+//     gpio_toggle_bit(dev, bit);
+//     gpio_toggle_bit(dev, bit);
+//     gpio_toggle_bit(dev, bit);
+//     gpio_toggle_bit(dev, bit);
+//     gpio_toggle_bit(dev, bit);
+//     gpio_toggle_bit(dev, bit);
+//     gpio_toggle_bit(dev, bit);
+//     gpio_toggle_bit(dev, bit);
+//     gpio_toggle_bit(dev, bit);
+//     gpio_toggle_bit(dev, bit);
+//     gpio_toggle_bit(dev, bit);
+//     gpio_toggle_bit(dev, bit);
+//     gpio_toggle_bit(dev, bit);
+//     gpio_toggle_bit(dev, bit);
+//     gpio_toggle_bit(dev, bit);
+// }
+
+void serial_term(void)
+{
+  uint8 input;
+  
+  if (! (g_loop_cnt %1000) ) {
+    if (Serial3.available()) {
+      input = Serial3.read();
+      Serial3.print("echo: ");
+      Serial3.println(input);
+
+      switch(input) {
+      case '\r':
+	break;
+
+      case ' ':
+	//      SerialUSB.println("spacebar, nice!");
+            break;
+
+        case '?':
+        case 'h':
+	  // cmd_print_help();
+	break;
+
+        case 'u':
+	  // SerialUSB.println("Hello World!");
+	  break;
+
+      case 'w':
+          //  Serial1.println("Hello World!");
+	  // Serial2.println("Hello World!");
+	  Serial3.println("Hello World!");
+	  break;
+
+        case 'm':
+	  // cmd_serial1_serial3();
+            break;
+
+        case 'E':
+	  //cmd_serial1_echo();
+            break;
+
+        case '.':
+            break;
+
+        case 'd':
+            SerialUSB.println("Disabling USB.  Press BUT to re-enable.");
+            SerialUSB.end();
+            pinMode(BOARD_BUTTON_PIN, INPUT);
+            while (!isButtonPressed())
+                ;
+            SerialUSB.begin();
+            break;
+
+        case 'n':
+	  //cmd_adc_stats();
+            break;
+
+        case 'N':
+	  // cmd_stressful_adc_stats();
+            break;
+
+        case 'e':
+	  // cmd_everything();
+            break;
+
+        case 'W':
+
+            break;
+
+        case 'U':
+	  { int ii=0;
+            SerialUSB.println("Dumping data to Serial3. Press any key to stop stream.");
+            while (!Serial3.available()) {
+                Serial3.print(ii);
+		ii++;
+		
+            }
+	  }
+	  break;
+
+        case 'g':
+	  // cmd_sequential_gpio_toggling();
+            break;
+
+        case 'G':
+	  // cmd_gpio_toggling();
+            break;
+
+        case 'j':
+	  // cmd_sequential_debug_gpio_toggling();
+            break;
+
+        case 'J':
+	  // cmd_debug_gpio_toggling();
+            break;
+
+        case 'B':
+	  // cmd_but_test();
+            break;
+
+        case 'f':
+	  Serial3.println("Wiggling D4 as fast as possible in bursts. "
+			  "Press any key to stop.");
+            pinMode(4, OUTPUT);
+            while (!Serial3.available()) {
+	      // fast_gpio(4);
+	      // delay(1);
+            }
+            break;
+
+        case 'p':
+	  // cmd_sequential_pwm_test();
+            break;
+
+        case '_':
+	  // Serial3.println("Delaying for 5 seconds...");
+	  // delay(5000);
+	  break;
+
+        // Be sure to update cmd_print_help() if you implement these:
+
+        case 't':               // TODO
+
+            break;
+
+        case 'T':               // TODO
+
+            break;
+
+        case 's':
+
+            break;
+
+        // Be sure to update cmd_print_help() if you implement these:
+
+        case 'i':               // TODO
+
+            break;
+
+        case 'I':               // TODO
+            Serial3.println("Unimplemented.");
+            break;
+
+        case 'r':
+            cmd_gpio_monitoring();
+            break;
+
+        case 'a':
+            cmd_sequential_adc_reads();
+            break;
+
+        case 'b':
+            cmd_board_info();
+            break;
+
+        case '+':
+            cmd_gpio_qa();
+            break;
+
+        default: // -------------------------------
+            Serial3.print("Unexpected byte: 0x");
+            Serial3.print((int)input, HEX);
+            Serial3.println(", press h for help.");
+        }
+
+        Serial3.print("> ");
+
+
+
+
+    }
+  }
+  g_loop_cnt++;
+}
+
+
+void loop() {
+  // while (1); // reduces clock jitter
+
+  if (!(g_count % N_SENDSERIAL)) {
+     Serial3.println(g_count);
+  }
+  g_count++;
+}
+
+// timer1 interrupt routine - all data processed here
+void AudioCodec_interrupt() {
+
+  // &'s are necessary on data_in variables
+  AudioCodec_data(&left_in, &right_in, left_out, right_out);
+  
+  // create some temporary variables
+  // these tend to work faster than using the main data variables
+  // as they arent fetched and stored all the time
+  int16 temp1;
+  
+  // create a variable frequency and amplitude sinewave
+  // fetch a sample from the lookup table
+  temp1 = sinewave[location];
+  // step through table at rate determined by mod1
+  // use upper byte of mod1 value to set the rate
+  // and have an offset of 1 so there is always an increment.
+  location += 1 + (mod1_value >> 8);
+  // if weve gone over the table boundary -> loop back
+  // around to the other side.
+  location &= 0x03ff; // fast way of doing rollover for 2^n numbers
+                      // otherwise it would look like this:
+                      // if (location >= 1024) {
+                      // location -= 1024;
+                      // }
+  
+  // set amplitude with mod0
+  // multiply our sinewave by the mod0 value
+  // since it returns a 32bit value it needs to be scaled with ">> 16"
+  temp1 = (temp1 * mod0_value) >> 16;
+  left_out = temp1; // put sinusoid out on left channel
+  right_out = -temp1; // put inverted version out on right chanel
+
+  // get ADC values
+  // & is required before adc variables
+  AudioCodec_ADC(&mod0_value, &mod1_value);
+
+
+  // you dont need to reti() with Maple
+}
+