Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Piano on your keyboard

Author
Message
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 11th May 2010 22:28 Edited at: 12th May 2010 18:37
Many people cannot afford musical instruments although they might want to play one. My aim for this project is to turn a PC keyboard into a piano.

I've mapped the keys in a zig-zag order which at first looks rather odd - like a twisted piano keyboard - but this allows for many more keys than a layout that appears more traditional and is not a difficult adjustment for the player. My mapping allows for a total of 44 keys, not bad considering that's exactly half as many as the 88 keys on a grand piano.


Here is my program so far:
You'll need to download my ding.wav to run, or replace it with one of your own sounds.
[UPDATED]


I've run into two problems that I need help with.

1. I'm having trouble getting the note frequencies right, is there a formula for working these out or a reference somewhere that has lots of frequencies. I could only find frequencies for one scale.

2. When pressing some keys together nothing happens. Is there a work-around so that all keys can be pressed at the same time?

Does anyone know of a site where you can download instrument sounds?

Attachments

Login to view attachments
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 11th May 2010 23:26
One of the tricks here if you are using samples, is that the pitch frequency has already been determined by whatever was recorded. The notes that are reproduced are going to be influenced by the sample rate: SET SOUND SPEED. If you had sampled a tone at 440 hz (Concert A) and it was recorded at a sample rate of 44100 hz then when the sound speed in DBC is 44100, the tone will be reproduced properly. 1 octave above would be twice the speed - 88200 . 1 octave below, half the speed 22050 .

Take a look at this thread:

Guitar Sounds

It gets into the detail of what I'm talking about.

Enjoy your day.
TheComet
16
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 12th May 2010 09:56
Quote: "1 octave above would be twice the speed - 88200 . 1 octave below, half the speed 22050 ."


I thought our ears work logarithmic, not linear...

TheComet

Dia
19
Years of Service
User Offline
Joined: 16th Jan 2005
Location:
Posted: 12th May 2010 14:03 Edited at: 12th May 2010 14:04
....that IS logarithmic (or exponential, it depends which way you look at it ) each octave up doubles freq, each octave down halves the freq

i.e. 11025 - 22050 - 44100 - 88200 - etc etc etc


linear would be if each octave increase the freq by a flat 44100

i.e. 0 - 44100 - 88200 - 132300

This is not the Sig you are looking for....
TheComet
16
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 12th May 2010 14:13
Oh, my mistake Wasn't thinking...

TheComet

Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 12th May 2010 17:56 Edited at: 12th May 2010 18:24
Thanks Latch I've got all the keys working now.
Any ideas on how to overcome the multiple key press problem?

UPDATED CODE IN OP

Robert The Robot
17
Years of Service
User Offline
Joined: 8th Jan 2007
Location: Fireball XL5
Posted: 13th May 2010 12:02
I don't think you can overome it - it's a failing of your keyboard, rather than your code. The problem was deatiled in an article - I forget who by, but I can't find it right now - I'll upload a copy later).

Basically, when you press a single ky you close a switch and the keyboard wiring tells it which one it was. Press multiple switches, though, and the keyboard could "short-circuit" - certain combinations don't trigger the keys you pressed, but another key nearby.

To overcome this problem, the keyboard can either transmit wrong data, or more likely will recognise the possibility of a short-circuit and simply not send any data at all.

"I wish I was a spaceman, the fastest guy alive. I'd fly you round the universe, in Fireball XL5..."
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 14th May 2010 01:03
In other words, you need a fancy "gaming" keyboard to allow the larger number of simultaneous key presses that you're looking for.


"Any sufficiently advanced technology is indistinguishable from magic" ~ Arthur C. Clarke
Robert The Robot
17
Years of Service
User Offline
Joined: 8th Jan 2007
Location: Fireball XL5
Posted: 14th May 2010 16:13
Bluntly, yes...

Oh, and here's the article I mentioned - it's quite interesting actually!

"I wish I was a spaceman, the fastest guy alive. I'd fly you round the universe, in Fireball XL5..."

Attachments

Login to view attachments
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 15th May 2010 07:05
that was interesting. Looks like I'm out of luck though

Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 15th May 2010 21:08
Quote: "Looks like I'm out of luck though"

Not necessarily. It's true that you might run into trouble by pressing 10 keys on the keyboard at once, but even the cheapest keyboard is setup to at least handle 2 keys at once. And if a combination triggers another key, so what.

A possible solution is to make a rotating list of key presses. Say you limit your keyboard to 4 keys at once, when any 4 keys are down at the same time, either a new key cannot be sounded until one of the others is released, or the first key pressed is automatically released when the new key is pressed.

And, just for familiarity's sake, most virtual keyboards are arranged like a piano keyboard starting at Q=C 2=C# W=D etc. It may be nice to have the option of this more common standard.

Enjoy your day.

Login to post a reply

Server time is: 2024-04-26 04:25:37
Your offset time is: 2024-04-26 04:25:37