Problem with sound [Partially solved + includes a simple piano]

@Crumble that’s what I thought, but if you have your baseline sound file recorded at a set pitch (say middle c) then the pitch command should be fairly straightforward to use to create the instrument. I’ve given up on the generator for the moment as it seems to introduce lag and glitches when used in the above type applications (probably to do with the length of samples - perhaps the decay on them)

@West That’s a good idea! I was going to record each note in garageband on a single track then drop onto computer and chop them in audacity into individual sound files then import to Codea. Would be a lot easier to use one note, then adjust the pitch. Going to give it a shot, hopefully pitch adjustment doesn’t lag like sound generation does.

@Crumble - this is demonstrated in the last example I posted - just add your sound file to the instrument table. Change the octaveshift parameter to shift the range if it’s too high/low

@West I plan to use the diatonic scale of E harmonic minor, covering 3 octaves. The octave shift function you made will definitely be help with the multiple octaves. Think I’ll record the 7 notes in the middle octave, then use your octave shift function to shift the scale higher or lower, if you don’t mind me using it.

Edit: haven’t been on my iPad, just tried out your sample, that is a sweet little piano you made. I’m not seeing where you are adjusting the pitch to individual notes. The code inside of the touched function? Or is the octave shift function doing that as well?

@Crumble the getPitch() function deals with it.

The sound() function takes the pitch as the second parameter. A value of 1 is the baseline value. A value of 2 shifts it by one octave and a value of 4 shifts it by 2 octaves. Similarly a value of 0.5 shifts down by an octave and 0.25 down by 2 octaves. (1=2^0, 2=2^1, 4=2^2 and 0.5=2^-1, 0.25=2^-2). There are 12 notes in an octave so each note in the binary log scale is separated by 1/12.

For example

If the note C is your baseline then the pitch value is 2^0.

The next note C# has the pitch value of 2^(1/12)

The next note D has the pitch value of 2^(2/12) and so on

Therefore notes can be fed in as whole numbers tothe getPitch function, hence why the songs are just arrays of integers.

I think this is right, but am willing to be better educated on this!

Hope this makes sense?

@West Yep, sounds like the way an equal temperament scale works.

how to make a song like?1,2,3??if a note with 1/16 beat?if use midi file?

@firewolf
{1,2,3} equates to C,C#,D and you’d add it like:

  table.insert(songlist,{song={1,2,3},name="firewolf"})

Adjust tempo to get the beat you want, and use 0 notes to pad with rests

I don’t think midi is supported

i mean how to make it for any song in the simplest way?

I don’t understand your question @firewolf

how to make the specific new song like your 3 songs in the simplest way?

@firewolf - the way I posted above is the easiest way (at the moment)

Take your song and convert each note into the equivalent number.

For example - taking Twinkle Twinkle Little Star:
http://www.guitarnick.com/images/twinkle-twinkle-little-star-guitar-beginners-sheet.png

The first seven notes are:
G,G,D,D,E,E,D

which maps across to
8,8,15,15,17,17,15

Note that the last D is double the length of the other notes, so follow it with a rest (0):

8,8,15,15,17,17,15,0,13,13,12,12,10,10,8,0

For this particular song, the quickest note is a crotchet (a quarter of a bar)

In practice you may want to put spaces between each note and adjust the tempo, to allow you to have quicker notes

8,0,8,0,15,0,15,0,17,0,17,0,15,0,0,0,13,0,13,0,12,0,12,0,10,0,10,0,8,0,0,0

so, to insert the song, add the following line

table.insert(songlist,{song={8,0,8,0,15,0,15,0,17,0,17,0,15,0,0,0,13,0,13,0,12,0,12,0,10,0,10,0,8,0,0,0},name="Twinkle Twinkle Little Star"})

Hope this helps

i understand it, thanks.

very nice job @West

Cheers @Jmv38

If the note C is your baseline then the pitch value is 2^0.

The next note C# has the pitch value of 2^(1/12)

The next note D has the pitch value of 2^(2/12) and so on
are they accurate pithch values for instruments? how to deal with bass staff’s notes? how to make baseline sound file for an instrument?

You would change pitch variable to 0.5 I believe. pitch=1 in setup.

An iPad will not be able to reproduce low tones very well, speakers are just too small.

The below code looks like it uses the pitch variable from setup.

--a pitch of 1 is the base pitch of the sound.
--a pitch of 2 is one octave higher
--a pitch of 0.5 is one octave lower
sound(instrument[currentinstrument].inst,1.0,pitch,0.0,false)

how about use songs’ sql data or another way like this?

120,4/4,0

-:2
C4:3/8 D4:1/8 E4:3/8 C4:1/8 
E4:1/4 C4:1/4 E4:1/2
D4:3/8 E4:1/8 F4:1/8 F4:1/8 E4:1/8 D4:1/8 
F4:1/2 -:1/2

E4:3/8 F4:1/8 G4:3/8 E4:1/8 
G4:1/4 E4:1/4 G4:1/2
F4:3/8 G4:1/8 A4:1/8 A4:1/8 G4:1/8 F4:1/8 
A4:1/2 -:1/2

G4:3/8 C4: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 F4:1/2 B4:1/2 G4:1/2 
C5:1/2 -:3/2
C5:1/4 G4:1/4 C4:1/2

No reason why you couldn’t write a function which would parse the above function into the equivalent table plus variables.

Is this a standard song file format? Are there open source resources with lots of songs already provided in this format? If so could you provide some links please?

One immediate simple step towards this would be to set up a series of constants at the start and map the values directly across.

E.g.

C3=1
Db3=2
D3=3
table.insert(songlist,{song={C3,Db3,D3},name="test"})

You would need to ensure all the sharp notes were referenced by their equivalent flat notes as you can’t use # in the name of a constant

this is a standard song file format, maybe theres a better way, they’re not open source, but i could find some.