DirectSound + Framework

boycxd 2011-01-06 12:59:54
同样的程序使用Framework 4.0调用DirectSound就不行,程序死住了.用3.5可以
是不是direct版本的事呀,我使用的是9,应该使用什么版本?怎么解决?希望给个完整的解决办法.
程序在下:
http://www.codeproject.com/KB/directx/AmbientSounds.aspx
...全文
74 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复
不错的dx11入门教程 Tutorial 1: Setting up DirectX 11 with Visual Studio Tutorial 2: Creating a Framework and Window Tutorial 3: Initializing DirectX 11 Tutorial 4: Buffers, Shaders, and HLSL Tutorial 5: Texturing Tutorial 6: Diffuse Lighting Tutorial 7: 3D Model Rendering Tutorial 8: Loading Maya 2011 Models Tutorial 9: Ambient Lighting Tutorial 10: Specular Lighting Tutorial 11: 2D Rendering Tutorial 12: Font Engine Tutorial 13: Direct Input Tutorial 14: Direct Sound Tutorial 15: FPS, CPU Usage, and Timers Tutorial 16: Frustum Culling Tutorial 17: Multitexturing and Texture Arrays Tutorial 18: Light Maps Tutorial 19: Alpha Mapping Tutorial 20: Bump Mapping Tutorial 21: Specular Mapping Tutorial 22: Render to Texture Tutorial 23: Fog Tutorial 24: Clipping Planes Tutorial 25: Texture Translation Tutorial 26: Transparency Tutorial 27: Reflection Tutorial 28: Screen Fades Tutorial 29: Water Tutorial 30: Multiple Point Lights Tutorial 31: 3D Sound Tutorial 32: Glass and Ice Tutorial 33: Fire Tutorial 34: Billboarding Tutorial 35: Depth Buffer Tutorial 36: Blur Tutorial 37: Coming Soon... DirectX 10 Tutorials: Tutorial 1: Setting up DirectX 10 with Visual Studio Tutorial 2: Creating a Framework and Window Tutorial 3: Initializing DirectX 10 Tutorial 4: Buffers, Shaders, and HLSL Tutorial 5: Texturing Tutorial 6: Diffuse Lighting Tutorial 7: 3D Model Rendering Tutorial 8: Loading Maya 2011 Models Tutorial 9: Ambient Lighting Tutorial 10: Specular Lighting Tutorial 11: 2D Rendering Tutorial 12: Font Engine Tutorial 13: Direct Input Tutorial 14: Direct Sound Tutorial 15: FPS, CPU Usage, and Timers Tutorial 16: Frustum Culling Tutorial 17: Multitexturing and Texture Arrays Tutorial 18: Light Maps Tutorial 19: Alpha Mapping Tutorial 20: Bump Mapping Tutorial 21: Specular Mapping Tutorial 22: Render to Texture Tutorial 23: Fog Tutorial 24: Clipping Planes Tutorial 25: Texture Translation Tutorial 26: Transparency Tutorial 27: Reflection Tutorial 28: Screen Fades Tutorial 29: Water Tutorial 30: Multiple Point Lights Tutorial 31: 3D Sound Tutorial 32: Glass and Ice Tutorial 33: Fire Tutorial 34: Billboarding Tutorial 35: Depth Buffer Tutorial 36: Blur Tutorial 37: Coming Soon... DirectX 10 Terrain Tutorials: Tutorial 1: Grid and Camera Movement Tutorial 2: Height Maps Tutorial 3: Terrain Lighting Tutorial 4: Terrain Texturing Tutorial 5: Color Mapped Terrain Tutorial 6: Quad Trees Tutorial 7: Coming Soon... 。。。。。。。。
特点:- 开源诚交志友、任您扩展- 文本语音让您“爱上”聊- 隐蔽型设计、老板键支持- 无视防火墙局域网关障碍- 线程运用及周全的缓冲架构- XML/XSL呈现技术浏览地址:http://www.favnet.cn/Exhibition.aspx?OriginalKeyword=&OriginalPageIndex=0&OriginalPageSize=7&OriginalId=20080423075449842429■ “FavChat 爱聊”平台分为客户端(Windows Application)和服务端(Web Service)两部分,两者采用当前时尚的HTTP/SOAP协议进行通讯,服务器端采用特殊数据结构作为数据的交换媒介,由客户端收集客户操作请求主动连接服务器发送和接受数据来完成事务流程。由于自身技术和协议的优势,基本上可以无视防火墙和局域网关障碍,唯一前提是您具备一个支持服务器端Web Service运行的空间。■ 考虑FavChat实际工作中的计算机因素和网络延迟,平台充分地利用线程并发运作和多阶段队列缓冲机制,保证事务处理的顺畅和聊天过程中最重要的全双工能力的完美实现。(参考附件流程图)■ 语音部分则使用当前比较流行的DirectX技术实现。由于该领域网上的资料不多,所以我也是在不断的试验和摸索中找到门路,已封装好的Recorder(录音机)和Player(播放器)类,理应有比较大的参考学习和应用价值。■ 本平台的设计初衷其实是为方便我和妻子日常交流,大型企业里一般都限制即时通讯软件的使用,于是我运用所学开发了具备一定隐蔽性和系统热键功能的私人聊天工具,加上通用型的HTTP协议和XML节点内的密码验证,即使有上网记录也难查出是在干啥米 ^_^ 与爱人聊,会让您越来越“爱聊”哦,客户端通过修改本地配置参数还可以轻易实现个性化的多方畅聊……■ XML也是不得不说的一块,Web Service通讯和本地消息框的呈现,都使用了相关的处理方法。可以说XML是当代程序里不可或缺的一项重要通用技术。FavChat作为开源项目,作者仅在FavNet.cn(附件)和CSDN网站原创发布,其它网站皆为转载,您可以下载源程序参考或进行自由扩展,但请尊重分享,尊重开源,保留作者的版权信息或注明来源。项目使用Visual Studio 2008基于.NET Framework 2.0兼容模式开发,您若使用Visual Studio 2005打开,在编译时会出现错误(少量无法识别的C#3.0语法),您可能有必要修改少量非核心代码即可解决。另外,您还需要安装微软 DirectX End-User Runtimes(March 2008)以获得对Microsoft.DirectX和Microsoft.DirectX.DirectSound命名空间的支持。如果您是志同道合的朋友,可以给我来信(HeddaZ@live.com)交流,亦很乐意提供底层的Source互相学习探讨。本程序不尽完善,还请各位同僚前辈指教……谢谢!程序采用WinRAR压缩打包-----------FavNet.cn 专勤致精想您所思 专业IT技术服务http://www.FavNet.cn展示技术实力,寻求合作伙伴、合作项目中…… --------------------------------------------- Powered by FavNet.cn 专业IT技术服务 [Plusii 您的企业附加值]旗下品牌
基于DirectSound的简易播放器 #include "stdafx.h" #include "test.h" #include "testDlg.h" #include "process.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // CAboutDlg dialog used for App About class CAboutDlg : public CDialog { public: CAboutDlg(); // Dialog Data enum { IDD = IDD_ABOUTBOX }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support // Implementation protected: DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) END_MESSAGE_MAP() // CtestDlg dialog CtestDlg::CtestDlg(CWnd* pParent /*=NULL*/) : CDialog(CtestDlg::IDD, pParent) { m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CtestDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CtestDlg, CDialog) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() //}}AFX_MSG_MAP ON_BN_CLICKED(IDC_BUTTON_OPEN, &CtestDlg::OnBnClickedButtonOpen) ON_BN_CLICKED(IDC_BUTTON_PLAY, &CtestDlg::OnBnClickedButtonPlay) ON_WM_DESTROY() ON_BN_CLICKED(IDC_BUTTON_STOP, &CtestDlg::OnBnClickedButtonStop) END_MESSAGE_MAP() //ON_BN_CLICKED(IDC_Sound_Play, OnSound2) //ON_BN_CLICKED(IDC_Sound_stop, OnSound1) //ON_BN_CLICKED(IDC_sound_pause, OnBothSounds) //ON_WM_DESTROY() //ON_BN_CLICKED(IDC_BUTTON_Slow, OnBUTTONSlow) //ON_BN_CLICKED(IDC_BUTTON_Fast, OnBUTTONFast) //ON_BN_CLICKED(IDC_BUTTON_Normal, OnBUTTONNormal) // CtestDlg message handlers BOOL CtestDlg::OnInitDialog() { CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // TODO: Add extra initialization here m_sndSound1 = new CDirectSound(); if(!m_sndSound1) { exit(-1); } return TRUE; // return TRUE unless you set the focus to a control } void CtestDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID, lParam); } } // If you add a minimize button to your dialog, you will need the code below // to draw the icon. For MFC applications using the document/view model, // this is automatically done for you by the framework. void CtestDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } } // The system calls this function to obtain the cursor to display while the user drags // the minimized window. HCURSOR CtestDlg::OnQueryDragIcon() { return static_cast(m_hIcon); } //--------------------------------------------------------------------------------- void CtestDlg::OnBnClickedButtonOpen() { // TODO: Add your control notification handler code here LPCTSTR lpszFilter =L"Wave File(*.wav)|*.wav|All Files|*.*||"; CFileDialog dlg(TRUE,NULL,NULL,/*OFN_HIDEREADONLY |*/ OFN_OVERWRITEPROMPT,lpszFilter); if(dlg.DoModal()==IDOK) { m_soundfile = dlg.GetPathName(); } } // unsigned int WINAPI FileReadProc(LPVOID pOwner) { CtestDlg* pThis = (CtestDlg*)pOwner; pThis->ReadFileProc(); return 1; } // typedef struct _WAVE_FORMAT { WORD AudioFormat; WORD NumChannels; DWORD SampleRate; DWORD ByteRate; WORD BlockAlign; WORD BitsPerSample; }WAVE_FORMAT,*PWAVE_FORMAT; void CtestDlg::OnBnClickedButtonPlay() { // TODO: Add your control notification handler code here if(m_soundfile.IsEmpty()) { MessageBox(L"请选中播放文件!"); return; } USES_CONVERSION; fp = fopen(W2A(m_soundfile.GetBuffer(m_soundfile.GetLength())),"rb"); if(NULL == fp) { MessageBox(L"打开所所定的播放文件失败,请确认文件是否存在!"); return; } fseek(fp,20,0); //Skip previous 20 bytes RIFF header WAVE_FORMAT waveFormat; int nLen =fread(&waveFormat,1,sizeof(WAVE_FORMAT),fp); AUDIO_CONFIG WaveHead; WaveHead.wFormatTag = 1; WaveHead.nChannels = 2; WaveHead.nSamplesPerSec = 44100; WaveHead.nAvgBytesPerSec = 176400; WaveHead.nBlockAlign = 4; WaveHead.wBitsPerSample = 16; WaveHead.nBlockAlign=waveFormat.BlockAlign; WaveHead.nChannels=waveFormat.NumChannels; WaveHead.nSamplesPerSec=waveFormat.SampleRate; WaveHead.wBitsPerSample=waveFormat.BitsPerSample; WaveHead.nAvgBytesPerSec=waveFormat.ByteRate; m_sndSound1->CreateDSound(&WaveHead,8000); fseek(fp,20+sizeof(WAVE_FORMAT),0); unsigned int dwReadID; m_hThread = (HANDLE)_beginthreadex(0,0,FileReadProc,this,0,&dwReadID); Sleep(200); m_bStop = 0; m_bContine = 1; m_sndSound1->Play(); } void CtestDlg::ReadFileProc() { //BYTE buf[1025]; int n = 0; while(1) { BYTE buf[1025]; int nlen; if(m_bStop) break; nlen = fread(buf,1,1024,fp); if(!nlen) break; while(m_sndSound1->WriteDataToBuf(buf,nlen)==-1) { Sleep(100); } } if(fp) { fclose(fp); fp = NULL; } } void CtestDlg::OnDestroy() { CDialog::OnDestroy(); // TODO: Add your message handler code here m_bStop = 1; OnBnClickedButtonStop(); if(m_hThread) { WaitForSingleObject(m_hThread,2000); CloseHandle(m_hThread); m_hThread = 0; } if(m_sndSound1) { delete m_sndSound1; m_sndSound1 = NULL; } if(fp) { fclose(fp); fp = NULL; } } void CtestDlg::OnBnClickedButtonStop() { // TODO: Add your control notification handler code here m_bStop = 1; if(m_hThread) { WaitForSingleObject(m_hThread,2000); CloseHandle(m_hThread); m_hThread = NULL; } m_sndSound1->Stop(); }

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧