Play Audio Files with DirectSound and Display its Spectrum in Real Time - Part 3

An article to show how to play  audio file with  DirectSound and display its spectrum in real time accurately
Is your email address OK? You are signed up for our newsletters but your email address is either unconfirmed, or has not been reconfirmed in a long time. Please  click here to have a confirmation email sent so we can confirm your email address and start sending you newsletters again. Alternatively, you can  update your subscriptions.

Introduction

This article is an improved edition of my article: Play Wave Files with DirectSound and Display its Spectrum in Real Time - Part 2. In this article, I add MP3, WMA, WAV, and OGG Vorbis support, which need Windows Media 9 or higher support, and I do some extra work to reorganize code. Here have two articles were posted on Code Project before this article, they are listed below.

Input

The input stream includes file, CD, microphone and so on. In this article, the input stream is audio file. So, I define CInput as base classes for all input types, and have some pure virtual functions defined in this class. The function GetDataInternal must be implemented by derived class, which reads audio data from audiofile and fills it to a buffer.

In this article, I use WMF (Windows Media Format) decodes WMA format. The main interfaces that were used are IWMSyncReaderINSSBufferIWMHeaderInfo. The IWMSyncReader interface provides the ability to read WMA files using synchronous calls. The INSSBuffer interface is the basic interface of a buffer object. A buffer object is a wrapper around a memory buffer. The methods exposed by this interface are used to manipulate the buffer. The IWMHeaderInfo interface sets and retrieves information in the header section of an ASF file. You can manipulate three types of header information by using the methods of this interface: metadataattributes, markers, and script commands. You can read MSDN for more information.

The libraries like libmadlibogg and libvorbis are all integrated in this application. And I defined four classes for MP3, WMA, WAV and OGG Vorbis files reading, these are CWMInCWaveInCMP3In and CVorbisIn. For more details, please read the code.

The application decodes mp3 files with libmad, it does not depend on WMF (Windows Media Format) anymore, this library is so cool, I like it. :)

Output

This component already implemented in Play Wave Files with DirectSound and Display its Spectrum in Real Time - Part 2 uses DirectSound for output. So, if you have some questions about it, you should read it first. You can also search CodeProject with the keyword DirectSound; you will get many articles about it.

The Expectation

I would always feel that the spectrum displayed in the window is not right, especially when playing some sound files. So, I hope I can get help on that, and thoroughly deal with it.



FROM:  https://www.codeproject.com/Articles/31709/Play-Audio-Files-with-DirectSound-and-Display-its



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值