Guest User

New code

a guest
Aug 27th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #include <stdio.h>
  3. #include <iostream>
  4. #include "include\bass.h"
  5. #include "include\bass_fx.h"
  6. #include <Windows.h>
  7. #include <string>
  8. #include "main.h"
  9.  
  10. #define string std::string
  11.  
  12. HRECORD recordingChan;
  13. HSTREAM playbackChan;
  14. DWORD effectChan;
  15. int prevState= 1;
  16.  
  17. void Error(string msg) {
  18.     string err = msg + ": Error code " + std::to_string(BASS_ErrorGetCode());
  19.     ::MessageBox(0, err.c_str(), "Error", MB_OK);
  20. }
  21. inline int quit() {
  22.     BASS_RecordFree();
  23.     BASS_Free();
  24.     while (true) {
  25.         if (GetAsyncKeyState(VK_ESCAPE) & 0x8000) {
  26.             return 0;
  27.         }
  28.     }
  29.  
  30. }
  31. int i = 0;
  32. BOOL CALLBACK MyRecordProc(HRECORD handle, const void *buffer, DWORD length, void *user) {
  33.     if (BASS_StreamPutData(playbackChan, buffer, length)==-1) {
  34.         Error("Cannot push to stream");
  35.         return FALSE;
  36.     }
  37.     if (!BASS_ChannelPlay(playbackChan, false)) {
  38.         Error("Cannot play stream");
  39.         return FALSE;
  40.     }
  41.  
  42.     return TRUE;
  43. }
  44. void clear() {
  45.     COORD topLeft = { 0, 0 };
  46.     HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
  47.     CONSOLE_SCREEN_BUFFER_INFO screen;
  48.     DWORD written;
  49.  
  50.     GetConsoleScreenBufferInfo(console, &screen);
  51.     FillConsoleOutputCharacterA(
  52.         console, ' ', screen.dwSize.X * screen.dwSize.Y, topLeft, &written
  53.     );
  54.     FillConsoleOutputAttribute(
  55.         console, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE,
  56.         screen.dwSize.X * screen.dwSize.Y, topLeft, &written
  57.     );
  58.     SetConsoleCursorPosition(console, topLeft);
  59. }
  60. int main() {
  61.     if (!BASS_Init(-1, 44100, BASS_DEVICE_LATENCY, 0, NULL)) {
  62.         Error("Cannot initialize output device.");
  63.         return quit();
  64.     }
  65.     DWORD loadingSound = BASS_StreamCreateFile(FALSE, "loading.wav", 0, 0, BASS_SAMPLE_FLOAT);
  66.     if (!loadingSound) {
  67.         Error("Cannot create loading sound.");
  68.         return quit();
  69.     }
  70.  
  71.  
  72.     //BASS_ChannelPlay(loadingSound, FALSE);
  73.     BASS_DEVICEINFO dInfo;
  74.     BASS_SetConfig(BASS_CONFIG_VISTA_TRUEPOS, false);// allows lower latency on Vista and newer with the drawback of
  75.                                                      //position reporting accuracy
  76.     int count = 0;
  77.     while (BASS_RecordGetDeviceInfo(count, &dInfo)) {
  78.         count++;
  79.         printf("Device #%d, ", count);
  80.         std::cout << "name: " << dInfo.name;
  81.         //std::cout << "driver: " << dInfo.driver;
  82.         std::cout << (dInfo.flags&BASS_DEVICE_ENABLED ? "enabled" : "disabled") << ", ";
  83.         std::cout << (dInfo.flags&BASS_DEVICE_DEFAULT ? "default device" : "") << ", ";
  84.         //what type of device is it?
  85.         switch ((dInfo.flags&BASS_DEVICE_TYPE_MASK))
  86.         {
  87.         case BASS_DEVICE_TYPE_DIGITAL:
  88.         {
  89.             printf("device is a digital interface."); break;
  90.  
  91.         }
  92.         case BASS_DEVICE_TYPE_DISPLAYPORT: {
  93.             printf("device is a display port connector."); break;
  94.  
  95.         }
  96.         case BASS_DEVICE_TYPE_HANDSET:
  97.         {
  98.             printf("device is a handset telephone interface."); break;
  99.         }
  100.         case BASS_DEVICE_TYPE_HDMI: {
  101.             printf("device is a HDMI endpoint."); break;
  102.         }
  103.         case BASS_DEVICE_TYPE_HEADPHONES:
  104.         {
  105.             printf("device is a set of headphones."); break;
  106.         }
  107.         case BASS_DEVICE_TYPE_HEADSET: {
  108.             printf("device is a pair of earphones with an attached mic."); break;
  109.         }
  110.         case BASS_DEVICE_TYPE_LINE:
  111.         {
  112.             printf("device is a line endpoint."); break;
  113.         }
  114.         case BASS_DEVICE_TYPE_MICROPHONE: {
  115.             printf("device is a microphone."); break;
  116.         }
  117.         case BASS_DEVICE_TYPE_NETWORK:
  118.         {
  119.             printf("device is a live network stream."); break;
  120.         }
  121.         case BASS_DEVICE_TYPE_SPDIF: {
  122.             printf("device is connected through Sony/Philips Digital Interface."); break;
  123.         }
  124.         case BASS_DEVICE_TYPE_SPEAKERS:
  125.         {
  126.             printf("device is a set of speakers."); break;
  127.         }
  128.         default:
  129.             break;
  130.         }
  131.  
  132.         printf("\n---------------------------\n");
  133.     }
  134.     printf("count: %d\n", count);
  135.  
  136.     printf("Pick a microphone to use\n");
  137.     int mic;
  138.     while (true)
  139.     {
  140.         printf(">");
  141.         std::cin >> mic;
  142.         std::cout << mic << std::endl;
  143.         if (mic >= count || mic < -1) {
  144.             printf("Value invalid\n");
  145.         }
  146.         else break;
  147.     }
  148.     //BASS_ChannelStop(loadingSound);
  149.     BASS_StreamFree(loadingSound);
  150.  
  151.     //mic is chosen
  152.     printf("Initializing Mic.......");
  153.     if (!BASS_RecordInit(mic)) {
  154.         Error("Can't initialize recording device");
  155.         return quit();
  156.     }
  157.     else {
  158.         BASS_RecordSetDevice(mic);
  159.         printf("done.\n");
  160.     }
  161.  
  162.  
  163.     BASS_RECORDINFO micInfo;
  164.     BASS_RecordGetInfo(&micInfo);
  165.  
  166.     printf("Record starting at %d hz, %d input.\n", micInfo.freq, micInfo.inputs);
  167.     std::cout << (micInfo.singlein ? "ONLY ONE INPUT MAY BE USED AT A TIME\n" : "");
  168.     std::cout << "This mic's drivers have" << (micInfo.flags&DSCAPS_CERTIFIED ? " " : " not ") << "been certified by Microsoft.\n";
  169.     std::cout << "This mic's drivers do" << (micInfo.flags&DSCCAPS_EMULDRIVER ? " not " : " ") << "have DirectSound recording support.\n";
  170.     if (micInfo.formats&WAVE_FORMAT_4S16)
  171.     {
  172.  
  173.         printf("Device is Stereo, 16-bit  \n");
  174.     }
  175.     else if (micInfo.formats&WAVE_FORMAT_4S08)
  176.     {
  177.         printf("Device is Stereo, 8-bit  \n");
  178.     }
  179.     else if (micInfo.formats&WAVE_FORMAT_4M16)
  180.     {
  181.         printf("Device is Mono, 16-bit  \n");
  182.     }
  183.     else if (micInfo.formats&WAVE_FORMAT_4M08)
  184.     {
  185.         printf("Device is Mono, 8-bit  \n");
  186.     }
  187.     BASS_INFO bInfo;
  188.     BASS_GetInfo(&bInfo);
  189.     printf("Creating playback channel\n");
  190.     playbackChan = BASS_StreamCreate(micInfo.freq, 1, 0, STREAMPROC_PUSH, 0);// create a stream to play the recording
  191.     if (!playbackChan) { Error("Cannot create playback channel."); return quit(); }
  192.  
  193.  
  194.     printf("Creating record channel\n");
  195.  
  196.     recordingChan = BASS_RecordStart(micInfo.freq, 1, BASS_SAMPLE_FLOAT, MyRecordProc, 0);
  197.  
  198.     if (!recordingChan) {
  199.         Error("Recording channel could not be created");
  200.         return quit();
  201.     }
  202.     if (!BASS_ChannelPlay(recordingChan, false)) Error("Cannot play recording channel");
  203.    
  204.  
  205.     while (true) {
  206.         if (GetAsyncKeyState(VK_SPACE) & 0x8000) {
  207.             break;
  208.         }
  209.         else {
  210.             switch (BASS_ChannelIsActive(playbackChan))
  211.             {
  212.             case BASS_ACTIVE_STOPPED:
  213.             {
  214.  
  215.                 if (prevState != 0) {
  216.                     printf("Playback has stopped.\n");
  217.                     prevState = 0;
  218.                 }
  219.                 prevState = 0;
  220.                 break;
  221.             }
  222.             case BASS_ACTIVE_PLAYING:
  223.             {
  224.                 if (prevState != 1) {
  225.                     printf("Playback is playing.\n");
  226.                 }
  227.                 prevState = 1;
  228.                 break;
  229.             }
  230.             case BASS_ACTIVE_STALLED:
  231.             {
  232.                 if (prevState != 2) {
  233.                     printf("The channel is paused.\n ");
  234.                 }
  235.                 prevState = 2;
  236.                 break;
  237.             }
  238.             case BASS_ACTIVE_PAUSED:
  239.             {
  240.                 if (prevState != 3) {
  241.                     printf("The channel is paused.\n");
  242.                 }
  243.                 prevState = 3;
  244.  
  245.                 break;
  246.             }
  247.  
  248.             default:
  249.             {
  250.                     printf("Nothing");
  251.  
  252.                 break;
  253.             }
  254.             }
  255.         }
  256.     }
  257.  
  258.  
  259.     return quit();
  260. }
Advertisement
Add Comment
Please, Sign In to add comment