views:

819

answers:

6

I wanna know how can I create sounds in LINUX with different frequencies using C++ libraries ? Is there any library for audio programming ( specially creating sounds with different freqs ) in C++ ?

How can I simulate piano and other musical instruments(MIDI) sounds using C++.

[EDIT] for example I want to create A Major with different sounds ( Violin, Piano, Guitar etc. )

I want to write something like this function:

void playNote( char type, double freq )

for example the A note below middle C is at 220 Hz. Middle C is at about 262 Hz (261.6).

so this should play Middle C for the Piano: ( 'P' means Piano for example )

playNote( 'P',  261.6 );

NOW , I want to know is there any library that could help me playing with notes and freqs ?

(I'm using G++ in Ubuntu 9.10 (Karmic Koala))

A: 

A quick googling gave following link where the same has been discussed. http://www.daniweb.com/forums/thread15252.html#

Hope it helps.

Andy
thanks for the link but I'm using Ubuntu Linux. ( I Google before asking on SO )
Michel Kogan
+3  A: 

OpenAL and FMOD are two popular libraries which can simulate waveforms.

ALUT (part of OpenAL) has a function...

ALuint alutCreateBufferWaveform (ALenum waveshape,
                                 ALfloat frequency,
                                 ALfloat phase,
                                 ALfloat duration);

However, for simulating musical instruments you will need a library that can handle MIDI information. The MIDI format stores data as musical notes. There should be a number of good libraries that can handle MIDI which would make it easy to simulate instruments.

Pace
How can I simulate piano and other musical instruments sounds using OpenAL ( for example simulate violin sound in all frequencies ) ?
Michel Kogan
I think OpenAL is not the right tool for my purpose. Am I right ?
Michel Kogan
You're right. Once again I didn't read the entire question before answering! I've updated with some information on MIDI which might be the best approach.
Pace
Are you looking for your application to receive MIDI information and generate the audio, like receive a "C Major" and generate the right waveforms corresponding to a piano playing a C Major, or are you looking for your application to send Note information "C, D, E#" to an API and have some other code generate the actual sounds?
bdk
Check the question again, I changed it :)
Michel Kogan
+2  A: 

You could try using csound it's a little hard to understand but you can simulate any instrument you want and you can use csound API in C++.

fn
I'l try this as soon as I came back home.
Michel Kogan
Thanks, csound is a good stuff but I think it's not good for my purpose. check the question again please :)
Michel Kogan
Actually, this will do what you want. There is a C++ interface (csound.hpp) that can call any of the CSound stuff. So you can easily write a playNote function doing what you described once you've got the library figured out.
Pace
I'm working on it. Thanks @fn :)
Michel Kogan
+2  A: 

I think C++ is not suitable language for your purpose, use Python instead. take a look at this link. Use csound API for Python.

linker
Thank you, I'm working on C++ API. But, I will think about your idea ;)
Michel Kogan
+1  A: 

For something very simple indeed (to start and stop a tone at a particular frequency), there's libbeep!

For a demo of this,

$ apt-get install beep

and try out the beep program.

+1  A: 

The Synthesis ToolKit would be a good starting point:

https://ccrma.stanford.edu/software/stk/

datageist