Recent

Author Topic: Play music tones  (Read 285 times)

tygraphics

  • New member
  • *
  • Posts: 6
Play music tones
« on: June 05, 2020, 08:25:56 pm »
In some of my pascal code from 25 years ago I used: note(440, AMP, DURATION);
Is there an something comperable in FPC?

Fred vS

  • Hero Member
  • *****
  • Posts: 1798
    • StrumPract is the musicians best friend
Re: Play music tones
« Reply #1 on: June 05, 2020, 08:34:48 pm »
Hello.

With uos you may use his build-in synthesizer.

   
Code: Pascal  [Select][+][-]
  1. procedure uos_InputSetSynth(PlayerIndex: cint32; InputIndex: cint32; Frequency: float;
  2.  VolumeL: float; VolumeR: float; Duration: cint32; Enable : boolean);
  3. // Frequency : in Hertz (-1 = do not change)
  4. // VolumeL :  from 0 to 1 (-1 = do not change)
  5. // VolumeR :  from 0 to 1 (-1 = do not change)
  6. // Duration : in msec (-1 = do not change)
  7. // Enabled : true or false ;
  8.  

Example:
Code: Pascal  [Select][+][-]
  1. uos_InputSetSynth(PlayerIndex1,inindex1, 440, 0.2,1, -1 ,true);


There is a console demo too:

https://github.com/fredvs/uos/blob/master/examples/consolesynth.pas
« Last Edit: June 05, 2020, 08:42:58 pm by Fred vS »
I use Lazarus 2.0.6 32/64 and FPC 3.2.0 32/64 on Debian 10.2 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs
https://gitlab.com/fredvs

tygraphics

  • New member
  • *
  • Posts: 6
Re: Play music tones
« Reply #2 on: June 05, 2020, 08:43:52 pm »
Thanks Fred!

Fred vS

  • Hero Member
  • *****
  • Posts: 1798
    • StrumPract is the musicians best friend
Re: Play music tones
« Reply #3 on: June 05, 2020, 08:49:21 pm »
Re-hello.

You may also use the pre-defined tones:

Code: Pascal  [Select][+][-]
  1. const // musical note ==> frequency in hertz
  2. la0  = 55.0;
  3. la0_d = 58.3;
  4. si0 = 61.7;
  5. do0 =  65.4;
  6. do0_d = 69.3;
  7. re0 = 73.4;
  8. re0_d =77.8;
  9. mi0  =82.4;
  10. fa0  = 87.3;
  11. fa0_d = 92.5;
  12. sol0 = 98.0;
  13. sol0_d = 103.8;
  14. la1  = 110.0;
  15. la1_d = 116.5;
  16. si1 = 123.5;
  17. do1 =  130.8;
  18. do1_d = 138.6;
  19. re1 = 146.8;
  20. re1_d =155.6;
  21. mi1  =164.8;
  22. fa1  = 174.6;
  23. fa1_d = 185.0;
  24. sol1 = 196.0;
  25. sol1_d = 207.7;
  26. la2 = 220.0;
  27. la2_d = 233.1;
  28. si2 = 2246.9;
  29. do2 =  261.6;
  30. do2_d = 277.2;
  31. re2 = 293.7;
  32. re2_d =311.1;
  33. mi2  =329.6;
  34. fa2  = 349.2;
  35. fa2_d = 370.0;
  36. sol2 = 392.0;
  37. sol2_d = 415.3;
  38. la3  = 440.0;
  39. la3_d = 466.2;
  40. si3 = 493.9;
  41. do3 =  523.3;
  42. do3_d = 554.4;
  43. re3 = 587.3;
  44. re3_d = 622.3;
  45. mi3 = 659.3;
  46. fa3  = 698.5;
  47. fa3_d = 740.0;
  48. sol3 = 784.0;
  49. sol3_d = 830.6;
  50. la4 = 880.0;
  51. la4_d = 932.4;
  52. si4 = 987.8;
  53. do4 =  1046.6;
  54. do4_d = 1108.8;
  55. re4 = 1174.6;
  56. re4_d = 1244.6;
  57. mi4 = 1318.6;
  58. fa4  = 1397.0;
  59. fa4_d = 1480.0;
  60. sol4 = 1568.0;
  61. sol4_d = 1661.2;
  62. la5 = 1760.0;



I use Lazarus 2.0.6 32/64 and FPC 3.2.0 32/64 on Debian 10.2 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs
https://gitlab.com/fredvs

 

TinyPortal © 2005-2018