News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

DirectShow and MP3

Started by uosunsetter, March 22, 2012, 03:22:30 PM

Previous topic - Next topic

uosunsetter

Hello again :)

I've done some searching and found that the using DirectShow is the best and simplest way to play a MP3. I want to achieve this with MASM32.

I have a features list that I want:

-Changing sound volume of the song
-Pause the song
-Knowing when the song is finished to play

and the list below is not certainly necessary but would be nice to have:

-Going forward and backward in song
-2 options of playing song: One with having the whole song in memory then playing from memory and the other one is reading from hdd part by part

I couldn't find anything to get me started in assembly :(

There is a software that uses DirectShow in this purpose called BASS and it says it works with DirectX 3.0 and higher which is quite good :) It also supports everything I mentioned above. But I don't want to use it because it is 100kb iand includes so many things that i will never ever use and my programme should be only one file, ultra tiny and fast also suporting old OS's :)

Thanks in advance! :)

dedndave

Edgar (Donkey) posted a nice little example program a while ago
it doesn't do everything you want, but it should get you started...
http://www.masm32.com/board/index.php?topic=18180.msg154154#msg154154

uosunsetter

I took a look and it is perfect to start thanks!

uosunsetter

I'm trying to understand the codes but cant :(

My MP3 player is going to be a console application. So i skipped the GUI related part and focused simply on playing a MP3.

Play:
cmp D[ready],FALSE
je >>.EXIT
cmp S[pimc],0
je >>.EXIT
CoInvoke(pimc,IMediaControl.Run)
ret
.EXIT
mov eax,-1
ret


What is CoInvoke and the rest of the line? Didn't see anything that initialized IMediaControl. I feel very confused about syntax. Also i saw a C header in the folder and a line in the beginning like "#include DShowExample.h" in the asm file.(?????)
I dont want to boring but am I too newby for writing a MP3 player? I also don't know anything about GoASM. Is it the problem?

dedndave

first, Edgar uses GoAsm, so the syntax may require some modification to work with Masm
second, DirectShow is a COM interface
perhaps not the best place for a newbie to start, but it's do-able   :P
http://msdn.microsoft.com/en-us/library/windows/desktop/dd375454%28v=vs.85%29.aspx

donkey

Hi uosunsetter,

Sorry I didn't see this thread till now (I'm on vacation). The example I posted should get you started in DirectShow, it demonstrates most of the fundamentals, There are a few things for translating to MASM which are a bit touchy. First off the ".H" files are actually goasm header files from my website, the header project which I started makes up the de-facto standard headers for GoAsm and they're named to match the definitions at MSDN, so if the docs say include xxx.h then that is what you include in GoAsm. For the syntax differences between GoAsm and MASM, well I've posted to enough threads where I've explained how to translate between them, if you have a specific problem I'd be more than glad to address it but understand that I program in GoAsm and am not terribly interested in translating code.

CoInvoke is a macro that I wrote for COM (Component Object Model) calls, it automates the process of calling COM interfaces in both x86-32 and x86-64 builds, the macro was designed to be as close to the C++ implementation as GoAsm macros would allow. I am absolutely certain that someone must have written one for MASM, however if you can't find one the macro is defined in the file MACROS.H and you can translate it to MASM quite easily.

If you have any problems post them in this or the DirectShow thread and I will get back to you.

Edgar
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

anunitu

Here is an open source MP3 player,not sure what it is written in,but it might give you some idea for writing your program.

http://coolplayer.sourceforge.net/?download

It has the binary's and source for download.

baltoro

UOSUNSETTER,   
Using DirectShow for playing audio files is the way to go,...although, most programmers do this in C++ (because COM is difficult in assembly). The problem is that DirectShow interfaces exist for each version of DirectX, and you have to check for this, or you can crash your application. And, I think EDGAR's example is excellent,...he's totally fearless when it comes to COM,...and he writes production quality code.  
There is an excellent Open Source Media Player over at SourceForge that includes all the source code and compiled binaries.
It's called Media Player Classic, and, it does just about everything that DirectShow is capable of,...but, it is written in C++.
Here is the main project website on SourceForge: Media Player Classic
This page describes the: Media Player Classic features
To browse the source code releases, look here: Source Code Repository
WARNING !!! It's a HUGE project,...but, it's been around forever and is very popular with programmers.
Baltoro

JD

Quote from: uosunsetter on March 22, 2012, 04:41:41 PM.....................My MP3 player is going to be a console application..........

It's windowed and uses mci but Bill Cravener has a neat little example on his download page.  It's item 23 "How to play MP3 files example zip file".

http://www.quickersoft.com/examples.html

uosunsetter

Firstly, Edgar, thanks for the example and the information. But after some tries I made a decision that I will not be touching COM objects or GoAsm until I gain some experience with basic asm and MASM32. I always used COM objects easly with high level languages so unfortunately I ended up with no information and understanding of COM. I will take my time to learn it.

anunitu, I checked out coolplayer before and it is really very "cool". But I wanted the whole program to be coded in assembly. It is C++ I guess.

baltoro, I'm already a fan of Media Player Classic :) "Huge projects = fail" for me every single time I try to seperate the little function I wanted. I guess I need more time on that too...

JD, I've already seen that example and runned it(now I started to feel like I made a lot of research :P). The thing that made me worry was it is using my codec which comes with K-Lite Codec Pack and I didn't see any control about position, volume etc... Regardless of that I want highest compatiblity possible. It was another reason for DirectShow.

Thanks for all helps anyway :)

donkey

Hi uosunsetter,

COM is not really that bad, though you would think it was a three headed monster from some of the comments in this and other assembly language boards. The basic COM call is pretty much the same as any other call, the only thing that takes time to wrap your head around is really inheritance and exposing other interfaces on an object. For the most part though with a decent set of macros you can build a COM app as easily as any other app. I would suggest however that you stay clear of IDispatch type interfaces and event sinks until you have a better understanding of the mechanisms involved.

For DirectShow, its a very straight forward interface, well at least as far as a Microsoft interface goes, and it should not be too difficult to do everything you wanted.

Edgar
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable