DirectSound的一个例子

DirectSound简单的概述|DirectSound SDK文档翻译 DirectSound开始使用DirectSound这个部分将会介绍设置和调试DirectSound工程,还有播放声音所需步骤的简短概述。1.编译DirectSound工程工程应当包含DSound.h头文件。如果DirectSound和DirectMusic一起用,还要包含Dmusici.h头文件。如果想直接使用DirectSoundAPI,调用函数,应当确保连接到Dsound.lib,当然库的地 阅读详情
 #include <windows.h>
#include <ddraw.h>
#include <dsound.h>
 
IDirectDraw *dd;
IDirectDrawSurface *dds0, *dds1, *dds2, *dds3;
IDirectDrawClipper *ddc;
IDirectSound *ds;
IDirectSoundBuffer *dsb1, *dsb2;
 
int x = 20, y = 20;
int vx = 5, vy = 3;
 
void MoveBall(HWND hwnd, BOOL bMove)
{
    BOOL bBounce = FALSE;
    RECT rectSrc, rectDest;
    int ox, oy, nx, ny;
    GetClientRect(hwnd, &rectDest);
    ClientToScreen(hwnd, (POINT *)&rectDest.left);
    ClientToScreen(hwnd, (POINT *)&rectDest.right);
    if (bMove)
    {
        ox = rectDest.left +
             MulDiv(rectDest.right - rectDest.left - 32, x, 500);
        oy = rectDest.top +
             MulDiv(rectDest.bottom - rectDest.top - 32, y, 500);
        x += vx;
        y += vy;
        if (x < 0) { x = 0; vx = -vx; bBounce = TRUE; }
        if (x >= 500) { x = 1000 - x; vx = -vx; bBounce = TRUE; }
        if (y < 0) { y = -y; vy = -vy; bBounce = TRUE; }
        if (y >= 500) { y = 1000 - y; vy = -vy; bBounce = TRUE; }
        if (bBounce)
        {
            dsb1->SetCurrentPosition(0);
            dsb1->Play(0, 0, 0);
        }
    }
    nx = rectDest.left +
         MulDiv(rectDest.right - rectDest.left - 32, x, 500);
    ny = rectDest.top +
         MulDiv(rectDest.bottom - rectDest.top - 32, y, 500);
    rectSrc.left = rectSrc.top = 0;
    rectSrc.right = rectSrc.bottom = 32;
    if (bMove)
    {
        rectDest.left = rectDest.top = 0;
        rectDest.right = rectDest.bottom = 32;
        dds2->Blt(&rectDest, dds3, &rectSrc, DDBLT_WAIT, NULL);
        if (abs(nx - ox) < 32 && abs(ny - oy) < 32)
        {
            if (nx < ox)
            {
                rectSrc.left = ox - nx;
                rectSrc.right = 32;
                rectDest.left = 0;
                rectDest.right = 32 - rectSrc.left;
             }
            else
            {
                rectDest.left = nx - ox;
                rectDest.right = 32;
                rectSrc.left = 0;
                rectSrc.right = 32 - rectDest.left;
            }
            if (ny < oy)
            {
                rectSrc.top = oy - ny;
                rectSrc.bottom = 32;
                rectDest.top = 0;
                rectDest.bottom = 32 - rectSrc.top;
            }
            else
            {
                rectDest.top = ny - oy;
                rectDest.bottom = 32;
                rectSrc.top = 0;
                rectSrc.bottom = 32 - rectDest.top;
            }
            dds2->Blt(&rectDest, dds1, &rectSrc, DDBLT_WAIT, NULL);
         }
         rectSrc.left = rectSrc.top = 0;
         rectSrc.right = rectSrc.bottom = 32;
         rectDest.left = ox;
         rectDest.top = oy;
         rectDest.right = rectDest.left + 32;
         rectDest.bottom = rectDest.top + 32;
         dds0->Blt(&rectDest, dds2, &rectSrc, DDBLT_WAIT, NULL);
    }
    rectDest.left = nx;
    rectDest.top = ny;
    rectDest.right = rectDest.left + 32;
    rectDest.bottom = rectDest.top + 32;
    dds0->Blt(&rectDest, dds1, &rectSrc, DDBLT_WAIT, NULL);
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg,
                         WPARAM wParam, LPARAM lParam)
{
    HDC hDC;
    PAINTSTRUCT paintStruct;
    switch(uMsg)
    {
        case WM_PAINT:
            hDC = BeginPaint(hwnd, &paintStruct);
            if (hDC != NULL)
            {
                MoveBall(hwnd, FALSE);
                EndPaint(hwnd, &paintStruct);
            }
            break;
        case WM_TIMER:
            MoveBall(hwnd, TRUE);
            break;
        case WM_KEYDOWN:
            switch (wParam)
            {
                case VK_LEFT: vx--; break;
                case VK_UP: vy--; break;
                case VK_RIGHT: vx++; break;
                case VK_DOWN: vy++; break;
                case VK_ESCAPE: PostMessage(hwnd, WM_CLOSE, 0, 0);
            }
            break;
        case WM_DESTROY:
            PostQuitMessage(0);
            break;
        default:
            return DefWindowProc(hwnd, uMsg, wParam, lParam);
      }
    return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                                        LPSTR d3, int nCmdShow)
{
    MSG msg;
    HWND hwnd;
    WNDCLASS wndClass;
    DDSURFACEDESC ddsd;
    DSBUFFERDESC dsbd;
    HDC hddDC;
    RECT rect;
    HRSRC hrsrc;
    HGLOBAL hRData;
    DWORD *pRData;
    LPBYTE pMem1, pMem2;
    DWORD dwSize1, dwSize2;
    if (hPrevInstance == NULL)
    {
        memset(&wndClass, 0, sizeof(wndClass));
        wndClass.style = CS_HREDRAW | CS_VREDRAW;
        wndClass.lpfnWndProc = WndProc;
        wndClass.hInstance = hInstance;
        wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
        wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
        wndClass.lpszClassName = "BOUNCE";
        if (!RegisterClass(&wndClass)) return FALSE;
   }
    hwnd = CreateWindow("BOUNCE", "BOUNCE",
                         WS_OVERLAPPEDWINDOW,
                         CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
                         NULL, NULL, hInstance, NULL);
    DirectDrawCreate(NULL, &dd, NULL);
    dd->SetCooperativeLevel(hwnd,
                            DDSCL_NORMAL | DDSCL_NOWINDOWCHANGES);
    memset(&ddsd, 0, sizeof(DDSURFACEDESC));
    ddsd.dwSize = sizeof(DDSURFACEDESC);
    ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
    ddsd.dwFlags = DDSD_CAPS;
    dd->CreateSurface(&ddsd, &dds0, NULL);
    dd->CreateClipper(0, &ddc, NULL);
    dds0->SetClipper(ddc);
    ddc->SetHWnd(0, hwnd);
    ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
    ddsd.dwHeight = 32;
    ddsd.dwWidth = 32;
    ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
    dd->CreateSurface(&ddsd, &dds1, NULL);
    dd->CreateSurface(&ddsd, &dds2, NULL);
    dd->CreateSurface(&ddsd, &dds3, NULL);
    dds1->GetDC(&hddDC);
    SaveDC(hddDC);
    rect.left = rect.top = 0;
    rect.right = rect.bottom = 32;
    FillRect(hddDC, &rect, (HBRUSH)(COLOR_WINDOW + 1));
    SelectObject(hddDC, GetStockObject(BLACK_BRUSH));
    SelectObject(hddDC, GetStockObject(BLACK_PEN));
    Ellipse(hddDC, 0, 0, 32, 32);
    RestoreDC(hddDC, -1);
    dds1->ReleaseDC(hddDC);
    dds3->GetDC(&hddDC);
    FillRect(hddDC, &rect, (HBRUSH)(COLOR_WINDOW + 1));
    dds3->ReleaseDC(hddDC);
    DirectSoundCreate(NULL, &ds, NULL);
    ds->SetCooperativeLevel(hwnd, DSSCL_NORMAL);
    memset(&dsbd, 0, sizeof(DSBUFFERDESC));
    dsbd.dwSize = sizeof(DSBUFFERDESC);
 dsbd.lpwfxFormat=(LPWAVEFORMATEX)(pRData + 5);
    ds->CreateSoundBuffer(&dsbd, &dsb1, NULL);
    dsb1->Lock(0, dsbd.dwBufferBytes,(void**) &pMem1, &dwSize1,
                                      (void**)&pMem2, &dwSize2, 0);
    memcpy(pMem1, (LPBYTE)(pRData + 11), dwSize1);
    if (dwSize2 != 0)
        memcpy(pMem2, (LPBYTE)(pRData + 11) + dwSize1, dwSize2);
    dsb1->Unlock(pMem1, dwSize1, pMem2, dwSize2);
    hrsrc = FindResource(hInstance, "HUM.WAV", "WAVE");
    hRData = LoadResource(hInstance, hrsrc);
    pRData = (DWORD *)LockResource(hRData);
    dsbd.dwBufferBytes = *(pRData + 10);
    dsbd.lpwfxFormat = (LPWAVEFORMATEX)(pRData + 5);
    ds->CreateSoundBuffer(&dsbd, &dsb2, NULL);
    dsb2->Lock(0, dsbd.dwBufferBytes, (void**)&pMem1, &dwSize1,
                                      (void**)&pMem2, &dwSize2, 0);
    memcpy(pMem1, (LPBYTE)(pRData + 11), dwSize1);
    if (dwSize2 != 0)
        memcpy(pMem2, (LPBYTE)(pRData + 11) + dwSize1, dwSize2);
    dsb2->Unlock(pMem1, dwSize1, pMem2, dwSize2);
    dsb2->Play(0, 0, DSBPLAY_LOOPING);
    ShowWindow(hwnd, nCmdShow);
    UpdateWindow(hwnd);
    SetTimer(hwnd, 1, 100, NULL);
    while (GetMessage(&msg, NULL, 0, 0))
        DispatchMessage(&msg);
    KillTimer(hwnd, 1);
    return msg.wParam;
} 
利用Directsound编程实现实时混音  摘要:将多个音频文件或多路音频数据同时输出到音频输出设备上,就可同时听到多个不同的声音,这就是混音。在游戏开发,网络视频会议开发中都会用到混音技术,本文详细介绍如何利用Directsound实现几路不同的音频进行实时的混音。   关键词:Directsound 混音  在游戏开发中比较常用的音效素材都是比较短的,所以一般常用的API是playsound()函数,比如我们要在游戏背景中播放一个te 阅读详情

相关推荐

excelimportor 批量导入 Excel 数据的关键技巧与避坑指南

在数据处理工程中,Excel 批量导入是最常见的需求之一。借助 pandas 等工具可以快速读取表格,但面对脏数据、类型推断和空值策略时,开发者常常要花不少精力排查与修复。ExcelImporter 这类封装工具将“读 Excel 并整理成结构化数据”的流程收敛为固定参数,配合 openpyxl 和 xlrd 引擎,能有效处理表头、数据类型、多 sheet 等场景。通过合理的 dtype 映射和空值策略,可以避免订单号前导零丢失、xls/xlsx 引擎混用、大文件内存溢出一系列实际问题。在数据迁移、报表接入

weixin_34405557的博客 336

DirectX基础示例

/* * Author: Leng_que * Date: 2009/08/29 * E-mail: leng_que@yahoo.com.cn * Description: Draw a triangle by DirectX 9.0 */#include #pragma comment(linker, "/subsystem:windows")#

冷却 718

C# 调用DirectX开发例子20个

我就不加分了,不知道CSDN里有没有,这是我找的C#开发Directx的例子源码,如果这里已经有了,就看一样不一样了,我这里有20个项目的源码,版主决定吧!对了,提醒大家,需要先安装DirectX的SDK,顺便说一下下载位置:http://www.crsky.com/soft/153.html,也可以到微软的主页下载最新的SDK。看了一下,大家都要分呢,我也要一点吧

一个DirectSound的例子

一个捕获音频并且播放的例子,可以用来唱歌^_^ 写了半天才发现Direct SDK有个类似的例子,所以到了最后几乎都是照抄了。 声音效果不太好,修改一下加上网络传送功能做成语音聊天工具。不过这样肯定不行,真正的语音聊天可能都要音频数

小发猫 2257

RK3568(buildroot)利用squashfs+overlay实现嵌入式系统高可靠存储方案

本文详细介绍了在RK3568嵌入式平台上,基于Buildroot系统,利用squashfs只读根文件系统与overlayfs可写层相结合的高可靠存储方案。该方案能有效防止设备意外断电导致的系统文件损坏,通过内核配置、启动脚本编写及镜像制作,实现系统核心的只读保护与用户数据的持久化分离,显著提升嵌入式设备的现场稳定性。

weixin_29189381的博客 557

02.1 知识图谱工具 Protege的下载安装与使用

Protege的下载安装与使用 本文是王昊奋老师《知识图谱》系列笔记第2.1篇。 文章目录Protege的下载安装与使用0 相关介绍0.0 Protege相关介绍0.1 Protégé的特点0.2 Protégé的用途1 Protege的下载1.1 准备工作:安装配置JAVA环境1.2 官网下载2 Protege的安装2.1 直接解压缩2.2 双击运行3 Protege的使用实例-创建类...

和而不流 7万+

游戏开发新手入门之位图化图形

简介    终于,你已经掌握了制作一个完整游戏的基础知识了,只不过你现在还只能使用GDI。今天,我们就学习使用DirectX来执行每一件你以前用GDI完成的工作,以及一些关于DirectX其它的东东。具体内容是:装载(调用)位图,使用位块传输,填充表面,使用剪裁板、颜色键

xah18的专栏 1115

c语言播放背景音乐

相信很多童鞋都在为大学课设而伤透头脑,而背景音乐的使用无疑会成为其中的一个亮点(总比没有好吧(╯▽╰)),故接下来我将介绍一下如何用C播放音乐。我用的编译器是CodeBlocks16.01接下来新建一个C文件建立完后是这样滴然后添加其中mciSendString()函数是由&lt;mmsystem.h&gt;库提供的供播放音乐(MP3)的函数第一个参数是歌曲所在的绝对路径 打开音乐所在位置 复制这...

qq_41443987的博客 3万+

DirectX的一个例子

#include #include #include  IDirectDraw *dd; IDirectDrawSurface *dds0, *dds1, *dds2, *dds3; IDirectDrawClipper *ddc; IDirectSound *ds; IDirectSoundBuffer *dsb1, *dsb2;  int x = 20, y = 20; int vx =

qianbo_0423的专栏 qq:418511899 18710866728 1222

FPGA实战:MIG IP核AXI接口DDR3读写优化指南

本文详细解析了FPGA中MIG IP核AXI接口的DDR3读写优化策略,涵盖关键参数配置、突发传输技巧及时序收敛方案。通过AXI接口优化和突发长度选择,可实现高达12.8GB/s的理论带宽,提升DDR3访问效率。文章还提供了Vivado配置实例和调试技巧,助力开发者解决FPGA内存控制中的实际问题。

weixin_29168393的博客 551

CodeQL查询时遇到报错:A fatal error occurred: Could not process query metadata for...如何解决?

🏆本文收录于 《全栈Bug调优(实战版)》 专栏,该专栏专注于分享我在真实项目开发中遇到的各类疑难Bug及其深层成因,并系统提供高效、可复现的解决思路和实操方案。无论你是刚入行的新手开发者,还是拥有多年项目经验的资深工程师,本专栏都将为你提供一条系统化、高质量的问题排查与优化路径,助力你加速成长,攻克技术壁垒,迈向技术价值最大化与职业发展的更高峰🚀!

**My Coding Family** 1089

【C】借助DirectSound进行流的形式无缝播放的例子

DirectSound是DirectX的一个组件。用于播放声音、BGM等。和DirectMusic不一样,DirectSound用于播放波形声音(WAV无损等),而不是midi音乐。通常大家使用DirectSound是直接把一个声波数据全部载入到一个IDirectSoundBuffer或IDirectSoundBuffer8里面,然后直接调用IDirectSoundBuffer::Play或IDi...

imxiangzi的专栏 1428

模拟电子技术基础(第四版)教材 电子版

今天给大侠带来“模拟电子技术基础(第四版)教材 电子版”,获取电子版资料,请在“FPGA技术江湖”公众号内回复“模拟电子技术基础(第四版)教材 电子版”,即可获取。话不多说,上货。 下面给各位大侠列一下目录,可以瞅一瞅是不是自己需要,电子版方便携带,可也省去一笔开销,不过学习起来没有实体书籍得劲,学习要认真哦。 《模拟电子技术基础(第四版)教材》电子版目录如下: 第一章 常用半导体器件 第二章 基本放大电路 第三章 多级放大电路 第四章 集成运算放大电路 第五章 放大电路...

3万+

一个DirectSound的例子,即录即放

一个捕获音频并且播放的例子,可以用来唱歌^_^写了半天才发现Direct SDK有个类似的例子,所以到了最后几乎都是照抄了。声音效果不太好,修改一下加上网络传送功能做成语音聊天工具。不过这样肯定不行,真正的语音聊天可能都要音频数据处理啊等功能的。我是想试这做个东西来唱歌,不过效果不好!程序错误很多,有很多地方可以改进的,不过我一贯的作风是浅尝即止。 部分代码----

施昌权专栏 1132

15、z/OS 优化配置与迁移实践

本文详细探讨了z/OS环境的优化配置与迁移实践,涵盖DASD存储库管理、用户目录更新、环境更新意义以及不同场景下的迁移案例。通过单笔记本系统和服务器级机器的实例,展示了迁移流程和关键要点,包括DASD文件创建、设备映射更新、系统重启初始化以及数据备份等步骤。文章还总结了迁移过程中的注意事项,并展望了未来z/OS优化的发展趋势,为z/OS系统的稳定运行和高效管理提供了实用指导。

zzz56的博客 137

基于STM32、HAL库的RN8209D电能计量芯片驱动程序设计

/ 假设电压互感器变比为220V:0.5V,电流互感器变比为20A:5mA。// 电压ADC原始值。// 电流ADC原始值。// 有功功率(W)// 电能(kWh)

corlin6688的博客 473

DirectSound的例子程序CaptureSound(.NET version)的一个Bug

最近笔者在.NET平台上学着使用DirectSound来做一个简单的录音和WAV文件合并的功能, 当然DirectX自带的CaptureSound例子提供了一切录音的源代码,不过我发现其中有个Bug,导致Release版本的程序无辜退出。DirectX SDK的版本: August 2007.代码(位于文件MainForm.cs):void InitNotifications(){

Wrote Ideas Down, Together with Skills 1439

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

在 Delphi 下使用 DirectSound (13): 测试回声效果器 IDirectSoundFXEcho8

{相关结构:} TDSFXEcho = packed record fWetDryMix: Single; //0 .. 100 : 50 (%) fFeedback: Single; //0 .. 100 : 50 (%) fLeftDelay: Single; //1 .. 2000 : 500(ms) fRightDelay: Single; //1...

weixin_34303897的博客 205

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

C++播放wav音乐和音效

1. #include <mmsystem.h>#pragma comment(lib,"winmm.lib")PlaySound(TEXT("c:\\temp\\up.wav"), NULL, SND_FILENAME | SND_ASYNC | SND_LOOP ); wav文件在播放前将被装入内存,所以不能太大。只能同时播放一个声音。后一个声音会关闭前一个声音...

851

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

VB.NET实现DirectSound9 (6) 声音特效

VB.NET实现DirectSound9 (6) 声音特效 关键字: VB.NET DirectSound 9 声音特效 回声Echo 作者:董含君转载请注明来自:http://blog.csdn.net/a11s实际上这个就是传说的混音,微软把各种效果添加起来变成了混音程序严格的讲,这个算作声音的...

weixin_34050389的博客 104

最简单的视音频播放示例8:DirectSound播放PCM

本文记录DirectSound播放音频的技术。DirectSound是Windows下最常见的音频播放技术。目前大部分的音频播放应用都是通过DirectSound来播放的。本文记录一个使用DirectSound播放PCM的例子。注:一位仁兄已经提醒我DirectSound已经计划被XAudio2取代了。后来考证了一下发现确有此事。因此在下次更新中考虑加入XAudio2播放PCM的例子。本文仍然记...

SurpassLi的专栏 162

DiriectX播放mp3

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using Microsoft.DirectX.

435

DirectSound应用

<br />关于DirectSound<br /> <br />目录:  <br />DirectSound设备    枚举可以使用的声音设备    <br />创造DirectSound对象    设置合作级    检索硬件信息    扬声器的设置    压缩  DirectSound缓冲    静态缓冲和流缓冲    创建辅助缓冲    缓冲控制选项    主缓冲的存取    播放声音    重放(PLAYBACK)的控制    播放进度和可以被写的位置(Current Play and Write P

naonaodog的专栏 1182
上一篇: DirectSound开发
下一篇: 如何给 Visual C++ 中的对话框增加位图背景
普通网友
博客等级 码龄22年 1万+粉丝 3156原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址