📄 audioformat.cpp
字号:
if (formatmap[sel] == WAVE_FORMAT_2S16) {
audio_bits_per_sampleLocal = 16;
audio_num_channelsLocal = 2;
audio_samples_per_secondsLocal = 22050;
}
if (formatmap[sel] == WAVE_FORMAT_4M08) {
audio_bits_per_sampleLocal = 8;
audio_num_channelsLocal = 1;
audio_samples_per_secondsLocal = 44100;
}
if (formatmap[sel] == WAVE_FORMAT_4M16) {
audio_bits_per_sampleLocal = 16;
audio_num_channelsLocal = 1;
audio_samples_per_secondsLocal = 44100;
}
if (formatmap[sel] == WAVE_FORMAT_4S08) {
audio_bits_per_sampleLocal = 8;
audio_num_channelsLocal = 2;
audio_samples_per_secondsLocal = 44100;
}
if (formatmap[sel] == WAVE_FORMAT_4S16) {
audio_bits_per_sampleLocal = 16;
audio_num_channelsLocal = 2;
audio_samples_per_secondsLocal = 44100;
}
BuildLocalRecordingFormat();
SuggestLocalCompressFormat();
UpdateLocalCompressFormatInterface();
}
void AudioFormat::OnInterleave()
{
// TODO: Add your control notification handler code here
BOOL binteleave =((CButton *) (GetDlgItem(IDC_INTERLEAVE)))->GetCheck();
if (binteleave) {
((CButton *) (GetDlgItem(IDC_IFACTOR)))->EnableWindow(TRUE);
((CButton *) (GetDlgItem(IDC_INTERLEAVEFRAMES)))->EnableWindow(TRUE);
((CButton *) (GetDlgItem(IDC_INTERLEAVESECONDS)))->EnableWindow(TRUE);
}
else {
((CButton *) (GetDlgItem(IDC_IFACTOR)))->EnableWindow(FALSE);
((CButton *) (GetDlgItem(IDC_INTERLEAVEFRAMES)))->EnableWindow(FALSE);
((CButton *) (GetDlgItem(IDC_INTERLEAVESECONDS)))->EnableWindow(FALSE);
}
}
void BuildLocalRecordingFormat() {
m_FormatLocal.wFormatTag = WAVE_FORMAT_PCM;
m_FormatLocal.wBitsPerSample = audio_bits_per_sampleLocal;
m_FormatLocal.nSamplesPerSec = audio_samples_per_secondsLocal;
m_FormatLocal.nChannels = audio_num_channelsLocal;
m_FormatLocal.nBlockAlign = m_FormatLocal.nChannels * (m_FormatLocal.wBitsPerSample/8);
m_FormatLocal.nAvgBytesPerSec = m_FormatLocal.nSamplesPerSec * m_FormatLocal.nBlockAlign;
m_FormatLocal.cbSize = 0;
}
void SuggestLocalCompressFormat() {
bAudioCompressionLocal = TRUE;
AllocLocalCompressFormat();
//1st try MPEGLAYER3
BuildLocalRecordingFormat();
MMRESULT mmr;
if ((m_FormatLocal.nSamplesPerSec == 22050) && (m_FormatLocal.nChannels==2) && (m_FormatLocal.wBitsPerSample <= 16)) {
pwfxLocal->wFormatTag = WAVE_FORMAT_MPEGLAYER3;
mmr = acmFormatSuggest(NULL, &m_FormatLocal, pwfxLocal, cbwfxLocal, ACM_FORMATSUGGESTF_WFORMATTAG);
}
if (mmr!=0) {
//Then try ADPCM
BuildLocalRecordingFormat();
pwfxLocal->wFormatTag = WAVE_FORMAT_ADPCM;
MMRESULT mmr = acmFormatSuggest(NULL, &m_FormatLocal, pwfxLocal, cbwfxLocal, ACM_FORMATSUGGESTF_WFORMATTAG);
if (mmr!=0) {
//Use the PCM as default
BuildLocalRecordingFormat();
pwfxLocal->wFormatTag = WAVE_FORMAT_PCM;
MMRESULT mmr = acmFormatSuggest(NULL, &m_FormatLocal, pwfxLocal, cbwfxLocal, ACM_FORMATSUGGESTF_WFORMATTAG);
if (mmr!=0) {
bAudioCompressionLocal = FALSE;
}
}
}
}
void AllocLocalCompressFormat() {
if (pwfxLocal) {
//Do nothing....already allocated
}
else {
MMRESULT mmresult = acmMetrics(NULL, ACM_METRIC_MAX_SIZE_FORMAT, &cbwfxLocal);
if (MMSYSERR_NOERROR != mmresult)
{
CString msgstr;
msgstr.Format("Metrics failed mmresult=%u!", mmresult);
::MessageBox(NULL,msgstr,"Note", MB_OK | MB_ICONEXCLAMATION);
return ;
}
if (cbwfxLocal < cbwfx) cbwfxLocal = cbwfx;
pwfxLocal = (LPWAVEFORMATEX)GlobalAllocPtr(GHND, cbwfxLocal);
if (NULL == pwfxLocal)
{
CString msgstr;
msgstr.Format("GlobalAllocPtr(%lu) failed!", cbwfxLocal);
::MessageBox(NULL,msgstr,"Note", MB_OK | MB_ICONEXCLAMATION);
return ;
}
}
}
void AudioFormat::OnCancel()
{
// TODO: Add extra cleanup here
if (pwfxLocal) {
GlobalFreePtr(pwfxLocal);
pwfxLocal = NULL;
}
CDialog::OnCancel();
}
void AudioFormat::OnVolume()
{
// Ver 1.1
if (waveInGetNumDevs() == 0) {
CString msgstr;
msgstr.Format(ID_ERR_DETECT_AUDIO_DEVICE);
MessageBox(msgstr,"Note", MB_OK | MB_ICONEXCLAMATION);
return;
}
CString launchPath("");
CString testLaunchPath;
CString exeFileName("\\sndvol32.exe");
char dirx[300];
GetWindowsDirectory(dirx,300);
CString Windir(dirx);
CString AppDir;
CString SubDir;
//Test Windows\sndvol32.exe
AppDir = Windir;
SubDir = "";
testLaunchPath=AppDir+SubDir+exeFileName;
if (launchPath=="") {
//Verify sndvol32.exe exists
OFSTRUCT ofs;
HFILE hdir = OpenFile(testLaunchPath, &ofs,OF_EXIST);
if (hdir != HFILE_ERROR) {
launchPath=testLaunchPath;
}
}
//Test Windows\system32\sndvol32.exe
AppDir = Windir;
SubDir = "\\system32";
testLaunchPath=AppDir+SubDir+exeFileName;
if (launchPath=="") {
//Verify sndvol32.exe exists
OFSTRUCT ofs;
HFILE hdir = OpenFile(testLaunchPath, &ofs,OF_EXIST);
if (hdir != HFILE_ERROR) {
launchPath=testLaunchPath;
//need CloseHandle ?
//BOOL ret = CloseHandle((HANDLE) hdir);
//if (!ret) MessageBox("Close handle Fails","Note",MB_OK | MB_ICONEXCLAMATION);
}
}
//Test Windows\system\sndvol32.exe
AppDir = Windir;
SubDir = "\\system32";
testLaunchPath=AppDir+SubDir+exeFileName;
if (launchPath=="") {
//Verify sndvol32.exe exists
OFSTRUCT ofs;
HFILE hdir = OpenFile(testLaunchPath, &ofs,OF_EXIST);
if (hdir != HFILE_ERROR) {
launchPath=testLaunchPath;
}
}
if (launchPath!="") { //launch Volume Control
//not sure
launchPath = launchPath + " /r /rec /record";
if (WinExec(launchPath,SW_SHOW)!=0) {
}
else {
MessageBox("Error launching Volume Control!","Note",MB_OK | MB_ICONEXCLAMATION);
}
}
}
void AudioFormat::OnSelchangeInputdevice()
{
// TODO: Add your control notification handler code here
int devID;
devID = ((CComboBox *) (GetDlgItem(IDC_INPUTDEVICE)))->GetCurSel();
if (devID < numdevice) {
UpdateDeviceData(devicemap[devID],waveinselected,NULL);
}
}
// ver 1.2
// =====================================
// UpdateDeviceData
//
// Update the user - interface based on the device data
//
// If the third parameter (compressed format) is not null, we assume it is compatibile with the 2nd parameter (recording format)
//
// =====================================
void AudioFormat::UpdateDeviceData(UINT deviceID, DWORD curr_sel_rec_format, LPWAVEFORMATEX curr_sel_pwfx) {
WAVEINCAPS pwic;
MMRESULT mmr = waveInGetDevCaps( deviceID , &pwic, sizeof(pwic) );
int selected_cindex=-1; //selected index of combo box
numformat=0; //counter, number of format
//Reset Recording Format Combo Box and format map
((CComboBox *) (GetDlgItem(IDC_COMBO1)))->ResetContent();
numformat = 0;
CString combolabel;
//This code works on the assumption (when filling in values for the interfaces)
//that the m_Format and pwfx formats (external variables) are already chosen correctly and compatibile with each other
if ((pwic.dwFormats) & WAVE_FORMAT_1M08) {
combolabel.LoadString(ID_LABEL_WAVE_FORMAT_1M08);
((CComboBox *) (GetDlgItem(IDC_COMBO1)))->AddString(combolabel);
formatmap[numformat]=WAVE_FORMAT_1M08;
numformat++;
}
if ((pwic.dwFormats) & WAVE_FORMAT_1M16) {
combolabel.LoadString(ID_LABEL_WAVE_FORMAT_1M16);
((CComboBox *) (GetDlgItem(IDC_COMBO1)))->AddString(combolabel);
formatmap[numformat]=WAVE_FORMAT_1M16;
numformat++;
}
if ((pwic.dwFormats) & WAVE_FORMAT_1S08) {
combolabel.LoadString(ID_LABEL_WAVE_FORMAT_1S08);
((CComboBox *) (GetDlgItem(IDC_COMBO1)))->AddString(combolabel);
formatmap[numformat]=WAVE_FORMAT_1S08;
numformat++;
}
if ((pwic.dwFormats) & WAVE_FORMAT_1S16) {
combolabel.LoadString(ID_LABEL_WAVE_FORMAT_1S16);
((CComboBox *) (GetDlgItem(IDC_COMBO1)))->AddString(combolabel);
formatmap[numformat]=WAVE_FORMAT_1S16;
numformat++;
}
if ((pwic.dwFormats) & WAVE_FORMAT_2M08) {
combolabel.LoadString(ID_LABEL_WAVE_FORMAT_2M08);
((CComboBox *) (GetDlgItem(IDC_COMBO1)))->AddString(combolabel);
formatmap[numformat]=WAVE_FORMAT_2M08;
numformat++;
}
if ((pwic.dwFormats) & WAVE_FORMAT_2M16) {
combolabel.LoadString(ID_LABEL_WAVE_FORMAT_2M16);
((CComboBox *) (GetDlgItem(IDC_COMBO1)))->AddString(combolabel);
formatmap[numformat]=WAVE_FORMAT_2M16;
numformat++;
}
if ((pwic.dwFormats) & WAVE_FORMAT_2S08) {
combolabel.LoadString(ID_LABEL_WAVE_FORMAT_2S08);
((CComboBox *) (GetDlgItem(IDC_COMBO1)))->AddString(combolabel);
formatmap[numformat]=WAVE_FORMAT_2S08;
numformat++;
}
if ((pwic.dwFormats) & WAVE_FORMAT_2S16) {
combolabel.LoadString(ID_LABEL_WAVE_FORMAT_2S16);
((CComboBox *) (GetDlgItem(IDC_COMBO1)))->AddString(combolabel);
formatmap[numformat]=WAVE_FORMAT_2S16;
numformat++;
}
if ((pwic.dwFormats) & WAVE_FORMAT_4M08) {
combolabel.LoadString(ID_LABEL_WAVE_FORMAT_4M08);
((CComboBox *) (GetDlgItem(IDC_COMBO1)))->AddString(combolabel);
formatmap[numformat]=WAVE_FORMAT_4M08;
numformat++;
}
if ((pwic.dwFormats) & WAVE_FORMAT_4M16) {
combolabel.LoadString(ID_LABEL_WAVE_FORMAT_4M16);
((CComboBox *) (GetDlgItem(IDC_COMBO1)))->AddString(combolabel);
formatmap[numformat]=WAVE_FORMAT_4M16;
numformat++;
}
if ((pwic.dwFormats) & WAVE_FORMAT_4S08) {
combolabel.LoadString(ID_LABEL_WAVE_FORMAT_4S08);
((CComboBox *) (GetDlgItem(IDC_COMBO1)))->AddString(combolabel);
formatmap[numformat]=WAVE_FORMAT_4S08;
numformat++;
}
if ((pwic.dwFormats) & WAVE_FORMAT_4S16) {
combolabel.LoadString(ID_LABEL_WAVE_FORMAT_4S16);
((CComboBox *) (GetDlgItem(IDC_COMBO1)))->AddString(combolabel);
formatmap[numformat]=WAVE_FORMAT_4S16;
numformat++;
}
if (numformat<=0) {
((CComboBox *) (GetDlgItem(IDC_COMBO1)))->AddString("None Available");
((CComboBox *) (GetDlgItem(IDC_COMBO1)))->SetCurSel(0);
((CEdit *) (GetDlgItem(IDC_COMPRESSEDFORMATTAG)))->SetWindowText("None Available");
((CEdit *) (GetDlgItem(IDC_COMPRESSEDFORMAT)))->SetWindowText(" ");
((CButton *) (GetDlgItem(IDC_CHOOSE)))->EnableWindow(FALSE);
//For this case, where no recording format, compressed format is available
//is handled by OnOk (no external formats is updated) when the user press the OK button.
return;
}
else {
((CButton *) (GetDlgItem(IDC_CHOOSE)))->EnableWindow(TRUE);
}
for (int k=0;k<numformat;k++) {
if (curr_sel_rec_format == formatmap[k])
selected_cindex=k;
}
//If can reach here ==> numformat > 0
if ((selected_cindex==-1) && (numformat>0)) { //selected recording format not found
//force selection to one that is compatible
selected_cindex=0;
((CComboBox *) (GetDlgItem(IDC_COMBO1)))->SetCurSel(selected_cindex);
//force selection of compress format
OnSelchangeRecordformat() ;
}
else {
//Compressed or Save format
AllocLocalCompressFormat();
if (curr_sel_pwfx==NULL) {
SuggestLocalCompressFormat();
}
else {
memcpy( (void *) pwfxLocal, (void *) curr_sel_pwfx, cbwfx );
}
UpdateLocalCompressFormatInterface();
//will this following line call OnSelchangeRecordformat() ?
if (selected_cindex>=0)
((CComboBox *) (GetDlgItem(IDC_COMBO1)))->SetCurSel(selected_cindex);
}
}
void AudioFormat::OnInterleaveframes()
{
// TODO: Add your control notification handler code here
((CButton *) (GetDlgItem(IDC_INTERLEAVEFRAMES)))->SetCheck(TRUE);
((CButton *) (GetDlgItem(IDC_INTERLEAVESECONDS)))->SetCheck(FALSE);
}
void AudioFormat::OnInterleaveseconds()
{
// TODO: Add your control notification handler code here
((CButton *) (GetDlgItem(IDC_INTERLEAVEFRAMES)))->SetCheck(FALSE);
((CButton *) (GetDlgItem(IDC_INTERLEAVESECONDS)))->SetCheck(TRUE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -