Show Posts
|
|
Pages: [1]
|
|
1
|
Using Arduino / Audio / Re: How to change modulation at real time in an arpeggiator?
|
on: May 13, 2013, 03:29:20 am
|
Hi, To optimize the code, what I would do is to create a table where you would load your notes : uint16_t arpeg_notes[8]; uint16_t arpeg_notes_start[8];
You can initialize it in your setup : arpeg_notes_start[0] = 72 arpeg_notes_start[1] = 76 ... arpeg_notes[0] = 72 arpeg_notes[1] = 76 ... Then in your loop : loop() { if(step>7) step=0; else step ++;
midi_note_on(0, arpeg_notes[step], vel); delay(dur); midi_note_off(0, arpeg_notes[step], vel); delay(wait);
read_analog(); } Then you make a read_analog function where you read your IR sensor on analog input 0, for exemple. And you want to change the note of all your table, and add the value of IR (transform the 10 bits analog value to 6 bits) read_analog() { change_note(analogRead(0)>>4); }
change_note(uint16_t cn) { for(int i = 0; i<8; i++) { arpeg_notes[i] = arpeg_notes_start[i] + cn; } } That's just an exemple, but in your change_note() function you can do what you want. Of course, doing that in your main loop() section is not good, because the execution time is depending on the computations made in the cycle, and your bpm will be varying a little. You should use arduino timers, but it's another story. And it's better if your code is tagged, like I do.
|
|
|
|
|
2
|
Using Arduino / Audio / Re: DDS Lookup table length
|
on: May 13, 2013, 02:50:09 am
|
|
Hello, Yes, all you say is right. The Shannon theorem says that your sample rate must be more than twice the higher frequency. So if you want sinusoidal signal from 50Hz to 500Hz, a sample rate at 1 kHz should be enough (higher is better). Your table length should be 1 kHz / 50 Hz = 20.
|
|
|
|
|
4
|
Using Arduino / Audio / Re: Mix or merge MIDI IN signals with internal MIDI messages / midi library
|
on: May 07, 2013, 10:05:12 am
|
|
Hi, Yes, it's possible. Just add the MIDI listener in your loop :
if (MIDI.read()) { ...}
Then you get the MIDI messages types : MIDI.getType() and the values (depending on the types) : MIDI.getData1() and MIDI.getData2()
So you can choose what you will send. For exemple, if the MIDI type is "NoteOn", MIDI.getData1() will be the value of the note, and MIDI.getData2() the volume.
Gaétan
|
|
|
|
|
5
|
Using Arduino / Audio / Re: Timers for audio
|
on: May 05, 2013, 10:20:07 am
|
|
Ok, thanks guys. That is what I was looking for, but it doesn't work for buffering. In fact, I think buffering has to be in the main loop. So I cleaned the code (I had some delay instructions), and now it works very well. I can read at least 4 different samples from sd card in the same time.
@duane : that's who wrote a lot of messages in your blog. My project of groovebox is nearly finished.
Thanks.
|
|
|
|
|
7
|
Using Arduino / Audio / Re: Timers for audio
|
on: April 30, 2013, 02:32:51 am
|
|
Thanks for the answer. I tried using sei() function, but my Due doesn't recognize it (function unknown). Maybe this function is just for Uno or Mega ? I will have to find an equivalence.
About the mp3, indeed there is 10 times less information per second than wave, but it must be uncompressed, and it's a costly operation. When I look at some projects about streaming audio data, it seems that it's always buffered in the loop() section. Maybe I will have to do this, because, as Billroy said, it's a C loop, not an interrupted loop.
If someone already made audio streaming, and already thought about this, I will be thankful if he shares his knowledge...
|
|
|
|
|
8
|
Using Arduino / Audio / Re: Timers for audio
|
on: April 29, 2013, 02:34:26 am
|
|
Ok thanks, it explains why the comportment is not the same between loop() and timers. So about I want to do :
1. Using loop()
loop() { read SD card fill the buffer }
timer1_handler (44100 Hz) { read the buffer }
2. Using timer
timer2_handler() (45 Hz) { read SD card (1024 samples at a time) fill the buffer }
timer1_handler(44000 Hz) { read the buffer }
Using loop() in solution 1 is too unstable because I can't determine the loop frequency. Using timer2 in solution 2 can't be done because the time used to read SD card cause lacking in the timer 1.
Is there an other solution ? It must be, because I know it's possible to read mp3 on SD cards with some shields. I didn't manage to analyse the codes to find the solution. I use SDFatLib, but didn't find the solution inside. If someone already did audio stream, let me know !
|
|
|
|
|
9
|
Using Arduino / Audio / Re: Timers for audio
|
on: April 28, 2013, 06:28:19 pm
|
|
Yes, I'm asking a lot to the arduino, but what i don't understand it's that it works with the main loop function, but not with timers. I tooth that the main loop was a timer interrupt like others...
|
|
|
|
|
10
|
Using Arduino / Audio / Timers for audio
|
on: April 28, 2013, 01:58:02 pm
|
Hi, I'll try to explain my problem the best I can. I'm doing an audio sampler with Arduino Due. I made a loop with a timer interrupt running 44000 times per second to generate my sound. I load a buffer with an other timer. When I'm doing short computations, it's ok. But when I do long computations, like reading an SD card, the first timer is lacking. As if it is waiting the second timer to end its operation. When I load the buffer in the main loop(), it seems to work, but I don't want to do it here. I tried different timers on different TC (there are 9), but it's always the same problem. So, I guess that timers are not independant, unlike the loop() function, which is decorrelated to other timers (computations made in one timer slow other timers) ? Or can it be an other problem ? Is there an option to put in the declaration of the timers which can make them independant from the others ? I coded the timers like it was discussed in this topic : http://arduino.cc/forum/index.php?topic=130423.0Thanks in avance, Gaétan
|
|
|
|
|
13
|
Using Arduino / Sensors / AnalogRead unstable with ColorLCD
|
on: November 30, 2012, 05:30:53 am
|
|
Hello, I just installed ColorLCD from Sparkfun on my Arduino Mega. It works Fine. But when I put a 10 kOhm potentiometer in an analog input (with two border pins connected to ground and 5V), the value is VERY unstable (+30 / -30). And Even if I'm connecting the analog input to the ground (with no potentiometer), the value is varying between 0 and 30 (on 1023), with some kind of cycles. If I disconnect the LCD, the analog values become stable again.
So I think maybe there are some kinds of capacitors (the varying has... constent cycles) in the LCD which are perturbating the inside of Arduino ?? Someone did have the same problem ? Can I add some regulation in the analog input of Arduino ? (like capacitors)
Thank you in advance, and sorry for my poor english.
|
|
|
|
|