Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <iostream>
- #include "include\bass.h"
- #include "include\bass_fx.h"
- #include <Windows.h>
- #include <string>
- #include "main.h"
- #define string std::string
- HRECORD recordingChan;
- HSTREAM playbackChan;
- DWORD effectChan;
- void Error(string msg) {
- string err = msg + ": Error code " + std::to_string(BASS_ErrorGetCode());
- ::MessageBox(0, err.c_str(), "Error", MB_OK);
- }
- inline int quit() {
- BASS_RecordFree();
- BASS_Free();
- char a;
- std::cin >> a;
- return 0;
- }
- BOOL CALLBACK MyRecordProc(HRECORD handle, const void *buffer, DWORD length, void *user) {
- BASS_StreamPutData(playbackChan, buffer, length); // feed recorded data to output stream
- BASS_ChannelPlay(playbackChan, false);//play
- return TRUE;
- }
- int main() {
- if (!BASS_Init(-1, 44100, BASS_DEVICE_FREQ, 0, NULL)) {
- Error("Cannot initialize output device.");
- return quit();
- }
- DWORD loadingSound = BASS_StreamCreateFile(FALSE, "loading.wav", 0, 0, BASS_SAMPLE_FLOAT);
- if (!loadingSound) {
- Error("Cannot create loading sound.");
- return quit();
- }
- BASS_ChannelPlay(loadingSound, FALSE);
- BASS_DEVICEINFO dInfo;
- BASS_SetConfig(BASS_CONFIG_VISTA_TRUEPOS, false);// allows lower latency on Vista and newer with the drawback of
- //position reporting accuracy
- int count = 0;
- while (BASS_RecordGetDeviceInfo(count, &dInfo)) {
- count++;
- printf("Device #%d, ", count);
- std::cout << "name: " << dInfo.name;
- //std::cout << "driver: " << dInfo.driver;
- std::cout << (dInfo.flags&BASS_DEVICE_ENABLED ? "enabled" : "disabled") << ", ";
- std::cout << (dInfo.flags&BASS_DEVICE_DEFAULT ? "default device" : "") << ", ";
- //what type of device is it?
- switch ((dInfo.flags&BASS_DEVICE_TYPE_MASK))
- {
- case BASS_DEVICE_TYPE_DIGITAL:
- {
- printf("device is a digital interface."); break;
- }
- case BASS_DEVICE_TYPE_DISPLAYPORT: {
- printf("device is a display port connector."); break;
- }
- case BASS_DEVICE_TYPE_HANDSET:
- {
- printf("device is a handset telephone interface."); break;
- }
- case BASS_DEVICE_TYPE_HDMI: {
- printf("device is a HDMI endpoint."); break;
- }
- case BASS_DEVICE_TYPE_HEADPHONES:
- {
- printf("device is a set of headphones."); break;
- }
- case BASS_DEVICE_TYPE_HEADSET: {
- printf("device is a pair of earphones with an attached mic."); break;
- }
- case BASS_DEVICE_TYPE_LINE:
- {
- printf("device is a line endpoint."); break;
- }
- case BASS_DEVICE_TYPE_MICROPHONE: {
- printf("device is a microphone."); break;
- }
- case BASS_DEVICE_TYPE_NETWORK:
- {
- printf("device is a live network stream."); break;
- }
- case BASS_DEVICE_TYPE_SPDIF: {
- printf("device is connected through Sony/Philips Digital Interface."); break;
- }
- case BASS_DEVICE_TYPE_SPEAKERS:
- {
- printf("device is a set of speakers."); break;
- }
- default:
- break;
- }
- printf("\n---------------------------\n");
- }
- printf("count: %d\n", count);
- printf("Pick a microphone to use\n");
- int mic;
- while (true)
- {
- printf(">");
- std::cin >> mic;
- std::cout << mic << std::endl;
- if (mic >= count || mic < -1) {
- printf("Value invalid\n");
- }
- else break;
- }
- BASS_ChannelStop(loadingSound);
- BASS_StreamFree(loadingSound);
- //mic is chosen
- printf("Initializing Mic.......");
- if (!BASS_RecordInit(mic)) {
- Error("Can't initialize recording device");
- return quit();
- }
- else {
- BASS_RecordSetDevice(mic);
- printf("done.\n");
- }
- BASS_RECORDINFO micInfo;
- BASS_RecordGetInfo(&micInfo);
- printf("Record starting at %d hz, %d input.\n", micInfo.freq, micInfo.inputs);
- std::cout << (micInfo.singlein ? "ONLY ONE INPUT MAY BE USED AT A TIME\n" : "");
- std::cout << "This mic's drivers have" << (micInfo.flags&DSCAPS_CERTIFIED ? " " : " not ") << "been certified by Microsoft.\n";
- std::cout << "This mic's drivers do" << (micInfo.flags&DSCCAPS_EMULDRIVER ? " not " : " ") << "have DirectSound recording support.\n";
- if (micInfo.formats&WAVE_FORMAT_4S16)
- {
- printf("Device is Stereo, 16-bit \n");
- }
- else if (micInfo.formats&WAVE_FORMAT_4S08)
- {
- printf("Device is Stereo, 8-bit \n");
- }
- else if (micInfo.formats&WAVE_FORMAT_4M16)
- {
- printf("Device is Mono, 16-bit \n");
- }
- else if (micInfo.formats&WAVE_FORMAT_4M08)
- {
- printf("Device is Mono, 8-bit \n");
- }
- BASS_INFO bInfo;
- BASS_GetInfo(&bInfo);
- printf("Creating record channel\n");
- recordingChan = BASS_RecordStart(micInfo.freq, 2, MAKELONG(0, 10), MyRecordProc, 0);// start recording with 10ms period
- if (!recordingChan) {
- Error("Recording channel could not be created");
- return quit();
- }
- printf("Creating playback channel\n");
- playbackChan = BASS_StreamCreate(micInfo.freq, 2, 0, STREAMPROC_PUSH, 0);
- std::cin.get();
- return quit();
- }
Add Comment
Please, Sign In to add comment