Visual Studio C++ OOP
I need to complete the program about how to play a WAV file in stereo.
the program seems to play the WAV file in mono since it has a bad sound quality.
chegg can't upload the WAV file, so I need you to use your own WAV file.
#include
#include
#include "CAudio.h"
#include "conio.h"
typedef struct wav_header {
// RIFF Header
char riff_header[4]; // Contains "RIFF"
int wav_size; // Size of the wav portion of the file, which follows the first 8 bytes. File size - 8
char wave_header[4]; // Contains "WAVE"
// Format Header
char fmt_header[4]; // Contains "fmt " (includes trailing space)
int fmt_chunk_size; // Should be 16 for PCM
short audio_format; // Should be 1 for PCM. 3 for IEEE Float
short num_channels;
int sample_rate;
int byte_rate; // Number of bytes per second. sample_rate * num_channels * Bytes Per
Sample
short sample_alignment; // num_channels * Bytes Per Sample
short bit_depth; // Number of bits per sample
// Data
char data_header[4]; // Contains "data"
int data_bytes; // Number of bytes in data. Number of samples * num_channels * sample byte
size
// uint8_t bytes[]; // Remainder of wave file is bytes
} wav_header;
CAudio *lp;
FILE *In;
int g_No = 0;
void CALLBACK Play_Proc(HWAVEOUT hWaveOut, UINT uMsg, DWORD dwInstance,
DWORD dwParam1, DWORD dwParam2)
{ int Len=160;
short Speech[160];
switch (uMsg)
{ case WOM_DONE:
if (lp->PStart)
{ if (In!=NULL) fread(Speech, 2, 160, In); // 160 Sample Data
if (feof(In)) fseek(In, 0, 0);
lp->Play_Speech(Speech, Len);
g_No += Len; printf("%dr", g_No++);
}
break;
}
}
int main()
{
lp = new CAudio();
// 2.Play WAV File
errno_t err;
wav_header Buf;
//if ((err = fopen_s(&In, "Speech.wav", "rb")) != 0) { printf("File Errorn"); return 0; }
if ((err = fopen_s(&In, "file_example_WAV_1MG.wav", "rb")) != 0) { printf("File Errorn");
return 0; }
//if ((err = fopen_s(&In, "guitartune.wav", "rb")) != 0) { printf("File Errorn"); return 0; }
//if ((err = fopen_s(&In, "rbds_capture_47500.wav", "rb")) != 0) { printf("File Errorn");
return 0; }
fread(&Buf, 1, sizeof(wav_header), In);
printf("Sample Rate=%dn", Buf.sample_rate);
printf("Channel =%dn", Buf.num_channels);
printf("Bits/Sample=%dn", Buf.bit_depth);
// 2.5
lp->Init_Audio(160, -1, -1, Buf.sample_rate);
lp->Open_Play((DWORD)Play_Proc, CALLBACK_FUNCTION);
lp->Start_Play();
//3.Play WAV File
char c = _getch();
// 4.
lp->Stop_Play();
lp->Close_Play();
// 5.
fclose(In); In = NULL;
}

Visual Studio C++ OOP I need to complete the program about how to .pdf

  • 1.
    Visual Studio C++OOP I need to complete the program about how to play a WAV file in stereo. the program seems to play the WAV file in mono since it has a bad sound quality. chegg can't upload the WAV file, so I need you to use your own WAV file. #include #include #include "CAudio.h" #include "conio.h" typedef struct wav_header { // RIFF Header char riff_header[4]; // Contains "RIFF" int wav_size; // Size of the wav portion of the file, which follows the first 8 bytes. File size - 8 char wave_header[4]; // Contains "WAVE" // Format Header char fmt_header[4]; // Contains "fmt " (includes trailing space) int fmt_chunk_size; // Should be 16 for PCM short audio_format; // Should be 1 for PCM. 3 for IEEE Float short num_channels; int sample_rate; int byte_rate; // Number of bytes per second. sample_rate * num_channels * Bytes Per Sample short sample_alignment; // num_channels * Bytes Per Sample short bit_depth; // Number of bits per sample // Data char data_header[4]; // Contains "data" int data_bytes; // Number of bytes in data. Number of samples * num_channels * sample byte size // uint8_t bytes[]; // Remainder of wave file is bytes } wav_header; CAudio *lp; FILE *In; int g_No = 0;
  • 2.
    void CALLBACK Play_Proc(HWAVEOUThWaveOut, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2) { int Len=160; short Speech[160]; switch (uMsg) { case WOM_DONE: if (lp->PStart) { if (In!=NULL) fread(Speech, 2, 160, In); // 160 Sample Data if (feof(In)) fseek(In, 0, 0); lp->Play_Speech(Speech, Len); g_No += Len; printf("%dr", g_No++); } break; } } int main() { lp = new CAudio(); // 2.Play WAV File errno_t err; wav_header Buf; //if ((err = fopen_s(&In, "Speech.wav", "rb")) != 0) { printf("File Errorn"); return 0; } if ((err = fopen_s(&In, "file_example_WAV_1MG.wav", "rb")) != 0) { printf("File Errorn"); return 0; } //if ((err = fopen_s(&In, "guitartune.wav", "rb")) != 0) { printf("File Errorn"); return 0; } //if ((err = fopen_s(&In, "rbds_capture_47500.wav", "rb")) != 0) { printf("File Errorn"); return 0; } fread(&Buf, 1, sizeof(wav_header), In); printf("Sample Rate=%dn", Buf.sample_rate); printf("Channel =%dn", Buf.num_channels); printf("Bits/Sample=%dn", Buf.bit_depth); // 2.5 lp->Init_Audio(160, -1, -1, Buf.sample_rate); lp->Open_Play((DWORD)Play_Proc, CALLBACK_FUNCTION);
  • 3.
    lp->Start_Play(); //3.Play WAV File charc = _getch(); // 4. lp->Stop_Play(); lp->Close_Play(); // 5. fclose(In); In = NULL; }