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;
- int prevState= 1;
- 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();
- while (true) {
- if (GetAsyncKeyState(VK_ESCAPE) & 0x8000) {
- return 0;
- }
- }
- }
- int i = 0;
- BOOL CALLBACK MyRecordProc(HRECORD handle, const void *buffer, DWORD length, void *user) {
- if (BASS_StreamPutData(playbackChan, buffer, length)==-1) {
- Error("Cannot push to stream");
- return FALSE;
- }
- if (!BASS_ChannelPlay(playbackChan, false)) {
- Error("Cannot play stream");
- return FALSE;
- }
- return TRUE;
- }
- void clear() {
- COORD topLeft = { 0, 0 };
- HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
- CONSOLE_SCREEN_BUFFER_INFO screen;
- DWORD written;
- GetConsoleScreenBufferInfo(console, &screen);
- FillConsoleOutputCharacterA(
- console, ' ', screen.dwSize.X * screen.dwSize.Y, topLeft, &written
- );
- FillConsoleOutputAttribute(
- console, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE,
- screen.dwSize.X * screen.dwSize.Y, topLeft, &written
- );
- SetConsoleCursorPosition(console, topLeft);
- }
- int main() {
- if (!BASS_Init(-1, 44100, BASS_DEVICE_LATENCY, 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 playback channel\n");
- playbackChan = BASS_StreamCreate(micInfo.freq, 1, 0, STREAMPROC_PUSH, 0);// create a stream to play the recording
- if (!playbackChan) { Error("Cannot create playback channel."); return quit(); }
- printf("Creating record channel\n");
- recordingChan = BASS_RecordStart(micInfo.freq, 1, BASS_SAMPLE_FLOAT, MyRecordProc, 0);
- if (!recordingChan) {
- Error("Recording channel could not be created");
- return quit();
- }
- if (!BASS_ChannelPlay(recordingChan, false)) Error("Cannot play recording channel");
- while (true) {
- if (GetAsyncKeyState(VK_SPACE) & 0x8000) {
- break;
- }
- else {
- switch (BASS_ChannelIsActive(playbackChan))
- {
- case BASS_ACTIVE_STOPPED:
- {
- if (prevState != 0) {
- printf("Playback has stopped.\n");
- prevState = 0;
- }
- prevState = 0;
- break;
- }
- case BASS_ACTIVE_PLAYING:
- {
- if (prevState != 1) {
- printf("Playback is playing.\n");
- }
- prevState = 1;
- break;
- }
- case BASS_ACTIVE_STALLED:
- {
- if (prevState != 2) {
- printf("The channel is paused.\n ");
- }
- prevState = 2;
- break;
- }
- case BASS_ACTIVE_PAUSED:
- {
- if (prevState != 3) {
- printf("The channel is paused.\n");
- }
- prevState = 3;
- break;
- }
- default:
- {
- printf("Nothing");
- break;
- }
- }
- }
- }
- return quit();
- }
Advertisement
Add Comment
Please, Sign In to add comment