Guest User

Live Feedback C++ (not working)

a guest
Aug 25th, 2018
171
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.  
  16. void Error(string msg) {
  17.     string err = msg + ": Error code " + std::to_string(BASS_ErrorGetCode());
  18.     ::MessageBox(0, err.c_str(), "Error", MB_OK);
  19. }
  20. inline int quit() {
  21.     BASS_RecordFree();
  22.     BASS_Free();
  23.     char a;
  24.     std::cin >> a;
  25.     return 0;
  26. }
  27. BOOL CALLBACK MyRecordProc(HRECORD handle, const void *buffer, DWORD length, void *user) {
  28.     BASS_StreamPutData(playbackChan, buffer, length); // feed recorded data to output stream
  29.     BASS_ChannelPlay(playbackChan, false);//play
  30.     return TRUE;
  31. }
  32. int main() {
  33.     if (!BASS_Init(-1, 44100, BASS_DEVICE_FREQ, 0, NULL)) {
  34.         Error("Cannot initialize output device.");
  35.         return quit();
  36.     }
  37.     DWORD loadingSound = BASS_StreamCreateFile(FALSE, "loading.wav", 0, 0, BASS_SAMPLE_FLOAT);
  38.     if (!loadingSound) {
  39.         Error("Cannot create loading sound.");
  40.         return quit();
  41.     }
  42.     BASS_ChannelPlay(loadingSound, FALSE);
  43.     BASS_DEVICEINFO dInfo;
  44.     BASS_SetConfig(BASS_CONFIG_VISTA_TRUEPOS, false);// allows lower latency on Vista and newer with the drawback of
  45.                                                      //position reporting accuracy
  46.     int count = 0;
  47.     while (BASS_RecordGetDeviceInfo(count, &dInfo)) {
  48.         count++;
  49.         printf("Device #%d, ", count);
  50.         std::cout << "name: " << dInfo.name;
  51.         //std::cout << "driver: " << dInfo.driver;
  52.         std::cout << (dInfo.flags&BASS_DEVICE_ENABLED ? "enabled" : "disabled") << ", ";
  53.         std::cout << (dInfo.flags&BASS_DEVICE_DEFAULT ? "default device" : "") << ", ";
  54.         //what type of device is it?
  55.         switch ((dInfo.flags&BASS_DEVICE_TYPE_MASK))
  56.         {
  57.         case BASS_DEVICE_TYPE_DIGITAL:
  58.         {
  59.             printf("device is a digital interface."); break;
  60.  
  61.         }
  62.         case BASS_DEVICE_TYPE_DISPLAYPORT: {
  63.             printf("device is a display port connector."); break;
  64.  
  65.         }
  66.         case BASS_DEVICE_TYPE_HANDSET:
  67.         {
  68.             printf("device is a handset telephone interface."); break;
  69.         }
  70.         case BASS_DEVICE_TYPE_HDMI: {
  71.             printf("device is a HDMI endpoint."); break;
  72.         }
  73.         case BASS_DEVICE_TYPE_HEADPHONES:
  74.         {
  75.             printf("device is a set of headphones."); break;
  76.         }
  77.         case BASS_DEVICE_TYPE_HEADSET: {
  78.             printf("device is a pair of earphones with an attached mic."); break;
  79.         }
  80.         case BASS_DEVICE_TYPE_LINE:
  81.         {
  82.             printf("device is a line endpoint."); break;
  83.         }
  84.         case BASS_DEVICE_TYPE_MICROPHONE: {
  85.             printf("device is a microphone."); break;
  86.         }
  87.         case BASS_DEVICE_TYPE_NETWORK:
  88.         {
  89.             printf("device is a live network stream."); break;
  90.         }
  91.         case BASS_DEVICE_TYPE_SPDIF: {
  92.             printf("device is connected through Sony/Philips Digital Interface."); break;
  93.         }
  94.         case BASS_DEVICE_TYPE_SPEAKERS:
  95.         {
  96.             printf("device is a set of speakers."); break;
  97.         }
  98.         default:
  99.             break;
  100.         }
  101.  
  102.         printf("\n---------------------------\n");
  103.     }
  104.     printf("count: %d\n", count);
  105.  
  106.     printf("Pick a microphone to use\n");
  107.     int mic;
  108.     while (true)
  109.     {
  110.         printf(">");
  111.         std::cin >> mic;
  112.         std::cout << mic << std::endl;
  113.         if (mic >= count || mic < -1) {
  114.             printf("Value invalid\n");
  115.         }
  116.         else break;
  117.     }
  118.     BASS_ChannelStop(loadingSound);
  119.     BASS_StreamFree(loadingSound);
  120.     //mic is chosen
  121.     printf("Initializing Mic.......");
  122.     if (!BASS_RecordInit(mic)) {
  123.         Error("Can't initialize recording device");
  124.         return quit();
  125.     }
  126.     else {
  127.         BASS_RecordSetDevice(mic);
  128.         printf("done.\n");
  129.     }
  130.  
  131.  
  132.     BASS_RECORDINFO micInfo;
  133.     BASS_RecordGetInfo(&micInfo);
  134.  
  135.     printf("Record starting at %d hz, %d input.\n", micInfo.freq, micInfo.inputs);
  136.     std::cout << (micInfo.singlein ? "ONLY ONE INPUT MAY BE USED AT A TIME\n" : "");
  137.     std::cout << "This mic's drivers have" << (micInfo.flags&DSCAPS_CERTIFIED ? " " : " not ") << "been certified by Microsoft.\n";
  138.     std::cout << "This mic's drivers do" << (micInfo.flags&DSCCAPS_EMULDRIVER ? " not " : " ") << "have DirectSound recording support.\n";
  139.     if (micInfo.formats&WAVE_FORMAT_4S16)
  140.     {
  141.  
  142.         printf("Device is Stereo, 16-bit  \n");
  143.     }
  144.     else if (micInfo.formats&WAVE_FORMAT_4S08)
  145.     {
  146.         printf("Device is Stereo, 8-bit  \n");
  147.     }
  148.     else if (micInfo.formats&WAVE_FORMAT_4M16)
  149.     {
  150.         printf("Device is Mono, 16-bit  \n");
  151.     }
  152.     else if (micInfo.formats&WAVE_FORMAT_4M08)
  153.     {
  154.         printf("Device is Mono, 8-bit  \n");
  155.     }
  156.     BASS_INFO bInfo;
  157.     BASS_GetInfo(&bInfo);
  158.  
  159.  
  160.     printf("Creating record channel\n");
  161.  
  162.     recordingChan = BASS_RecordStart(micInfo.freq, 2, MAKELONG(0, 10), MyRecordProc, 0);// start recording with 10ms period
  163.     if (!recordingChan) {
  164.         Error("Recording channel could not be created");
  165.         return quit();
  166.     }
  167.  
  168.     printf("Creating playback channel\n");
  169.     playbackChan = BASS_StreamCreate(micInfo.freq, 2, 0, STREAMPROC_PUSH, 0);
  170.  
  171.     std::cin.get();
  172.  
  173.     return quit();
  174. }
Add Comment
Please, Sign In to add comment