chiaro che non e nulla di ottimizzato, pero funzia!
se poi vai sul sito di audiere ce la descrizione di tutte le funzioni (puoi far suonare persino il rumore bianco, i file mp3 etc)
Codice PHP:
#include <cstdlib>
#include <iostream>
#include <windows.h>
#include <time.h>
#include <conio.h>
#include "audiere.h"
void wait ( float seconds );
using namespace audiere;
using namespace std;
int main(int argc, char *argv[])
{
int i;
char musicfilename[100],c;
cout << "Tastiera musicale, le note vanno dal Do al Do successivo"<<endl;
cout << "Premi dalla 'a' alla 'k', 'e' se vuoi uscire dal programma "<<endl;
AudioDevicePtr device(OpenDevice()); //apre un device
SampleSourcePtr Do (CreateTone(261.6)); // qui creo vari toni a frequenza diverse
SampleSourcePtr Re (CreateTone(293.7));
SampleSourcePtr Mi (CreateTone(329.7));
SampleSourcePtr Fa (CreateTone(349.2));
SampleSourcePtr Sol (CreateTone(392));
SampleSourcePtr La (CreateTone(440));
SampleSourcePtr Si (CreateTone(493));
SampleSourcePtr DoS (CreateTone(523.3));
OutputStreamPtr Do1(OpenSound(device,Do,true)); // qua si creano le varie note associandole ai toni prima creati
OutputStreamPtr Re1(OpenSound(device,Re,true));
OutputStreamPtr Mi1(OpenSound(device,Mi,true));
OutputStreamPtr Fa1(OpenSound(device,Fa,true));
OutputStreamPtr Sol1(OpenSound(device,Sol,true));
OutputStreamPtr La1(OpenSound(device,La,true));
OutputStreamPtr Si1(OpenSound(device,Si,true));
OutputStreamPtr DoS1(OpenSound(device,DoS,true));
c=getch();
while(c!='e')
{
switch(c)
{
case 'a':
Do1->play(); // play fa suonare gli output stream che hai definito prima
wait(0.1);
Do1->stop();
break;
case 's':
Re1->play();
wait(0.1);
Re1->stop();
break;
case 'd':
Mi1->play();
wait(0.1);
Mi1->stop();
break;
case 'f':
Fa1->play();
wait(0.1);
Fa1->stop();
break;
case 'g':
Sol1->play();
wait(0.1);
Sol1->stop();
break;
case 'h':
La1->play();
wait(0.1);
La1->stop();
break;
case 'j':
Si1->play();
wait(0.1);
Si1->stop();
break;
case 'k':
DoS1->play();
wait(0.1);
DoS1->stop();
break;
}
c=getch();
}
system("PAUSE");
return EXIT_SUCCESS;
}
void wait ( float seconds )
{
float endwait;
endwait = clock () + seconds * CLK_TCK ;
while (clock() < endwait) {}
}