Make int array into byte array

Hi there,

I am new to Arduino.

I have 8 octaves. Each octave has 8 keys. How do I free up memory? I would like to change int to byte, however the largest frequency is around 4000. The notes correspond to different frequencies specified here: https://www.arduino.cc/en/Tutorial/toneMelody

int melody1[9] = {
NOTE_C1 , NOTE_D1, NOTE_E1, NOTE_F1, NOTE_G1, NOTE_A1, NOTE_B1, NOTE_C2, 0};
int melody2[9] = {
NOTE_C2 , NOTE_D2, NOTE_E2, NOTE_F2, NOTE_G2, NOTE_A2, NOTE_B2, NOTE_C3, 0};
int melody3[9] = {
NOTE_C3 , NOTE_D3, NOTE_E3, NOTE_F3, NOTE_G3, NOTE_A3, NOTE_B3, NOTE_C4, 0};
int melody4[9] = {
NOTE_C4 , NOTE_D4, NOTE_E4, NOTE_F4, NOTE_G4, NOTE_A4, NOTE_B4, NOTE_C5, 0};
int melody5[9] = {
NOTE_C5 , NOTE_D5, NOTE_E5, NOTE_F5, NOTE_G5, NOTE_A5, NOTE_B5, NOTE_C6, 0};
int melody6[9] = {
NOTE_C6 , NOTE_D6, NOTE_E6, NOTE_F6, NOTE_G6, NOTE_A6, NOTE_B6, NOTE_C7, 0};
int melody7[9] = {
NOTE_C7 , NOTE_D7, NOTE_E7, NOTE_F7, NOTE_G7, NOTE_A7, NOTE_B7, NOTE_C8, 0};
int melody8[9] = {
NOTE_C8 , NOTE_D8, NOTE_E7, NOTE_F7, NOTE_G7, NOTE_A7, NOTE_B7, NOTE_C8,0};

Thank you in advance.

Scale the frequencies to fit in a byte. You will lose a little accuracy. Just right shift, which will be equivalent to a divide by an integer power of 2. If you right shift by 4, the highest frequency you can capture would be 255x16 = 4080.

Thank you for your reply. Sorry I don't understand what you mean. I'm new to programming. Could you please provide an example? Thanks again.

NOTE_C8 4186

mirandamg:
Thank you for your reply. Sorry I don't understand what you mean. I'm new to programming. Could you please provide an example? Thanks again.

NOTE_C8 4186

You told me the highest frequency would be 4000. If you want to scale 4186 to fit a byte, you would divide by 32, which yields 130. To use it later you would scale it back up by multiplying by 32, yielding 4160. Is that clearer?

There is no magical way to fit numbers larger than 255 into a byte without losing accuracy. It's like asking to put an elephant into a bathtub. It can't be done.