mexomagno / arduitunes

Poliphonic chiptune music player. An arduino, a speaker and you're done! Play the presets or make your own.
GNU General Public License v2.0
15 stars 2 forks source link

Arduino IDE errors #2

Closed JeanHenriqueAlves closed 8 years ago

JeanHenriqueAlves commented 8 years ago

Hello, I'm getting various errors when uploading the code to my UNO.

D:\Arditunes\Arditunes.ino:17:0: warning: "_BV" redefined [enabled by default]

define _BV(b) (1 << (b)) //para manejo directo de pins

^

In file included from c:\program files\arduino\hardware\tools\avr\avr\include\avr\io.h:99:0,

             from c:\program files\arduino\hardware\tools\avr\avr\include\avr\pgmspace.h:88,

             from C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:28,

             from sketch\Arditunes.ino.cpp:1:

c:\program files\arduino\hardware\tools\avr\avr\include\avr\sfr_defs.h:208:0: note: this is the location of the previous definition

define _BV(bit) (1 << (bit))

^

Arditunes:70: error: 'prog_char' does not name a type

PROGMEM prog_char voz1[]={

     ^

Arditunes:82: error: 'prog_char' does not name a type

PROGMEM prog_char voz2[]={

     ^

Arditunes:108: error: 'prog_char' does not name a type

PROGMEM prog_char voz3[]={

     ^

Arditunes:128: error: 'prog_char' does not name a type

PROGMEM prog_char voz4[]={

     ^

Arditunes:130: error: 'prog_char' does not name a type

PROGMEM prog_char voz5[]={

     ^

Arditunes:154: error: variable 'voces' must be const in order to be put into read-only section by means of 'attribute((progmem))'

PROGMEM const char* voces[]={voz1,voz2,voz3,voz4,voz5};

                       ^

Arditunes:154: error: 'voz1' was not declared in this scope

PROGMEM const char* voces[]={voz1,voz2,voz3,voz4,voz5};

                          ^

Arditunes:154: error: 'voz2' was not declared in this scope

PROGMEM const char* voces[]={voz1,voz2,voz3,voz4,voz5};

                               ^

Arditunes:154: error: 'voz3' was not declared in this scope

PROGMEM const char* voces[]={voz1,voz2,voz3,voz4,voz5};

                                    ^

Arditunes:154: error: 'voz4' was not declared in this scope

PROGMEM const char* voces[]={voz1,voz2,voz3,voz4,voz5};

                                         ^

Arditunes:154: error: 'voz5' was not declared in this scope

PROGMEM const char* voces[]={voz1,voz2,voz3,voz4,voz5};

                                              ^

Arditunes:171: error: 'prog_uint16_t' does not name a type

prog_uint16_t NOTAS[] PROGMEM={31,/C1/33,35,37,39,41,44,46,49,52,55,58, //12

^

In file included from C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:28:0,

             from sketch\Arditunes.ino.cpp:1:

D:\Arditunes\Arditunes.ino: In function 'void initNotas_p()':

Arditunes:212: error: 'NOTAS' was not declared in this scope

 int progint2int=pgm_read_word_near(NOTAS + parseNota(nota[i]));//NOTAS[parseNota(nota[i])];//

                                    ^

D:\Arditunes\Arditunes.ino: In function 'void getNext(char)':

Arditunes:383: error: 'prog_char' was not declared in this scope

 PGM_P prog_str=(prog_char*)pgm_read_word(&(voces[voz]));

                 ^

Arditunes:383: error: expected primary-expression before ')' token

 PGM_P prog_str=(prog_char*)pgm_read_word(&(voces[voz]));

                           ^

exit status 1 'prog_char' does not name a type

Did I miss something?

mexomagno commented 8 years ago

I'm so sorry for not having seen this before. I think all these errors might have to do with the version of Arduino IDE you're using. I don't know how the new ides work and what they import before. At the time I programmed this, I was using Arduino IDE 1.0.5. Could you please try compiling with that version? If you already fixed this, could you share how? I repeat my apologies, I'll now be more attentive. Cheers!

mexomagno commented 8 years ago

__BV (b) (1 << (b))_ I think they now include this function. I had to define it myself before. As they use the exact same definition, it should be safe to remove it and use the now built in instead.

_prog_char | prog_uint16 was not declared in this scope_ I think this answers why that is happening to you

The rest of the errors seem to be directly related to both of the previous errors.

If you still are interested on making this project work, please comment your results :) Cheers

JeanHenriqueAlves commented 8 years ago

Hello Max, thanks for the reply, but I closed this issue because I managed to fix the code. As you said, I removed the _BV funcion. Other changes I did to the code were:

PROGMEM prog_char voz1[]={SONG}; >>>
const char voz1[] PROGMEM = {SONG};

PROGMEM const char* voces[]={voz1,voz2,voz3,voz4,voz5}; >>> const char* const voces[] PROGMEM = {voz1,voz2,voz3,voz4,voz5};

prog_uint16_t NOTAS[] PROGMEM= >>> const uint16_t NOTAS[] PROGMEM=

PGM_P prog_str=(progchar)pgm_read_word(&(voces[voz])); >>> PGM_P progstr=(const char)pgm_read_word(&(voces[voz]));

After I did these changes, the code ran mostly without any issues, just some minor random lags but that must be because of all the songs being commented out stored on the RAM. The only major issues I found is that the code is not able to play notes lower than G2 (any note lower than that sounds completely off pitch), and the notes around B6-C#7 sounds a bit off pitch too but I have not tested with notes higher than that.

Your web app is fairly good for small songs but not for large ones, so I would like to suggest a tool/web app to convert MIDI files to the song language used in your code and also add a percussion channel like the Bassdll from drewcrawford (https://github.com/drewcrawford/bassdll/). That would make your code an excellent chiptune player. I have used a site to convert MIDI to RTTTL then did some changes using notepad and have sucessfully made some more songs, but it takes lots of work to make a song without any errors. Also, allowing dotted notes and rests on the code would help a lot.

mexomagno commented 8 years ago

Thanks for the heads up, Jean. I'm very happy that you managed to make it work :D Did you like the tunes? The super mario theme was directly typed in, no web app!

When I first did this project, the main motivation was to achieve polyphonic sounds (I bought my first arduino with this in mind! If I had only known what I was getting myself into... haha), which I did. The very simple web app I coded was a way to make it somehow more usable for other people. It's clear that this can be greatly improved (midi support, better webapp, different waveforms-sounds, improved musical correctness, decent hardware mixing...), but for now I don't have any plans on doing that as I am currently very busy.

I think MIDI is definitely the way to go, and if you really want to keep working on this, please do! Just don't forget to mention my original work :)

About the pitch correctness, there was a sad tradeoff between pitch precision and enough time to run the interruption. I believe the lowest pitch is limited by the Timer 2 counter size. The secret is in the mcd variable which is used to configure the Timer 2 time interruption count. Try changing it's value and see what happens. It's value of 20 was empirically determined, based on the aforementioned tradeoff. Lower values hanged everything up, higher values led to out-of-tune notes.

If you really really want to know exactly what's happening, I reccomend you read the project that guided the development of mine if you haven't already seen it. Also, If you want I can translate my spanish code comments to english and upload it.

Cheers, Jean!

JeanHenriqueAlves commented 8 years ago

Yes, I liked them a lot, specially the pokémon trainer battle song. Some of the songs I managed to make using the method I mentioned before were the gym leader battle (RBY), wild pokémon battle (also RBY) and the Celebrated Chop Waltz (Chopsticks).

As I learn more about coding I'm going to improve your code and add some more features like MIDI IN, a percussion track through pulse-code modulation, etc, and try to fix the limitations you mentioned.

I bet you spent too many hours working on it, and you did a really good job. Thank you for starting this project, it's awesome. Too bad it seems that not many people know it.

mexomagno commented 8 years ago

I'm glad you liked them and the project.

When I bought my first Arduino Uno, I was already thinking on doing something like this. I just wasn't aware of what I was getting myself into. I jumped straight from making a blinking led to modifying the chip's configuration bits. But my programming background was good and I didn't have to spend too much time (like a week or so), but I did learn a lot and had a great time!

Your plans seem like a lot of fun. Will you use this same repo (a new branch maybe)? Keep me updated!

Cheers.