int DSound_Load_WAV(char *filename, int control_flags)
{
// this function loads a .wav file, sets up the directsound
// buffer and loads the data into memory, the function returns
// the id number of the sound
HMMIO hwav; // handle to wave file
MMCKINFO parent, // parent chunk
child; // child chunk
WAVEFORMATEX wfmtx; // wave format structure
int sound_id = -1, // id of sound to be loaded
index; // looping variable
UCHAR *snd_buffer, // temporary sound buffer to hold voc data
*audio_ptr_1=NULL, // data ptr to first write buffer
*audio_ptr_2=NULL; // data ptr to second write buffer
DWORD audio_length_1=0, // length of first write buffer
audio_length_2=0; // length of second write buffer
// step one: are there any open id's ?
for (index=0; index < MAX_SOUNDS; index++)
{
// make sure this sound is unused
if (sound_fx[index].state==SOUND_NULL)
{
sound_id = index;
break;
} // end if
} // end for index
// did we get a free id?
if (sound_id==-1)
return(-1);
// set up chunk info structure
parent.ckid = (FOURCC)0;
parent.cksize = 0;
parent.fccType = (FOURCC)0;
parent.dwDataOffset = 0;
parent.dwFlags = 0;
// copy data
child = parent;
// open the WAV file
if ((hwav = mmioOpen(filename, NULL, MMIO_READ | MMIO_ALLOCBUF))==NULL)
return(-1);
// descend into the RIFF
parent.fccType = mmioFOURCC('W', 'A', 'V', 'E');
if (mmioDescend(hwav, &parent, NULL, MMIO_FINDRIFF))
{
// close the file
mmioClose(hwav, 0);
// return error, no wave section
return(-1);
} // end if
// descend to the WAVEfmt
child.ckid = mmioFOURCC('f', 'm', 't', ' ');
if (mmioDescend(hwav, &child, &parent, 0))
{
// close the file
mmioClose(hwav, 0);
// return error, no format section
return(-1);
} // end if
// now read the wave format information from file
if (mmioRead(hwav, (char *)&wfmtx, sizeof(wfmtx)) != sizeof(wfmtx))
{
// close file
mmioClose(hwav, 0);
// return error, no wave format data
return(-1);
} // end if
// make sure that the data format is PCM
if (wfmtx.wFormatTag != WAVE_FORMAT_PCM)
{
// close the file
mmioClose(hwav, 0);
// return error, not the right data format
return(-1);
} // end if
// now ascend up one level, so we can access data chunk
if (mmioAscend(hwav, &child, 0))
{
// close file
mmioClose(hwav, 0);
// return error, couldn't ascend
return(-1);
} // end if
// descend to the data chunk
child.ckid = mmioFOURCC('d', 'a', 't', 'a');
if (mmioDescend(hwav, &child, &parent, MMIO_FINDCHUNK))
{
// close file
mmioClose(hwav, 0);
// return error, no data
return(-1);
} // end if
// finally!!!! now all we have to do is read the data in and
// set up the directsound buffer
// allocate the memory to load sound data
snd_buffer = (UCHAR *)malloc(child.cksize);
// read the wave data
mmioRead(hwav, (char *)snd_buffer, child.cksize);
// close the file
mmioClose(hwav, 0);
// set rate and size in data structure
sound_fx[sound_id].rate = wfmtx.nSamplesPerSec;
sound_fx[sound_id].size = child.cksize;
sound_fx[sound_id].state = SOUND_LOADED;
// set up the format data structure
memset(&pcmwf, 0, sizeof(WAVEFORMATEX));
pcmwf.wFormatTag = WAVE_FORMAT_PCM; // pulse code modulation
pcmwf.nChannels = 1; // mono
pcmwf.nSamplesPerSec = 11025; // always this rate
pcmwf.nBlockAlign = 1;
pcmwf.nAvgBytesPerSec = pcmwf.nSamplesPerSec * pcmwf.nBlockAlign;
pcmwf.wBitsPerSample = 8;
pcmwf.cbSize = 0;
// prepare to create sounds buffer
dsbd.dwSize = sizeof(DSBUFFERDESC);
dsbd.dwFlags = control_flags | DSBCAPS_STATIC | DSBCAPS_LOCSOFTWARE;
dsbd.dwBufferBytes = child.cksize;
dsbd.lpwfxFormat = &pcmwf;
// create the sound buffer
if (FAILED(lpds->CreateSoundBuffer(&dsbd,&sound_fx[sound_id].dsbuffer,NULL)))
{
// release memory
free(snd_buffer);
// return error
return(-1);
} // end if
// copy data into sound buffer
if (FAILED(sound_fx[sound_id].dsbuffer->Lock(0,
child.cksize,
(void **) &audio_ptr_1,
&audio_length_1,
(void **)&audio_ptr_2,
&audio_length_2,
DSBLOCK_FROMWRITECURSOR)))
return(0);
// copy first section of circular buffer
memcpy(audio_ptr_1, snd_buffer, audio_length_1);
// copy last section of circular buffer
memcpy(audio_ptr_2, (snd_buffer+audio_length_1),audio_length_2);
// unlock the buffer
if (FAILED(sound_fx[sound_id].dsbuffer->Unlock(audio_ptr_1,
audio_length_1,
audio_ptr_2,
audio_length_2)))
return(0);
// release the temp buffer
free(snd_buffer);
// return id
return(sound_id);
} // end DSound_Load_WAV
相关推荐
DirectSound播放器实战:VC++实现WAV播放、暂停与音量控制
Windows音频编程是许多桌面软件开发中绕不开的话题,从早期的MCI到WaveOut,再到DirectSound与现代WASAPI,每一代接口都承载着不同的应用需求。DirectSound作为DirectX家族中的经典音频组件,以缓冲区混音机制为核心,底层原理清晰透明,是理解Windows音频播放链路的有效途径。在实际工程中,无论是工业控制上位机还是传统MFC应用,利用DirectSound播放WAV文件、实现暂停恢复、音量调节与进度获取,都是极具价值的技术方案。音频缓冲区管理、RIFF文件解析、设备协作
wavenet_vocoder(预处理MFCC特征提取代码段分析)
从加载进来音频开始看起,前面制作路径列表就不在细述了 wav = audio.load_wav(wav_path) if hparams.rescaling: wav = wav / np.abs(wav).max() * hparams.rescaling_max 首先遇到hparams.rescaling_max=0.99,即wav / wav内元素绝对值中的最大值,将使得所有元素范围在(-1,1),相当于做个归一化。 mel_spectrogram = audio.melsp.
wav头文件读取工具
windows的exe程序,读取标准wav文件的44字节头信息,并将该头信息显示出来。注:所要读取的wav文件需要跟exe文件放在同一目录下,且名字为1.wav
[python] windows下使用librosa.load 加载wav文件报错: RuntimeWarning: Couldn't find ffmpeg or avconv
环境: 操作系统:windows10 librosa:0.5.1 完整报错信息: RuntimeWarning: Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work warn("Couldn't find ffmpeg or avconv - defaulting to ffmpeg, b...
波形文件(.wav)读写操作
对wav文件控制函数的说明(常用mmio函数: mmioOpen( ) 打开一个RIFF文件 mmioDescend ( ) 进入块 mmioRead( ); 该取RIFF文件 mmioAscend ( ); 跳出块 mmioClose( ); 关闭PIFF文件 对于块来说,进入块和跳出块是配对的。 读取WAV文件的读取过程: mmioOpen( ) 打开文件 ↓ mmioDescend ("WAVE") 进入"fmt"块 ↓ mmioRead( ) 读取WAVE文件格式信息 ↓ mmioAscend ( ) 跳出"fmt"块 ↓ mmioDescend ("data") 进入"data"块 ↓ mmioRead( ) 读取WAVE数据信息 ↓ mmioClose( ) 关闭文件。 输出WAV文件的过程: WaveOutOpen () 打开一个输出设备 ↓ WaveOutPrepareHeader() 准备WAVE数据头。 ↓ WaveOutWrite() 将数据写入设备并开始播放 ↓ WaveOutReset() 停止播放并重置管理器 ↓ WaveOutClose() 并闭播放设备 ↓ WaveOutUnpareHeader() 清理用WaveOutPrepareHeader准备的Wave
WAV文件的读写接口类,依赖标准C++库
使用标准C++库实现实现PCM格式的WAV文件的读写。 class CWaveFile { public: CWaveFile(void); ~CWaveFile(void); // Write wav head bool static WriteHead(const string& filename, uint32_t length); // Write wav file bool static write(const string& filename, const Wave_header &header, void *data, uint32_t length); // Read wav file bool read(const string &filename); private: // Read wav file header bool read_header(const string &filename); private: shared_ptr header; unique_ptr data; };
语音识别 Deep Speech Recognition 小模型代码初探
最近开始学习语音识别 (Speech Recognition) 相关 发现了一个结构挺清晰的中文识别小模型 原项目有一些 bug 在此记录下 项目地址 https://github.com/yang123qwe/end2end_chinese_speech_recognition 问题一 module 'torchaudio' has no attribute 'load_wav' pytorchaudio 模块版本问题 直接将函数 load_wav 改成 load() 即可 问题二 No au.
2023年LitCTF web组wp
1、导弹迷踪2、1zjs3、php是世界上最好的语言!!4、Ping5、我Flag呢?7、作业管理系统8、Vim yyds10、这是什么?SQL!注一下!11、Flag点击就送!12、就当无事发生13、彩蛋。
SDL2.0例子代码分析---循环播放wav loopwav
SDL2.0中循环播放一段声音文件 ,并且添加上注释。 /* 加载并且循环播放一个WAV文件*/ /* loopwaves.c is much more robust in handling WAVE files -- This is only for simple WAVEs */ #include "SDL_config.h" #include #include #if HA
基于STM32与HRTIM的四开关Buck-Boost双向DC-DC电源设计实战(附源码、仿真与设计解析)
本文详细介绍了基于STM32F334的HRTIM高分辨率定时器实现四开关Buck-Boost双向DC-DC电源的设计实战。通过精准的PWM控制、双环PID算法和智能模式切换逻辑,解决了电压震荡与效率优化等关键问题,并提供了完整的源码、PSIM仿真及参数计算,为高性能电源设计提供了实用参考。
YOLO系列训练时出现loss出现nan值或者测试时P\R\map全部为0值的解决办法(GTX16xx系列显卡大坑)
YOLO系列训练时出现loss出现nan值或者测试时P\R\map全部为0值的解决办法(GTX16xx系列显卡大坑)
Combine Schedulers源码分析:UnimplementedScheduler如何防止测试漏洞
Combine Schedulers是一个为Swift Combine框架提供增强调度器功能的开源库,其中UnimplementedScheduler组件通过在测试中主动暴露未预期的调度行为,帮助开发者有效防止潜在的测试漏洞。本文将深入解析UnimplementedScheduler的工作原理及其在测试安全中的关键作用。 ## 什么是UnimplementedScheduler? Unimpl
别再手动算重量了!用C++给UG/NX写个自动计算零件质量与质心的插件(附完整源码)
本文详细介绍了如何使用C++为UG/NX开发智能质量分析插件,实现零件质量与质心的自动计算。通过结合NXOpen和UF_MODL API,设计高效的数据结构和批量处理机制,大幅提升机械设计效率。文章包含完整源码和实用技巧,帮助工程师告别手动计算,适用于复杂装配体的自动化工程计算。
(一)DirectSound接口播放WAVE音频文件
首先要声明三个接口,用于声音的播放 LPDIRECTSOUND8 g_pDirectSound=NULL; //directSound接口 LPDIRECTSOUNDBUFFER g_pPrimaryBuffer =NULL;//主缓冲区接口 LPDIRECTSOUNDBUFFER8 g_pSecondaryBuffer = NULL;//辅助缓冲区接口
PyTorch实战:用FGSM攻击MNIST分类器(附可视化对比)
本文通过PyTorch实战演示了如何使用FGSM对抗攻击方法攻击MNIST手写数字分类器。文章详细解析了FGSM攻击原理,提供了从环境搭建、模型准备到攻击实施、可视化对比的完整代码实战流程,并探讨了对抗样本的生成与模型鲁棒性评估。
服务器安装Ubuntu 18.04.2 LTS超详细步骤(小白图文详解)
服务器安装Ubuntu 18.04.2 LTS超详细步骤(小白图文详解) 本文不包括启动盘制作步骤,相关内容可自行百度 华为服务器 1 插入u盘,关机重启 2 初始化界面后进入到系统的BIOS设置界面 (华为服务器按Del键,不同品牌方法不同) 3 进入的时候,华为的服务器默认设置了BIOS密码,因此需要输入之前预设的密码。 注意密码大小写问题,若密码输错三次,则需重启 4 密码输入以后,进入...
WAV格式百度语音测试文件
WAV格式百度语音测试文件 去发现同类优质开源项目:https://gitcode.com/ 文件简介 此仓库提供的资源文件是WAV格式的音频文件,专为百度语音识别功能测试而设计。该文件同样适用于其他相关功能的测试,具有广泛的可用性。 使用说明 本文件为纯净的WAV音频格式,可直接用于百度语音测试或其他音频处理功能的测试。 请根据测试需求合理使用该文件,未经许可不得用于商业用途。 注意事项 ...
从时序精度到视觉盛宴:PY32F030驱动WS2812的工程艺术与避坑指南
本文深入探讨了基于PY32F030微控制器驱动WS2812智能LED的完整解决方案。通过精确的时序控制、硬件PWM结合DMA传输技术,实现了稳定可靠的驱动效果,并提供了电源管理、信号完整性和常见问题排查等实用避坑指南,帮助开发者轻松应对严格的纳秒级时序挑战。
Java Swing如何播放音效和音乐
Java Swing播放音效和音乐的方法
YOLO系列算法改进 | 自研篇 | C3k2融合Circulant Attention注意力模块 | 给局部特征提取器装上了全局动态卷积核,兼顾效率、精度与泛化能力!| AAAI 2026
YOLO系列算法改进 | 自研篇 | C3k2融合Circulant Attention注意力模块 | 给局部特征提取器装上了全局动态卷积核,兼顾效率、精度与泛化能力!| AAAI 2026 (以YOLO26最新目标检测模型为基础,融合C3k2_Circulant创新模块改进Backbone)
计算机控制技术及应用
《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。
JMF应用篇 之 创建音频播放器
浏览在本节中,我们将进行创建一个简单的音频播放器的第一个练习。本例将介绍Manager类和Player接口,中两个都是建立大多数基于JMF应用的重要部分。本例的功能目标是在字符界面下播放本地的音频文件。我们将学习此源代码,并了解每一行所做的任务。完成本节后,你将会有一个基于JMF的可播放包括MP3, WAV, AU等多种音频文件的演示程序。在本练习后的源代码分类种可查询文件SimpleAudio
Data-Structures-and-Algorithm-Analysis-in-Java.pdf
作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...
matlab 各种文件的读取(及读写问题的解决)
0. 文本文件 load('**.mat') load('**.mat', '-ascii') load('-mat', filename) load('-ascii', filename) 1. 音频 wav 文件等:audioread() 2. 视频 常用接口 vision.VideoFileReader(‘…’) 接收视频文件的...
STM32F407中文手册
STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。
蓝牙模块HM-10手册
蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。
音频文件结构解析:从WAV到MP3
音频文件主要由文件头和音频数据两部分构成。常见格式如WAV包含明确的RIFF头、格式块和PCM数据块;OGG采用分页结构存储压缩音频;MP3由帧序列组成。解析音频需先读取文件头获取采样率、声道等元信息,再通过解码器(如libvorbis)将压缩数据转为PCM格式。WAV可直接读取二进制结构,而压缩格式需专用解码库。解码后的PCM数据可存储为整型/浮点数组或流式缓冲区,用于播放、分析或后期处理。不同格式的头部结构差异显著,处理时需针对性解析。
.m4a音频文件转.wav格式
将.m4a音频文件转.wav格式,话不多说,直接上代码!!! from pydub import AudioSegment import wave import pylab as pl import numpy as np #加载语音文件 song = AudioSegment.from_file('F:\\python\\wstdata\\wait\\20220331_192944.m4a')#路径可以使用绝对路径也可以使用相对路径 song.export('changed.wav','wav')#*
VC实现播放wav音频文件
根据前面几篇关于语音操作文章,实现播放wav音频文件: a.>加载wav文件;b.>读取wav文件信息;c.>获得wav数据块;d.>打开音频设备;e.>装载读取的数据;f.>发送到音频设备上播放数据;g.>关闭设备释放内存. /*********************************************************...
232



被折叠的 条评论
为什么被折叠?



