Several users have contacted us about using the Unix toolchain on OS X, so they can develop programs for Maple without using the IDE. We’ve gotten it working on the latest version of Snow Leopard; now you can, too!
This is a short list of descriptions of some audio effects that I put together for my work with audio processing on Maple so that I could easily look and come up with something in code. I left out some, like distortion and tremolo, that are either very obvious to me or too general (or have too many forms) to classify with a short description.
Noise Gate
Require signal level to reach a threshold before passing it. It’s good to have a lower threshold to turn it off than used to turn it on to eliminate “chatter” or switching on and off during sound that’s around the threshold. Sometimes a hold-time before the signal can be switched off is desirable.
Octave-up
Apply full-wave rectification and mix with original signal or FFT and shift all the bins to the bin with twice the frequency.
Octave-down
Convert signal to square wave, count the period, stretch by a factor of 2, and mix. Add another square wave stretched by a factor of four to create two octaves down. For a more natural sound, use the stretched square waves to modulate the polarity of the original signal. Doing this with the one octave down square wave produces frequencies at one half and three halves ratios of the “fundamental frequency” of the input signal. Octave-down effects are commonly used for kick drums to produce a “heavier” sound.
Phaser
The electronic phasing effect is created by splitting an audio signal into two paths. One path treats the signal with an all-pass filter, which preserves the amplitude of the original signal and alters the phase. The amount of change in phase depends on the frequency. When signals from the two paths are mixed, the frequencies that are out of phase will cancel each other out, creating a phaser’s characteristic notches. Changing the mix ratio changes the depth of the notches; the deepest notches occur when the mix ratio is 50%. The phasors (not phasers) in the output of the discrete Fourier transform could also be rotated before the inverse transform is applied to achieve phasing.
Chorus
The chorus effect is produced by taking an audio signal and mixing it with one or more delayed, pitch-modulated copies of itself. The pitch of the added voices is typically modulated by an LFO, which makes the overall effect similar to that of a flanger, except with longer delays and without feedback.
Flanging
Flanging is an audio effect that occurs when two identical signals are mixed together, but with one signal time-delayed by a small and gradually changing amount, usually smaller than 20 milliseconds. This produces a swept comb filter effect: peaks and notches are produced in the resultant frequency spectrum, related to each other in a linear harmonic series. Varying the time delay causes these to sweep up and down the frequency spectrum. Part of the output signal is usually fed back to the input, producing a resonance effect which further enhances the intensity of the peaks and troughs. The phase of the fed-back signal is sometimes inverted, producing another variation on the flanging sound.
Reverberation
Feedback delay networks can be used to simulate or implement reverb. A convolution reverb can also be used, which can be understood by the fact the convolving the response of an environment to infinitely short impulse with a signal transforms the signal to how it would be in that environment. Gated reverb is an effect commonly applied to drums to make them sound more “punchy”. It is strong reverb that is often gated by the level of the original signal.
Ring Modulation
Ring modulation is achieved by multiplying two signals. Often one of the signals is something simple like a sine-wave or another simple waveform. The product is the sum and difference of and between the frequencies present in each waveform. Can be used to make speech sound robotic.
Vocoder
A vocoder is an analysis/synthesis system, mostly used for speech. In the encoder, the input is passed through a multi-band filter, each band is passed through an envelope follower, and the control signals from the envelope followers are communicated to the decoder. The decoder applies these (amplitude) control signals to corresponding filters in the (re)synthesizer.
Comb Filter
A comb filter adds a delayed version of a signal to itself, causing constructive and destructive interference. The frequency response of a comb filter consists of a series of regularly-spaced spikes, giving the appearance of a comb.
Real-time audio processing is an example of an application where Maple really shines in comparison to Arduino. Maple has 12-bit ADCs with sample rates up to 1MSPS and PWM fast enough to clear ~11.8 bits of resolution (log2(72MHz/20kHz)=11.8) at a frequency twice the Nyquist frequency of the upper end of the bandwidth of the human ear (20kHz). And there’s a lot of clock cycles to do all kinds of really awesome stuff to the signal (e.g. echo, distortion, octave, harmony, equalization, flange, phaser, fuzz, ring modulation, and complete new imagined effects)! I drew up a schematic and layout in EAGLE and etched a PCB with two 1/8″ audio jacks, an adjustable preamp, input and output filters, and some potentiometers. Here’s a photo of the assembled shield and the schematic:
Note: The potentiometer knobs aren’t on the schematic; I hand wired them afterwards.
Here are the EAGLE schematic and board layout files for this board: audioshieldproto-r2-v1.sch audioshieldproto-r2-v1.brd
This can also be breadboarded with some increase in noise, but it’s not that bad for guitar. I made a similar board awhile ago that had no input filter, and it was a lot of fun, but I wanted to lower the noise floor of the system, which ends up sounding like a hiss in the background. To do this, I needed an input filter. Why? What happens is that the signal going into the ADC pin contains component frequencies above half the sampling rate of the ADC that get aliased back into the audible range. So any noise (environmental, digital transition, etc.) that contains frequencies above half the sample rate that’s around make the output noisier. The purpose of the analog input filter is to filter them out before they are digitized. This is what what the input filter looks like:
The filter is an active filter of the Sallen-Key topology. I used AD8452 op-amps that I got from Digi-Key, which is one of the few op-amps suitable for 3.3V single supply operation. Another good op-amp for this, which I’ll probably go with on the next version of this board, is the LM324, which is a quad op-amp (four in a package). This will make it easier and cheaper to build a higher order input filter. I modeled the filter I built on this board with LTSpice and this is what the frequency response looks like:
Here’s a link to the LTSpice schematic for the filter: sallen-keyinputlowpassfilter.asc
So what does it sound like? I’m obsessed with audio effects, but I don’t play guitar. I tried to play guitar for these recordings. Here’s a photo of the setup:
To record the effect, I simply connected the output to my computer instead of headphones or a guitar amplifier.
Here’s an mp3 of the guitar just being passed through with no effect:
audioshieldproto-passcleanguitar.mp3
This is where the knob that varies the mix between clean and the effect is turned about half-way up:
audioshieldproto-halfeffectguitar.mp3
Here’s full effect:
audioshieldproto-fulleffectguitar.mp3
These are with a sine and triangle wave input instead of a guitar and I turned the knob up and then down:
audioshieldproto-sinewave-turningknob.mp3
audioshieldproto-trianglewave-turningknob.mp3
I generated the sine and triangle waves with a signal generator app I downloaded onto an iPod Touch:
Notice the noise on all of these recordings. There are four main sources of this, which will be eliminated with more work. As mentioned, a higher input filter will rid of some noise. The code for the effect causes low amplitude signals are mapped to high amplitudes, which is another source of noise. This can be remedied by using a slightly different transfer function for the effect. A third source is from sampling an unbuffered 10k potentiometer. High-speed measurements made with the ADC require lower input impedances to achieve low noise. The reading of the potentiometer is being coupled to the input signal in the sketch for this effect by multiplying the reading by the input to derive the output. Most “control parameters” should probably be measured at a lower sample rate, and simply varying the mix of effect vs. no-effect is so common that it may should be a function that’s done completely in analog.
The final source of noise is really more of a systematic distortion. You might notice the non-gaussian sounding clicks/pops/ticks etc. This is likely due to timing irregularities in the sketch’s execution. While Maple is running the sketch, it gets interrupted a lot. For example, regular systick interrupts trigger the system timer to increment when using millis(), regular USB interrupts provide the SerialUSB functionality. An improved version of an audio application might remedy this by using DMA and timer features of the stm32. On the sampling side, this might include configuring the ADC’s to run in DMA mode, where they record samples into a buffer for you automatically without requiring any attention from the processor. You can then read from that buffer safe in the knowledge that the samples were captured at highly regular intervals (plus you save on processor time). On the output side, ideally we should be adjusting the PWM value at consistent intervals as well. To do this, we could configure a timer interrupt at high priority to guarantee an output event at fixed intervals such as 1/44000 of a second. These more advanced features are partially supported by the library in 0.0.6, and documentation is on the way. Check out the app notes from ST for more information on stuff that can be done to get the most out of the ADC systems onboard the stm32.
Here’s the sketch for the effect:
// Octave-ish/Harmonizer-ish Audio/Guitar Effect // for handmade prototype audio effects Maple shield // by okie and the leaf blowers #define AIN 18 #define AOUT 6 #define POT 16 int knob = 0; int signalin = 0; int signalout = 0; int iomap[] = {256, 259, 262, 265, 268, 271, 274, 277, 281, 284, 287, 290, 293, 296, 299, 302, 305, 309, 312, 315, 318, 321, 324, 327, 330, 333, 336, 339, 342, 345, 348, 351, 353, 356, 359, 362, 365, 368, 371, 373, 376, 379, 382, 384, 387, 390, 392, 395, 398, 400, 403, 405, 408, 411, 413, 415, 418, 420, 423, 425, 427, 430, 432, 434, 437, 439, 441, 443, 445, 447, 449, 451, 453, 455, 457, 459, 461, 463, 465, 467, 468, 470, 472, 473, 475, 477, 478, 480, 481, 483, 484, 486, 487, 488, 490, 491, 492, 493, 494, 495, 497, 498, 499, 500, 500, 501, 502, 503, 504, 505, 505, 506, 507, 507, 508, 508, 509, 509, 510, 510, 510, 511, 511, 511, 511, 511, 511, 511, 512, 511, 511, 511, 511, 511, 511, 511, 510, 510, 510, 509, 509, 508, 508, 507, 507, 506, 505, 505, 504, 503, 502, 501, 500, 500, 499, 498, 497, 495, 494, 493, 492, 491, 490, 488, 487, 486, 484, 483, 481, 480, 478, 477, 475, 473, 472, 470, 468, 467, 465, 463, 461, 459, 457, 455, 453, 451, 449, 447, 445, 443, 441, 439, 437, 434, 432, 430, 427, 425, 423, 420, 418, 415, 413, 411, 408, 405, 403, 400, 398, 395, 392, 390, 387, 384, 382, 379, 376, 373, 371, 368, 365, 362, 359, 356, 353, 351, 348, 345, 342, 339, 336, 333, 330, 327, 324, 321, 318, 315, 312, 309, 305, 302, 299, 296, 293, 290, 287, 284, 281, 277, 274, 271, 268, 265, 262, 259, 256, 252, 249, 246, 243, 240, 237, 234, 230, 227, 224, 221, 218, 215, 212, 209, 206, 202, 199, 196, 193, 190, 187, 184, 181, 178, 175, 172, 169, 166, 163, 160, 158, 155, 152, 149, 146, 143, 140, 138, 135, 132, 129, 127, 124, 121, 119, 116, 113, 111, 108, 106, 103, 100, 98, 96, 93, 91, 88, 86, 84, 81, 79, 77, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 43, 41, 39, 38, 36, 34, 33, 31, 30, 28, 27, 25, 24, 23, 21, 20, 19, 18, 17, 16, 14, 13, 12, 11, 11, 10, 9, 8, 7, 6, 6, 5, 4, 4, 3, 3, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 6, 6, 7, 8, 9, 10, 11, 11, 12, 13, 14, 16, 17, 18, 19, 20, 21, 23, 24, 25, 27, 28, 30, 31, 33, 34, 36, 38, 39, 41, 43, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 77, 79, 81, 84, 86, 88, 91, 93, 96, 98, 100, 103, 106, 108, 111, 113, 116, 119, 121, 124, 127, 129, 132, 135, 138, 140, 143, 146, 149, 152, 155, 158, 160, 163, 166, 169, 172, 175, 178, 181, 184, 187, 190, 193, 196, 199, 202, 206, 209, 212, 215, 218, 221, 224, 227, 230, 234, 237, 240, 243, 246, 249, 252, 255, 259, 262, 265, 268, 271, 274, 277, 281, 284, 287, 290, 293, 296, 299, 302, 305, 309, 312, 315, 318, 321, 324, 327, 330, 333, 336, 339, 342, 345, 348, 351, 353, 356, 359, 362, 365, 368, 371, 373, 376, 379, 382, 384, 387, 390, 392, 395, 398, 400, 403, 405, 408, 411, 413, 415, 418, 420, 423, 425, 427, 430, 432, 434, 437, 439, 441, 443, 445, 447, 449, 451, 453, 455, 457, 459, 461, 463, 465, 467, 468, 470, 472, 473, 475, 477, 478, 480, 481, 483, 484, 486, 487, 488, 490, 491, 492, 493, 494, 495, 497, 498, 499, 500, 500, 501, 502, 503, 504, 505, 505, 506, 507, 507, 508, 508, 509, 509, 510, 510, 510, 511, 511, 511, 511, 511, 511, 511, 512, 511, 511, 511, 511, 511, 511, 511, 510, 510, 510, 509, 509, 508, 508, 507, 507, 506, 505, 505, 504, 503, 502, 501, 500, 500, 499, 498, 497, 495, 494, 493, 492, 491, 490, 488, 487, 486, 484, 483, 481, 480, 478, 477, 475, 473, 472, 470, 468, 467, 465, 463, 461, 459, 457, 455, 453, 451, 449, 447, 445, 443, 441, 439, 437, 434, 432, 430, 427, 425, 423, 420, 418, 415, 413, 411, 408, 405, 403, 400, 398, 395, 392, 390, 387, 384, 382, 379, 376, 373, 371, 368, 365, 362, 359, 356, 353, 351, 348, 345, 342, 339, 336, 333, 330, 327, 324, 321, 318, 315, 312, 309, 305, 302, 299, 296, 293, 290, 287, 284, 281, 277, 274, 271, 268, 265, 262, 259, 256, 252, 249, 246, 243, 240, 237, 234, 230, 227, 224, 221, 218, 215, 212, 209, 206, 202, 199, 196, 193, 190, 187, 184, 181, 178, 175, 172, 169, 166, 163, 160, 158, 155, 152, 149, 146, 143, 140, 138, 135, 132, 129, 127, 124, 121, 119, 116, 113, 111, 108, 106, 103, 100, 98, 96, 93, 91, 88, 86, 84, 81, 79, 77, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 43, 41, 39, 38, 36, 34, 33, 31, 30, 28, 27, 25, 24, 23, 21, 20, 19, 18, 17, 16, 14, 13, 12, 11, 11, 10, 9, 8, 7, 6, 6, 5, 4, 4, 3, 3, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 6, 6, 7, 8, 9, 10, 11, 11, 12, 13, 14, 16, 17, 18, 19, 20, 21, 23, 24, 25, 27, 28, 30, 31, 33, 34, 36, 38, 39, 41, 43, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 77, 79, 81, 84, 86, 88, 91, 93, 96, 98, 100, 103, 106, 108, 111, 113, 116, 119, 121, 124, 127, 129, 132, 135, 138, 140, 143, 146, 149, 152, 155, 158, 160, 163, 166, 169, 172, 175, 178, 181, 184, 187, 190, 193, 196, 199, 202, 206, 209, 212, 215, 218, 221, 224, 227, 230, 234, 237, 240, 243, 246, 249, 252, 255, 259, 262, 265, 268, 271, 274, 277, 281, 284, 287, 290, 293, 296, 299, 302, 305, 309, 312, 315, 318, 321, 324, 327, 330, 333, 336, 339, 342, 345, 348, 351, 353, 356, 359, 362, 365, 368, 371, 373, 376, 379, 382, 384, 387, 390, 392, 395, 398, 400, 403, 405, 408, 411, 413, 415, 418, 420, 423, 425, 427, 430, 432, 434, 437, 439, 441, 443, 445, 447, 449, 451, 453, 455, 457, 459, 461, 463, 465, 467, 468, 470, 472, 473, 475, 477, 478, 480, 481, 483, 484, 486, 487, 488, 490, 491, 492, 493, 494, 495, 497, 498, 499, 500, 500, 501, 502, 503, 504, 505, 505, 506, 507, 507, 508, 508, 509, 509, 510, 510, 510, 511, 511, 511, 511, 511, 511, 511, 512, 511, 511, 511, 511, 511, 511, 511, 510, 510, 510, 509, 509, 508, 508, 507, 507, 506, 505, 505, 504, 503, 502, 501, 500, 500, 499, 498, 497, 495, 494, 493, 492, 491, 490, 488, 487, 486, 484, 483, 481, 480, 478, 477, 475, 473, 472, 470, 468, 467, 465, 463, 461, 459, 457, 455, 453, 451, 449, 447, 445, 443, 441, 439, 437, 434, 432, 430, 427, 425, 423, 420, 418, 415, 413, 411, 408, 405, 403, 400, 398, 395, 392, 390, 387, 384, 382, 379, 376, 373, 371, 368, 365, 362, 359, 356, 353, 351, 348, 345, 342, 339, 336, 333, 330, 327, 324, 321, 318, 315, 312, 309, 305, 302, 299, 296, 293, 290, 287, 284, 281, 277, 274, 271, 268, 265, 262, 259, 256, 252, 249, 246, 243, 240, 237, 234, 230, 227, 224, 221, 218, 215, 212, 209, 206, 202, 199, 196, 193, 190, 187, 184, 181, 178, 175, 172, 169, 166, 163, 160, 158, 155, 152, 149, 146, 143, 140, 138, 135, 132, 129, 127, 124, 121, 119, 116, 113, 111, 108, 106, 103, 100, 98, 96, 93, 91, 88, 86, 84, 81, 79, 77, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 43, 41, 39, 38, 36, 34, 33, 31, 30, 28, 27, 25, 24, 23, 21, 20, 19, 18, 17, 16, 14, 13, 12, 11, 11, 10, 9, 8, 7, 6, 6, 5, 4, 4, 3, 3, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 6, 6, 7, 8, 9, 10, 11, 11, 12, 13, 14, 16, 17, 18, 19, 20, 21, 23, 24, 25, 27, 28, 30, 31, 33, 34, 36, 38, 39, 41, 43, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 77, 79, 81, 84, 86, 88, 91, 93, 96, 98, 100, 103, 106, 108, 111, 113, 116, 119, 121, 124, 127, 129, 132, 135, 138, 140, 143, 146, 149, 152, 155, 158, 160, 163, 166, 169, 172, 175, 178, 181, 184, 187, 190, 193, 196, 199, 202, 206, 209, 212, 215, 218, 221, 224, 227, 230, 234, 237, 240, 243, 246, 249, 252, 255, 259, 262, 265, 268, 271, 274, 277, 281, 284, 287, 290, 293, 296, 299, 302, 305, 309, 312, 315, 318, 321, 324, 327, 330, 333, 336, 339, 342, 345, 348, 351, 353, 356, 359, 362, 365, 368, 371, 373, 376, 379, 382, 384, 387, 390, 392, 395, 398, 400, 403, 405, 408, 411, 413, 415, 418, 420, 423, 425, 427, 430, 432, 434, 437, 439, 441, 443, 445, 447, 449, 451, 453, 455, 457, 459, 461, 463, 465, 467, 468, 470, 472, 473, 475, 477, 478, 480, 481, 483, 484, 486, 487, 488, 490, 491, 492, 493, 494, 495, 497, 498, 499, 500, 500, 501, 502, 503, 504, 505, 505, 506, 507, 507, 508, 508, 509, 509, 510, 510, 510, 511, 511, 511, 511, 511, 511, 511, 512, 511, 511, 511, 511, 511, 511, 511, 510, 510, 510, 509, 509, 508, 508, 507, 507, 506, 505, 505, 504, 503, 502, 501, 500, 500, 499, 498, 497, 495, 494, 493, 492, 491, 490, 488, 487, 486, 484, 483, 481, 480, 478, 477, 475, 473, 472, 470, 468, 467, 465, 463, 461, 459, 457, 455, 453, 451, 449, 447, 445, 443, 441, 439, 437, 434, 432, 430, 427, 425, 423, 420, 418, 415, 413, 411, 408, 405, 403, 400, 398, 395, 392, 390, 387, 384, 382, 379, 376, 373, 371, 368, 365, 362, 359, 356, 353, 351, 348, 345, 342, 339, 336, 333, 330, 327, 324, 321, 318, 315, 312, 309, 305, 302, 299, 296, 293, 290, 287, 284, 281, 277, 274, 271, 268, 265, 262, 259, 255, 252, 249, 246, 243, 240, 237, 234, 230, 227, 224, 221, 218, 215, 212, 209, 206, 202, 199, 196, 193, 190, 187, 184, 181, 178, 175, 172, 169, 166, 163, 160, 158, 155, 152, 149, 146, 143, 140, 138, 135, 132, 129, 127, 124, 121, 119, 116, 113, 111, 108, 106, 103, 100, 98, 96, 93, 91, 88, 86, 84, 81, 79, 77, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 43, 41, 39, 38, 36, 34, 33, 31, 30, 28, 27, 25, 24, 23, 21, 20, 19, 18, 17, 16, 14, 13, 12, 11, 11, 10, 9, 8, 7, 6, 6, 5, 4, 4, 3, 3, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 6, 6, 7, 8, 9, 10, 11, 11, 12, 13, 14, 16, 17, 18, 19, 20, 21, 23, 24, 25, 27, 28, 30, 31, 33, 34, 36, 38, 39, 41, 43, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 77, 79, 81, 84, 86, 88, 91, 93, 96, 98, 100, 103, 106, 108, 111, 113, 116, 119, 121, 124, 127, 129, 132, 135, 138, 140, 143, 146, 149, 152, 155, 158, 160, 163, 166, 169, 172, 175, 178, 181, 184, 187, 190, 193, 196, 199, 202, 206, 209, 212, 215, 218, 221, 224, 227, 230, 234, 237, 240, 243, 246, 249, 252, 255, 259, 262, 265, 268, 271, 274, 277, 281, 284, 287, 290, 293, 296, 299, 302, 305, 309, 312, 315, 318, 321, 324, 327, 330, 333, 336, 339, 342, 345, 348, 351, 353, 356, 359, 362, 365, 368, 371, 373, 376, 379, 382, 384, 387, 390, 392, 395, 398, 400, 403, 405, 408, 411, 413, 415, 418, 420, 423, 425, 427, 430, 432, 434, 437, 439, 441, 443, 445, 447, 449, 451, 453, 455, 457, 459, 461, 463, 465, 467, 468, 470, 472, 473, 475, 477, 478, 480, 481, 483, 484, 486, 487, 488, 490, 491, 492, 493, 494, 495, 497, 498, 499, 500, 500, 501, 502, 503, 504, 505, 505, 506, 507, 507, 508, 508, 509, 509, 510, 510, 510, 511, 511, 511, 511, 511, 511, 511, 512, 511, 511, 511, 511, 511, 511, 511, 510, 510, 510, 509, 509, 508, 508, 507, 507, 506, 505, 505, 504, 503, 502, 501, 500, 500, 499, 498, 497, 495, 494, 493, 492, 491, 490, 488, 487, 486, 484, 483, 481, 480, 478, 477, 475, 473, 472, 470, 468, 467, 465, 463, 461, 459, 457, 455, 453, 451, 449, 447, 445, 443, 441, 439, 437, 434, 432, 430, 427, 425, 423, 420, 418, 415, 413, 411, 408, 405, 403, 400, 398, 395, 392, 390, 387, 384, 382, 379, 376, 373, 371, 368, 365, 362, 359, 356, 353, 351, 348, 345, 342, 339, 336, 333, 330, 327, 324, 321, 318, 315, 312, 309, 305, 302, 299, 296, 293, 290, 287, 284, 281, 277, 274, 271, 268, 265, 262, 259, 255, 252, 249, 246, 243, 240, 237, 234, 230, 227, 224, 221, 218, 215, 212, 209, 206, 202, 199, 196, 193, 190, 187, 184, 181, 178, 175, 172, 169, 166, 163, 160, 158, 155, 152, 149, 146, 143, 140, 138, 135, 132, 129, 127, 124, 121, 119, 116, 113, 111, 108, 106, 103, 100, 98, 96, 93, 91, 88, 86, 84, 81, 79, 77, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 43, 41, 39, 38, 36, 34, 33, 31, 30, 28, 27, 25, 24, 23, 21, 20, 19, 18, 17, 16, 14, 13, 12, 11, 11, 10, 9, 8, 7, 6, 6, 5, 4, 4, 3, 3, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 6, 6, 7, 8, 9, 10, 11, 11, 12, 13, 14, 16, 17, 18, 19, 20, 21, 23, 24, 25, 27, 28, 30, 31, 33, 34, 36, 38, 39, 41, 43, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 77, 79, 81, 84, 86, 88, 91, 93, 96, 98, 100, 103, 106, 108, 111, 113, 116, 119, 121, 124, 127, 129, 132, 135, 138, 140, 143, 146, 149, 152, 155, 158, 160, 163, 166, 169, 172, 175, 178, 181, 184, 187, 190, 193, 196, 199, 202, 206, 209, 212, 215, 218, 221, 224, 227, 230, 234, 237, 240, 243, 246, 249, 252, 255, 259, 262, 265, 268, 271, 274, 277, 281, 284, 287, 290, 293, 296, 299, 302, 305, 309, 312, 315, 318, 321, 324, 327, 330, 333, 336, 339, 342, 345, 348, 351, 353, 356, 359, 362, 365, 368, 371, 373, 376, 379, 382, 384, 387, 390, 392, 395, 398, 400, 403, 405, 408, 411, 413, 415, 418, 420, 423, 425, 427, 430, 432, 434, 437, 439, 441, 443, 445, 447, 449, 451, 453, 455, 457, 459, 461, 463, 465, 467, 468, 470, 472, 473, 475, 477, 478, 480, 481, 483, 484, 486, 487, 488, 490, 491, 492, 493, 494, 495, 497, 498, 499, 500, 500, 501, 502, 503, 504, 505, 505, 506, 507, 507, 508, 508, 509, 509, 510, 510, 510, 511, 511, 511, 511, 511, 511, 511, 512, 511, 511, 511, 511, 511, 511, 511, 510, 510, 510, 509, 509, 508, 508, 507, 507, 506, 505, 505, 504, 503, 502, 501, 500, 500, 499, 498, 497, 495, 494, 493, 492, 491, 490, 488, 487, 486, 484, 483, 481, 480, 478, 477, 475, 473, 472, 470, 468, 467, 465, 463, 461, 459, 457, 455, 453, 451, 449, 447, 445, 443, 441, 439, 437, 434, 432, 430, 427, 425, 423, 420, 418, 415, 413, 411, 408, 405, 403, 400, 398, 395, 392, 390, 387, 384, 382, 379, 376, 373, 371, 368, 365, 362, 359, 356, 353, 351, 348, 345, 342, 339, 336, 333, 330, 327, 324, 321, 318, 315, 312, 309, 305, 302, 299, 296, 293, 290, 287, 284, 281, 277, 274, 271, 268, 265, 262, 259, 256, 252, 249, 246, 243, 240, 237, 234, 230, 227, 224, 221, 218, 215, 212, 209, 206, 202, 199, 196, 193, 190, 187, 184, 181, 178, 175, 172, 169, 166, 163, 160, 158, 155, 152, 149, 146, 143, 140, 138, 135, 132, 129, 127, 124, 121, 119, 116, 113, 111, 108, 106, 103, 100, 98, 96, 93, 91, 88, 86, 84, 81, 79, 77, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 43, 41, 39, 38, 36, 34, 33, 31, 30, 28, 27, 25, 24, 23, 21, 20, 19, 18, 17, 16, 14, 13, 12, 11, 11, 10, 9, 8, 7, 6, 6, 5, 4, 4, 3, 3, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 6, 6, 7, 8, 9, 10, 11, 11, 12, 13, 14, 16, 17, 18, 19, 20, 21, 23, 24, 25, 27, 28, 30, 31, 33, 34, 36, 38, 39, 41, 43, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 77, 79, 81, 84, 86, 88, 91, 93, 96, 98, 100, 103, 106, 108, 111, 113, 116, 119, 121, 124, 127, 129, 132, 135, 138, 140, 143, 146, 149, 152, 155, 158, 160, 163, 166, 169, 172, 175, 178, 181, 184, 187, 190, 193, 196, 199, 202, 206, 209, 212, 215, 218, 221, 224, 227, 230, 234, 237, 240, 243, 246, 249, 252, 255, 259, 262, 265, 268, 271, 274, 277, 281, 284, 287, 290, 293, 296, 299, 302, 305, 309, 312, 315, 318, 321, 324, 327, 330, 333, 336, 339, 342, 345, 348, 351, 353, 356, 359, 362, 365, 368, 371, 373, 376, 379, 382, 384, 387, 390, 392, 395, 398, 400, 403, 405, 408, 411, 413, 415, 418, 420, 423, 425, 427, 430, 432, 434, 437, 439, 441, 443, 445, 447, 449, 451, 453, 455, 457, 459, 461, 463, 465, 467, 468, 470, 472, 473, 475, 477, 478, 480, 481, 483, 484, 486, 487, 488, 490, 491, 492, 493, 494, 495, 497, 498, 499, 500, 500, 501, 502, 503, 504, 505, 505, 506, 507, 507, 508, 508, 509, 509, 510, 510, 510, 511, 511, 511, 511, 511, 511, 511, 512, 511, 511, 511, 511, 511, 511, 511, 510, 510, 510, 509, 509, 508, 508, 507, 507, 506, 505, 505, 504, 503, 502, 501, 500, 500, 499, 498, 497, 495, 494, 493, 492, 491, 490, 488, 487, 486, 484, 483, 481, 480, 478, 477, 475, 473, 472, 470, 468, 467, 465, 463, 461, 459, 457, 455, 453, 451, 449, 447, 445, 443, 441, 439, 437, 434, 432, 430, 427, 425, 423, 420, 418, 415, 413, 411, 408, 405, 403, 400, 398, 395, 392, 390, 387, 384, 382, 379, 376, 373, 371, 368, 365, 362, 359, 356, 353, 351, 348, 345, 342, 339, 336, 333, 330, 327, 324, 321, 318, 315, 312, 309, 305, 302, 299, 296, 293, 290, 287, 284, 281, 277, 274, 271, 268, 265, 262, 259, 255, 252, 249, 246, 243, 240, 237, 234, 230, 227, 224, 221, 218, 215, 212, 209, 206, 202, 199, 196, 193, 190, 187, 184, 181, 178, 175, 172, 169, 166, 163, 160, 158, 155, 152, 149, 146, 143, 140, 138, 135, 132, 129, 127, 124, 121, 119, 116, 113, 111, 108, 106, 103, 100, 98, 96, 93, 91, 88, 86, 84, 81, 79, 77, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 43, 41, 39, 38, 36, 34, 33, 31, 30, 28, 27, 25, 24, 23, 21, 20, 19, 18, 17, 16, 14, 13, 12, 11, 11, 10, 9, 8, 7, 6, 6, 5, 4, 4, 3, 3, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 6, 6, 7, 8, 9, 10, 11, 11, 12, 13, 14, 16, 17, 18, 19, 20, 21, 23, 24, 25, 27, 28, 30, 31, 33, 34, 36, 38, 39, 41, 43, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 77, 79, 81, 84, 86, 88, 91, 93, 96, 98, 100, 103, 106, 108, 111, 113, 116, 119, 121, 124, 127, 129, 132, 135, 138, 140, 143, 146, 149, 152, 155, 158, 160, 163, 166, 169, 172, 175, 178, 181, 184, 187, 190, 193, 196, 199, 202, 206, 209, 212, 215, 218, 221, 224, 227, 230, 234, 237, 240, 243, 246, 249, 252, 255, 259, 262, 265, 268, 271, 274, 277, 281, 284, 287, 290, 293, 296, 299, 302, 305, 309, 312, 315, 318, 321, 324, 327, 330, 333, 336, 339, 342, 345, 348, 351, 353, 356, 359, 362, 365, 368, 371, 373, 376, 379, 382, 384, 387, 390, 392, 395, 398, 400, 403, 405, 408, 411, 413, 415, 418, 420, 423, 425, 427, 430, 432, 434, 437, 439, 441, 443, 445, 447, 449, 451, 453, 455, 457, 459, 461, 463, 465, 467, 468, 470, 472, 473, 475, 477, 478, 480, 481, 483, 484, 486, 487, 488, 490, 491, 492, 493, 494, 495, 497, 498, 499, 500, 500, 501, 502, 503, 504, 505, 505, 506, 507, 507, 508, 508, 509, 509, 510, 510, 510, 511, 511, 511, 511, 511, 511, 511, 512, 511, 511, 511, 511, 511, 511, 511, 510, 510, 510, 509, 509, 508, 508, 507, 507, 506, 505, 505, 504, 503, 502, 501, 500, 500, 499, 498, 497, 495, 494, 493, 492, 491, 490, 488, 487, 486, 484, 483, 481, 480, 478, 477, 475, 473, 472, 470, 468, 467, 465, 463, 461, 459, 457, 455, 453, 451, 449, 447, 445, 443, 441, 439, 437, 434, 432, 430, 427, 425, 423, 420, 418, 415, 413, 411, 408, 405, 403, 400, 398, 395, 392, 390, 387, 384, 382, 379, 376, 373, 371, 368, 365, 362, 359, 356, 353, 351, 348, 345, 342, 339, 336, 333, 330, 327, 324, 321, 318, 315, 312, 309, 305, 302, 299, 296, 293, 290, 287, 284, 281, 277, 274, 271, 268, 265, 262, 259, 256, 252, 249, 246, 243, 240, 237, 234, 230, 227, 224, 221, 218, 215, 212, 209, 206, 202, 199, 196, 193, 190, 187, 184, 181, 178, 175, 172, 169, 166, 163, 160, 158, 155, 152, 149, 146, 143, 140, 138, 135, 132, 129, 127, 124, 121, 119, 116, 113, 111, 108, 106, 103, 100, 98, 96, 93, 91, 88, 86, 84, 81, 79, 77, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 43, 41, 39, 38, 36, 34, 33, 31, 30, 28, 27, 25, 24, 23, 21, 20, 19, 18, 17, 16, 14, 13, 12, 11, 11, 10, 9, 8, 7, 6, 6, 5, 4, 4, 3, 3, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 6, 6, 7, 8, 9, 10, 11, 11, 12, 13, 14, 16, 17, 18, 19, 20, 21, 23, 24, 25, 27, 28, 30, 31, 33, 34, 36, 38, 39, 41, 43, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 77, 79, 81, 84, 86, 88, 91, 93, 96, 98, 100, 103, 106, 108, 111, 113, 116, 119, 121, 124, 127, 129, 132, 135, 138, 140, 143, 146, 149, 152, 155, 158, 160, 163, 166, 169, 172, 175, 178, 181, 184, 187, 190, 193, 196, 199, 202, 206, 209, 212, 215, 218, 221, 224, 227, 230, 234, 237, 240, 243, 246, 249, 252}; void setup() { pinMode(AIN, INPUT_ANALOG); pinMode(AOUT, PWM); pinMode(POT, INPUT_ANALOG); // make PWM frequency at least greater than two times the upper end of the // signal bandwidth (signal bandwidth: ~20-20000Hz) timers_set_reload(1, 0x0200); } void loop() { signalin = analogRead(AIN); knob = analogRead(POT); // output: mix raw input and the input mapped to a sine wave stored in iomap // where the mix is weighted by the knob // also: // - scale raw input term by 8 to convert 12-bit ADC reading to 9-bit PWM // - iomap already scales the signal by 8, but scale by 8 again because its // shape is natually louder than raw signal // - scale both terms by the range of the knob reading, 4096 // - divide by 2 because two full scale signals are summed signalout = (signalin*knob/8 + iomap[signalin]*(4096-knob)/4)/4096/2; pwmWrite(AOUT,signalout); }
This sketch is just a quick, easy way to do what it does. Many optimizations can be made for memory, speed, and using timers to make readings and output to PWM would reduce distortion. The main function of this code is to map every possible input value to a different output, which is a really simple concept that can create a slew of neat effects, many which are very common. Here’s a neat webpage about it: http://web.inter.nl.net/hcc/davies/apmicro.html
The mapping being done by my sketch is stored in the array called “iomap”. I computed this array with a simple Python script. Here’s a graph of the map and the script:
Python script: iomapgenerator.py
The horizontal axis is input and the vertical axis is output. I think the behavior of this mapping is interesting. A very low amplitude sine wave is simply amplified but as the amplitude becomes larger, it gets transformed into sine waves with frequencies that are octaves above it.
We’re interested in your comments and ideas! And if you’re interested in continued development on a shield for this stuff, let us know.
It’s been a long week coming, but the latest/greatest version of the IDE has been released; get it now from the install page or the following direct links. If you’re upgrading, you can just back up your old IDE directory and extract the archive to the same place.
- Windows XP 32-bit: http://static.leaflabs.com/pub/leaflabs/maple-ide/maple-ide-0.0.6-windowsxp32.zip
- Linux 32-bit: http://static.leaflabs.com/pub/leaflabs/maple-ide/maple-ide-0.0.6-linux32.tgz
- Linux 64-bit: http://static.leaflabs.com/pub/leaflabs/maple-ide/maple-ide-0.0.6-linux64.tgz
- Mac OSX 10.6 32-bit: http://static.leaflabs.com/pub/leaflabs/maple-ide/maple-ide-0.0.6-macosx-10_6.dmg
Most of the changes were in libmaple; the primary focus was on fixing SerialUSB issues (blocking and autoreset), squashing bugs, and adding interrupt support to the hardware timers.
- Fixed
SerialUSB.print()blocking issue - Usercode would frequently not run when disconnected from a serial port monitor; now it should at least run slowly. See USB docs for more details; in the long run we intend to add even more flexibility here.
- Changed USB reset scheme
- Hopefully fixes some issues with auto-reset on Windows XP.
init()called earlier (thanks xttocs!)- This should help porting some libraries.
- New Makefile scheme for libmaple
- Smarter, less magical, rules based Makefile system.
- Improved udev rule
- Hopefully fixes some issues for Ubuntu 10.04 users.
SerialN.end()andSerialN.flush()methods- By popular request!
- New Timer class for configuring interrupts with the hardware timers
- Whole bunch of goodness! See the docs.
- More
- Many documentation updates, new highlighted keywords, and examples for Serial passthrough, the timers, SerialUSB, and crude VGA.
For a complete list of changes see these github changelogs for the IDE and libmaple.
Please post your successes, failures, comments, and condolences in this forum thread, and have a productive weekend!
This weekend Barry and I found ourselves in a Dollar Tree store– one of the greatest places known to man.
We picked ourselves up some toys to play with, all for a dollar:
The code we used can be found down below. Basically it reads from a button, which changes the state between off and glowing each LED in sequence. The circuit is similarly simple, the diagram also can be found below.
Continue for code and schematic…
While debugging our new SerialUSB implementation I needed to use the regular Serial2 interface to track down ASSERT failures, but couldn’t find a spare FTDI chip around the lab. I’ve got one of these super slick little ones in the mail, but in the meanwhile I wrote this sketch in about 2 seconds which turns a spare Maple into a Serial-USB passthrough:
void setup() { Serial2.begin(9600); } void loop() { if(SerialUSB.available()) { Serial2.write(SerialUSB.read()); } if(Serial2.available()) { SerialUSB.write(Serial2.read()); } }
There are a million better ways to do this but I love how easy this was!
About
Contact
Community
Distributors
Licensing
Feeds
Search
Contact webmaster@leaflabs.com with website issues
Powered by WordPress, nginx, Linux, vim, and coffee.
This site intended to be valid HTML 4.01 Strict. Best viewed with any standards-compliant browser.
Copyright LeafLabs LLC, 2009-2010, a member of the
Green Street Space.
Unless otherwise noted all content on this website is released under the
Creative Commons Attribution Licence 3.0
Hello Anonymous! Login?







