Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1.  
  2. /*
  3.  * Author: JohnXenox aka Aleksandr Igorevich.
  4.  *
  5.  * Programme name: PlayNote
  6.  * Description: The programme to play a note.
  7.  *
  8.  * Works from command line, only!
  9. */
  10.  
  11. // To generate .wav file with sox (to listen):
  12. //  sox -n -L -c 1 -b 16 -r 48000 Note_C5.wav synth 1 sine 1046.4
  13. // To generate .raw file with sox (to PlayNote):
  14. //  sox -n -L -c 1 -b 16 -r 48000 Note_C5.raw synth 1 sine 1046.4
  15.  
  16. #define CREATION_DATE "2020.05.17"
  17.  
  18. #include <conio.h>
  19. #include <stdio.h>
  20. #include <string.h>
  21.  
  22. #include "PlayNote_lib1.h"
  23. #include "PlayNote_lib2.h"
  24.  
  25.  
  26. unsigned int drv_ver = 0;
  27. unsigned int buffer = 0;
  28.  
  29. unsigned int *raw_file_data = 0;
  30.  
  31. char raw_file[4096] = {0};
  32.  
  33.  
  34.  
  35. int main(int argc, char** argv)
  36. {
  37. // ============================================================ //
  38. // checks memory availability ================================= //
  39.  
  40.     if(initMemory() == 0) return -1;
  41.  
  42. // ============================================================ //
  43. // sets a current path to a raw file ========================== //
  44.  
  45.     //setCurrentPathToARawFile(raw_file, argv[0], "Note_C6_0.5.raw");
  46.  
  47. _ksys_set_wanted_events(0);
  48.  
  49. // ============================================================ //
  50. // processes the command line arguments ======================= //
  51.  
  52.     if (argc > 1)
  53.     {
  54.         //printfOnADebugBoard("ARGV1: %s\n", argv[1]);
  55.         strcpy(raw_file, argv[1]);
  56.  
  57.         // checks to a full path to a file?
  58.         if(*argv[1] != '/')
  59.         {
  60.             setCurrentPathToARawFile(raw_file, argv[0], argv[1]);
  61.         }
  62.     }
  63.     else
  64.     {
  65.         if (con_init_console_dll()) return 1; // init fail
  66.  
  67.         con_set_title("Useful info!");
  68.  
  69.         con_printf("\n Name: PlayNote");
  70.         con_printf("\n Date: %s", CREATION_DATE);
  71.         con_printf("\n Description: The programme to play a note.\n");
  72.  
  73.         con_printf("\n Author: JohnXenox\n");
  74.  
  75.         con_printf("\n Usage: PlayNote <path>\n");
  76.         con_printf("  path - path to a file to be played.\n\n");
  77.  
  78.         con_printf(" Examples:\n");
  79.         con_printf("  PlayNote note.raw\n");
  80.         con_printf("  PlayNote /tmp0/1/note.raw\n");
  81.  
  82.         return 0;
  83.     }
  84.  
  85.     //printfOnADebugBoard("raw_file path: %s\n", argv[1]);
  86.  
  87. // ============================================================ //
  88. // plays a note =============================================== //
  89.  
  90.     int raw_file_length = 0;
  91.     raw_file_data = openFile(&raw_file_length,raw_file);
  92.     if(raw_file_data == 0) return -2;
  93.  
  94.     _InitSound(&drv_ver);
  95.     _CreateBuffer((PCM_STATIC | PCM_1_16_48), raw_file_length, &buffer);
  96.     _SetBuffer((int*)buffer, (int*)raw_file_data, 0, raw_file_length);
  97.     _SetBufferPos((int*)buffer, 0);
  98.  
  99.     _PlayBuffer((int*)buffer, 0);
  100.  
  101.     makeDelay(30);
  102.  
  103.     _StopBuffer((int*)buffer);
  104.  
  105.     return 0;
  106. }
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.