LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-14-2010, 06:31 AM   #1
kjaer
LQ Newbie
 
Registered: Jan 2006
Posts: 2

Rep: Reputation: 0
Playing piano from the terminal


Hi guys.

In short, what I want to achieve is this:
echo "a b c a" | piano.sh
And hear it, like it was played on a piano.
As you can see, I really would like to keep it simple, it is for a school project, and this is a minor but important thing. I am getting the data from the serial port and that part is working.
I have been looking at software synthesizers etc. but again, I want it to be simple. :-)

Has anyone done anything similar or related to this? Is it at all possible?

Best regards
Kresten
 
Old 10-14-2010, 03:41 PM   #2
mpagnan
Member
 
Registered: Apr 2003
Location: Canada
Distribution: Mint KDE 18.2
Posts: 33

Rep: Reputation: 5
The sound card drivers direct a sound card on what sounds/notes to play. So, you need to program something that will send the right instruction for each note to the sound card driver. You will need more than a script. The only sound that script languages like bash have been programmed to play is the monotone "beep". I am not sure whether an Amarok script will do what you need. A "how to" is at http://amarok.kde.org/wiki/Script-Wr...o#Introduction
 
Old 10-14-2010, 11:34 PM   #3
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Bookworm (Fluxbox WM)
Posts: 1,391
Blog Entries: 54

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
Quote:
Originally Posted by kjaer View Post
In short, what I want to achieve is this:
echo "a b c a" | piano.sh
It depends how much programming you want to do (and which language).

One way would be to generate midi notes; for example, in Python you could use a module such as pyfluidsynth, or even generate midi events directly from the incoming note list.

A quick and ugly way would be to create a whole lot of mp3 files with the different notes, and then use a shell script to run mpg321 on the ones that match the notes coming in!
 
Old 10-14-2010, 11:48 PM   #4
x111
Member
 
Registered: Jul 2010
Distribution: Slackware
Posts: 49

Rep: Reputation: 7
Quote:
Originally Posted by neonsignal View Post
It depends how much programming you want to do (and which language).

One way would be to generate midi notes; for example, in Python you could use a module such as pyfluidsynth, or even generate midi events directly from the incoming note list.

A quick and ugly way would be to create a whole lot of mp3 files with the different notes, and then use a shell script to run mpg321 on the ones that match the notes coming in!
An interesting idea, for a console.
The use of MIDI is a traditional way, but I think if you can manage to somehow "mix" the sound of the mp3 notes (using PulseAudio or something like that), it will be much more real. The sound of MIDI notes is rather flat, you know.

I'm no expert on programming and sound stuff, but an enthusiast of music and the console . Please keep posting the result of your work here.
 
Old 10-15-2010, 01:20 AM   #5
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Bookworm (Fluxbox WM)
Posts: 1,391
Blog Entries: 54

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
Just for fun, you can also use SoX to play notes in a script, taking notes on the standard input (separated by spaces or lf):
Code:
#!/bin/bash
while read -e input
do
   for i in $input
   do
      play -q -n synth 3 pluck %$(expr index aabccddeffgg $i - 1) &
      sleep 0.5
   done
done

Last edited by neonsignal; 10-15-2010 at 01:34 AM. Reason: forgot to put in semitone spacing
 
Old 10-15-2010, 07:21 AM   #6
mpagnan
Member
 
Registered: Apr 2003
Location: Canada
Distribution: Mint KDE 18.2
Posts: 33

Rep: Reputation: 5
neonsignal,
Thanks for that. I do not know how after many years I missed SoX, that I now find is a standard offering of many Linux / Unix distributions.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
playing audio files via terminal jone kim Linux - General 7 05-21-2010 08:35 PM
creating a custom roll up Piano: can I connect 2 type-keyboards via USB? browny_amiga Linux - Hardware 1 11-27-2008 09:27 AM
LXer: Digital piano adds Linux LXer Syndicated Linux News 0 09-26-2008 01:40 PM
terminal arrow keys not playing nice madivad Solaris / OpenSolaris 4 03-11-2008 08:35 PM
Totem playing off of network, Xine playing local iammike Ubuntu 0 04-30-2005 11:43 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration