CSU多媒体技术及应用(实验)

前言

这学期学完多媒体技术及应用课程后,想把做实验时遇到的坑与技巧和大家分享(学弟学妹)。毕竟,可能 过几天我就全忘了,做的实验代码也可能会删了。

 

目录

  • 实验1《数字音频处理程序设计》
  • 实验2《数字图像处理程序设计》
  • 实验3《数字视频处理程序设计》

 

正文

实验一 音频处理

实验内容:

1.打开两个音频文件(限Wav文件,并具有相同的采样频率和量化深度),然后用第 二个音频文件左声道代替第一个音频文件左声道,但保留第一个音频文件的右声道,最 后播放第一个音频文件,并观察结果。

2.设计实现静音效果。

关键步骤

1. 将文件放入与主cpp文件同目录下:

添加代码:

// Global Variables:
HINSTANCE hInst;								// current instance
TCHAR szTitle[MAX_LOADSTRING];					// The title bar text
TCHAR szWindowClass[MAX_LOADSTRING];			// the main window class name

WCHAR *wszSourceFile = NULL;

const WCHAR *wszTargetFile = L"out1.wav";
const WCHAR *wszTargetFile2 = L"out2.wav";

2. 实现静音与声道替换的关键代码: 

HRESULT WriteWaveData(
	HANDLE hFile,               // Output file1.
	HANDLE hFile2,               // Output file2.
    IMFSourceReader *pReader,   // Source reader.
	IMFSourceReader *pReaderAnother,   // Another Source reader.
    DWORD cbMaxAudioData,       // Maximum amount of audio data (bytes).
	DWORD cbMaxAudioDataAnother,       // Maximum amount of audio data (bytes).
    DWORD *pcbDataWritten,       // Receives the amount of data written.
	DWORD *pcbDataWrittenAnother       // Receives the amount of data written.
    )
{
    //......此处省略默认生成的代码
    //Get a pointer to the audio data in the sample.
    hr = pSample->ConvertToContiguousBuffer(&pBuffer);
	if (FAILED(hr)) { break; }
	hr2 = pSampleAnother->ConvertToContiguousBuffer(&pBufferAnother);
	if (FAILED(hr2)) { break; }
	//锁定内存,得到缓冲地址指针
	hr = pBuffer->Lock(&pAudioData, NULL, &cbBuffer);
	if (FAILED(hr)) { break; }
	hr2 = pBufferAnother->Lock(&pAudioDataAnother, NULL, &cbBufferAnother);
	if (FAILED(hr2)) { break; }
		
    // Make sure not to exceed the specified maximum size.
	if (cbMaxAudioData - cbAudioData < cbBuffer)
    {
        cbBuffer = cbMaxAudioData - cbAudioData;
    }
    if (cbMaxAudioDataAnother - cbAudioDataAnother < cbBufferAnother)
    {
         cbBufferAnother = cbMaxAudioDataAnother - cbAudioDataAnother;
    }
	
	//音频数据处理模块
	for (int i = 0; i < cbBuffer; i++)
	{
        //静音
        *(pAudioData + i) = 100;
        //用第二支曲子代替左声道,右声道保持原曲不变
        if((i-2)%4 == 0 )     *(pAudioData + i) = (*(pAudioDataAnother + i)); //屏蔽左声道的第三个字节
        if((i-3)%4 == 0 )     *(pAudioData + i) = (*(pAudioDataAnother + i)); //屏蔽左声道的第四个字节
	  }
	
    // Write data1 and data2 to the output file1 and output file2.
	hr  = WriteToFile(hFile, pAudioData, cbBuffer);
	hr2 = WriteToFile(hFile2, pAudioDataAnother, cbBufferAnother);
	if (FAILED(hr)) { break; }
	if (FAILED(hr2)) { break; }

//......此处省略默认生成的代码

}

3. 运行程序,生成结果音频:

 

如果是静音的话,out1.wav是静音文件,out2.wav是导入的 第二个文件。

如果是声道替换的话,out1.wav文件

  • 6
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

来坛天子笑~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值