答loveMFC19760708问

该博客提供了Windows环境下音频播放的程序代码。先介绍将录音转为wave格式,在VC中新建项目添加资源并编写代码实现播放;还给出了在控制台窗口播放mp3且支持列表的程序,包含文件复制、播放列表填充、随机播放等功能的代码。

先有你MM的录音吧?转成wave格式的,这会吧?

在VC中新建一个空的win32项目,然后添加一个资源,把wave文件加进去,取个ID:MY_WAVE

新建一个CPP文件叫WinMain.cpp,然后添加到源文件文件夹里,在里面写下面的代码:

#include <windows.h>

int WinMain( HINSTANCE hInstance, HINSTANCE, LPSTR, int )
{
return PlaySound( MAKEINTRESOURCE(MY_WAVE), hInstance, SND_RESOURCE|SND_NOWAIT );
}


编译运行就好了

BOOL PlayResource(LPSTR lpName)
{
BOOL bRtn;
LPSTR lpRes;
HANDLE hResInfo, hRes;

// Find the WAVE resource.

hResInfo = FindResource(hInst, lpName, "WAVE");
if (hResInfo == NULL)
return FALSE;

// Load the WAVE resource.

hRes = LoadResource(hInst, hResInfo);
if (hRes == NULL)
return FALSE;

// Lock the WAVE resource and play it.

lpRes = LockResource(hRes);
if (lpRes != NULL) {
bRtn = sndPlaySound(lpRes, SND_MEMORY | SND_SYNC |
SND_NODEFAULT);
UnlockResource(hRes);
}
else
bRtn = 0;

// Free the WAVE resource and return success or failure.

FreeResource(hRes);
return bRtn;
}

===============

PlaySound("C://SOUNDS//BELLS.WAV", NULL, SND_SYNC);

下面这段程序可以在Windows的控制台窗口中播放mp3,支持列表。编译一下就可以运行。

class Globals
{

public:
//## Constructors
Globals(){};

//## Destructor
virtual ~Globals(){};
//## Other Operations (specified)
// This method copies a file.
static bool copyFile (const CString& sourceFilename, const CString& destinationFilename);
//## This method removes a file.
static void removeFile (const CString& filename);

};

class Player
{
public:
//## Constructors
Player(){ srand( (unsigned)time( NULL ) );};

//## Destructor
~Player(){};

//## Other Operations (specified)
#define MAX_FILES 10000
void printinfo ();
void printerror (char * programname);
long fillplaylist (CString& file);
void playmp3(long entries, bool randomplay, bool copy);
protected:

private:
CString playlist[MAX_FILES];
int randomindex[MAX_FILES];

};

#include <stdlib.h>
#include <conio.h>
#include <io.h>
#include <stdio.h>
#include <time.h>
#include <iostream.h>
#include <afx.h>
#include <fstream.h>
#include <mmsystem.h>
#include <winbase.h>
void main (int ArgC, char *ArgV[])
{
Player play;
long entries;
bool randomplay = false;
bool copy = false;
int LV_Option;

play.printinfo ();
if (ArgC < 2)
play.printerror(ArgV[0]);
for(int i = 2; i<ArgC; i++)
{
if(strlen(ArgV[i]) == 1)
{
LV_Option = ArgV[i][0];
switch (LV_Option)
{
case 'r': randomplay = true;
cout << "Note: Playing titles in random order." << endl;
break;
case 'c': copy = true;
cout << "Note: Copy files before playing." << endl;
break;
}
}
}
entries=play.fillplaylist((CString) ArgV[1]);
if (entries > 0)
play.playmp3(entries,randomplay,copy);
cout << "End reached, program terminated normally."<< endl;
};

bool Globals::copyFile (const CString& sourceFilename, const CString& destinationFilename)
{
const int BUF_SIZE = 10480;

ifstream sourceFile;
ofstream destinationFile;
unsigned char *buffer = NULL;

errno = 0;
//cout << "copy file: " << sourceFilename << " to " << destinationFilename<< endl;
sourceFile.open((const char *)sourceFilename,ios::nocreate);
if (sourceFile.fail())
{
cout << "Error opening source file: " << sourceFilename << " Reason: " << strerror(errno) << endl;
return false;
}
sourceFile.setmode(filebuf::binary);

destinationFile.open((const char *)destinationFilename);
if (destinationFile.fail())
{
cout << "Error opening destination file: " << destinationFilename << " Reason: " << strerror(errno) << endl;
return false;
}
destinationFile.setmode(filebuf::binary );
buffer = new unsigned char[BUF_SIZE];
while (!sourceFile.eof())
{
sourceFile.read(buffer, BUF_SIZE);

if ((sourceFile.fail()) && (!sourceFile.eof()))
{
delete buffer;
cout << "Error reading source file: " << sourceFilename << " Reason: " << strerror(errno) << endl;
return false;
}
if (sourceFile.eof())
destinationFile.write(buffer, sourceFile.gcount());
else
destinationFile.write(buffer, BUF_SIZE);

if (destinationFile.fail())
{
delete buffer;
cout << "Error writing to destination file: " << destinationFilename << " Reason: " << strerror(errno) << endl;
return false;
}
} // End-while (!sourceFile.eof())

sourceFile.close();
destinationFile.close();

delete buffer;
return true;
}

void Globals::removeFile (const CString& filename)
{
//cout << "remove file: " << filename << endl;
if (filename.GetLength() > 0)
{
errno = 0;
if (remove((const char *)filename) != 0)
{
cout << "Error deleting file: " << filename << " Reason: " << strerror(errno) << endl;
exit (-1);
}
}
}


void Player::printinfo ()
{
cout << "==========================================================================" << endl;
cout << "=== Simple mp3 player for WIN-DOS ===" << endl;
cout << "=== Version 1.2 ===" << endl;
cout << "=== R. Luff - (c)DG2HL (rluff@gmx.de) (http://visumod.freeshell.org) ===" << endl;
cout << "==========================================================================" << endl <<endl;
}

void Player::printerror (char * programname)
{
cout << "Usage: " << programname << " listfile.lst/m3u, *.mp3 or mp3file.mp3 [r] [c]" << endl << endl;
cout << "Options:" << endl;
cout << "r: random play." << endl;
cout << "c: copy file temporary to hard disk before playing." << endl;
cout << "e.g. " << programname << " c://music//playlist.m3u r" << endl;
cout << "plays titles from playlist file playlist.m3u in random order, do not copy file." << endl << endl;
cout << "During execution press:" << endl;
cout << "q to terminate the program." << endl;
cout << "s to skip a song, the program will continue with the next song in playlist." << endl;
cout << "p for pause mode, press any key to continue playing." << endl;
exit (-1);
}

long Player::fillplaylist (CString& file)
{
long lv_entries = 0;
long i = 0;
if ((file.Find( ".lst" ) > 0 ) || (file.Find( ".m3u" ) > 0 ))
{
//load a playlist
char buffer[200];
ifstream ifile (file);
if (!ifile.fail())
{
cout << "Loading list file: " << file << " .....";
while ((!ifile.eof()) && (i < MAX_FILES))
{
ifile.getline(buffer,sizeof(buffer));
if (buffer[0] != '#')
{
playlist[i] = buffer;
i++;
}
}
cout << " done!" << endl;
lv_entries = i-1;
}
else
{
cout << "Error loading list-file" << endl;
exit (-1);
}
}
if (file.Find(".mp3") > 0)
{
cout << "Getting playlist from directory: " << file << " .....";
//load the directory
struct _finddata_t c_file;
long hFile;
int lastslash;
CString path ="";

//a path given ?? separate it
lastslash = file.ReverseFind('//');
if (lastslash > 0)
{
path = file.Left(lastslash+1);
}
// Find first file in current directory
if( (hFile = _findfirst( file, &c_file )) == -1L )
{
cout << endl << "No file: " << file << " found !" << endl;
exit (-1);
}
else
{
playlist[i] = path + c_file.name;
/* Find the rest of the files */
while( _findnext( hFile, &c_file ) == 0 )
{
i++;
playlist[i] = path + c_file.name;
}
_findclose( hFile );
lv_entries = i+1;
}
cout << " done!" << endl;
}

for ( i = 0; i < lv_entries; i++ )
{
randomindex[i] = 0;
}
return lv_entries;
}

<接上>
void Player::playmp3(long entries, bool randomplay, bool copy)
{
long i;
long stop = 0;
long random;
int ch;
CString title;
//this path is exists everywhere and prevents me to search environment variables
CString tmpplayfile = "c://mp3player.mp3";
CString mci_command;
bool OK;
LPTSTR lpszReturnString =" ";
DWORD fdwError = 0;
UINT cchErrorText=50;

i = 0;
do
{
if (randomplay)
{
do
{
//play playlist in random order, but play all titles once
random = rand()%entries;
}
while (randomindex[random] != 0);
randomindex[random] = 1;
title = playlist[random];
}
else
{
//play playlist in normal order
title = playlist[i];
}
i = i + 1;
OK = false;
if (copy)
{
OK = Globals::copyFile(title, tmpplayfile);
}
else
{
//when the file do not needed to copy, mciSendString do not like the long names with spaces, convert it:
char buf[256];
if (GetShortPathName( title, buf, 256 ) > 0)
{
tmpplayfile = buf;
OK = true;
}
}
if (OK)
{
ch = ' ';

cout << "Playing: " << title << " " << i << " of " << entries << endl;
mci_command = "open ";
mci_command += tmpplayfile;
mci_command += " type MPEGVideo Alias Mp3 wait";
//mciSendString("open c://TEMP//player//Debug//a.mp3 type MPEGVideo Alias Mp3", "", 0, 0);
mciSendString(mci_command, "", 0, 0);
mciSendString("play Mp3", "", 0, 0);
fdwError = mciSendString("status Mp3 mode",lpszReturnString,50, 0);
while ((strcmp(lpszReturnString,"playing") == 0) && (stop == 0))
{
Sleep(2000);
fdwError = mciSendString("status Mp3 mode",lpszReturnString,50, 0);
//mciGetErrorString(fdwError, lpszReturnString, cchErrorText );
if( _kbhit() )
{
ch = _getch();
ch = toupper( ch );
if (ch == 'Q')
{
cout << "Note: Normal termination by user. Playlist not completely finnished" << endl;
stop = 1;
}
if (ch == 'S')
{
cout << "Note: Song skipped by user" << endl;
stop = 1;
}
if (ch == 'P')
{
mciSendString("pause Mp3", "", 0, 0);
cout << "Note: Pause, press any key to continue" << endl;
ch = _getch();
mciSendString("play Mp3", "", 0, 0);
}
}
//cout << "TEST>>" << lpszReturnString<< "<<TEST" << endl;
}
mciSendString("close Mp3 wait", "", 0, 0);
stop = 0;
if (copy)
Globals::removeFile(tmpplayfile);
else
Sleep(2000);
}
//check if q buttom has been pressed on keyboard
}
while (i != entries && ch != 'Q' );
}


内容面向制造业的鲁棒机器学习集成计算流程研究(Python代码实现)概要:本文围绕“面向制造业的鲁棒机器学习集成计算流程研究”展开,重点探讨了如何在制造环境中构建具备强鲁棒性的机器学习集成计算框架,并提供了基于Python的代码实现。研究聚焦于应对制造业中常见的数据不确定性、噪声干扰和工况变化等题,提出了一套集成化的计算流程,涵盖数据预处理、特征工程、模型训练、集成学习策略以及鲁棒性优化机制。文中强调通过多模型融合、异常检测、自适应学习等技术提升系统稳定性与泛化能力,适用于复杂工业场景下的预测、分类与质量控制任务。; 适合人群:具备一定Python编程基础和机器学习知识,从事智能制造、工业数据分析、自动化控制等相关领域的科研人员及工程技术人员,尤其适合研究生、企业研发人员及工业AI项目开发者。; 使用场景及目标:①应用于工业生产过程中的质量预测、故障诊断与能效优化;②构建抗干扰能力强的智能制造决策系统;③实现对多源异构工业数据的高效建模与稳定推理,提升生产线智能化水平。; 阅读建议:建议结合文中提供的Python代码实例,配合实际工业数据集进行复现与调优,重点关注集成策略与鲁棒性模块的设计逻辑,同时可扩展应用于其他工业AI场景。
求解大规模带延迟随机平均场博弈中参数无关CSME的解法器研究(Matlab代码实现)内容概要:本文围绕“求解大规模带延迟随机平均场博弈中参数无关CSME的解法器研究”展开,提出了一种基于Matlab代码实现的数值解法,旨在有效求解带有时间延迟的随机平均场博弈题中的参数无关CSME(Coupled System of Mean Field Equations)。研究聚焦于构建高效的数值计算框架,克服传统方法在处理高维、非线性与延迟耦合系统时的计算瓶颈,提升解法器的稳定性与收敛性。文中详细阐述了数学模型构建、算法设计思路及关键步骤的Matlab实现,通过仿真实验验证了所提方法在不同场景下的有效性与鲁棒性。同时,文档列举了大量相关科研方向与Matlab应用案例,涵盖电力系统、路径规划、信号处理、机器学习等多个领域,展示了Matlab在复杂系统仿真与优化中的广泛应用能力。; 适合人群:具备一定数学建模与Matlab编程基础,从事控制理论、博弈论、优化算法或相关工程仿真研究的研究生、博士生及科研人员。; 使用场景及目标:①深入理解带延迟的随机平均场博弈建模与CSME求解机制;②掌握利用Matlab实现复杂非线性系统数值求解的技术方法;③借鉴文中的算法设计思路与代码框架,应用于自身科研项目中的系统仿真与优化题。; 阅读建议:建议读者结合文中提供的Matlab代码实例,逐步调试与运行关键算法模块,加深对理论推导与数值实现之间联系的理解。同时可参考文档末尾列出的相关研究方向与代码资源,拓展研究视野,提升科研效率。 ```
内容概要:本文介绍了一个基于Java和Vue的书法笔迹特征的字体鉴别与生成系统的设计与实现,融合深度学习与全栈开发技术。系统通过卷积神经网络(CNN)结合注意力机制提取书法笔迹的多层次特征,利用多标签分类与对比学习模型实现字体风格的高效鉴别,并采用条件生成对抗网络(CGAN)实现个性化字体的自动生成。后端基于Spring Boot框架处理数据管理与AI服务调度,前端使用Vue.js构建交互友好的界面,结合Elasticsearch实现大规模书法数据的快速检索。系统还构建了书法样本数据库,支持风格标注、相似性搜索与动态优化,形成集特征提取、风格识别、字体生成与数据管理于一体的智能化平台。; 适合人群:具备一定Java、Vue和深度学习基础,从事全栈开发、AI应用研发或对数字人文、文化遗产保护感兴趣的研发人员、高校师生及技术人员。; 使用场景及目标:①应用于书法艺术的数字化保护与风格鉴别;②支持书法教育中的笔迹分析与教学辅助;③服务于艺术品鉴定、个性化字体设计及文化创意产业的AI生成需求;④为研究人员提供可扩展的书法数据分析与模型实验平台; 阅读建议:此资源包含完整的模型描述与代码示例,建议结合前后端实现与AI模型训练流程进行系统学习,重点关注特征提取、多标签分类、GAN生成及Elasticsearch检索的集成应用,并通过实际调试加深对系统架构与算法协同的理解。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值