Author Topic: question regarding mp3 playback  (Read 4450 times)

0 Members and 1 Guest are viewing this topic.

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
question regarding mp3 playback
« on: May 16, 2007 »
right here goes i want to be able to convert an mp3 to a bin file and link them into the exe and have them played back from memory like ufmod i know this will make the exe huge but that will be fine for me and im just wondering what lib would be best for this i dont want any dlls?

and also how would i go about building the lib for freebasic.

cheers.
« Last Edit: May 16, 2007 by ninogenio »
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: question regarding mp3 playback
« Reply #1 on: May 16, 2007 »
There are loads of programs to convert binary files to source code so you can compile them in, in fact, there's code in my Melon CDI demo source for doing it.
Then you need to make your mp3 into a wav (just encapsulate it in a wav format, not actually convert it)
http://www.studiodust.com/riffmp3.html claims to be able to do that.
Then
sndPlaySound(pointer_to_sound, SND_MEMORY)
You will need to add winmm.lib to the project, I think that means including mmsystem.bi.

That might work.

Jim
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: question regarding mp3 playback
« Reply #2 on: May 16, 2007 »
thanks jim im going to try it and as ever ill report back an how its went.

cheers
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: question regarding mp3 playback
« Reply #3 on: May 16, 2007 »
k+ for that jim cheers it works!

the only problem i have is that it only play the first quarter of my song the mp3 is 4.9meg before being turned into a raw file and 25 meg after.

i thought the problem might have came from the riff converter limiting the size of the header but i used the switch -l 0 to turn of size limiting and it still has the probleml.

it also take an age to compile is there any way of speeding it up by mabey turning the raw music file into a .o file and linking it in or something?
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: question regarding mp3 playback
« Reply #4 on: May 16, 2007 »
Maybe you need to find a different utility to add the header?

You can pre-compile the file by moving the data into a file called mp3.bas

fbc -c mp3.bas

The when you build the main program do

fbc main.bas -a mp3.o

You might need to make a small change to main.bas so it can see the name of the data in mp3.o.
I think that would be something like (not sure about this)

extern import mp3_array_data_name as byte (sizeofdata)

Jim
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: question regarding mp3 playback
« Reply #5 on: May 16, 2007 »
right no problem jim i was thinking that maybe the sndplaysound function was limited to 1meg or something.

one more thing when the audio is playing - the program doesnt move on to the main loop till sndplaysound is done how might i fix this i was thinking of multithreading and having one thread deal with the playsoundand and one for the main loop?
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: question regarding mp3 playback
« Reply #6 on: May 16, 2007 »
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/htm/_win32_sndplaysound.asp

You could add SND_ASYNC to the flags to make it play in the background.

Jim
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: question regarding mp3 playback
« Reply #7 on: May 17, 2007 »
it was my fault the music wasnt fully playing i had forgot to turn the file into a raw again after setting the size in the header info to unlimited so the song plays fully now.

i also got the object stuff going and it compiles really fast now btw the extern part goes like this after a lot of trail and error

extern music(0 to 5042383) Alias "music" as ubyte

that line also has to be in the music.bas file at the top before turning the file into an object.

the syncing part also went fine so now i have a fully working mp3 player in about 100k before crunching.

sndPlaySound( @music(0) , SND_MEMORY or SND_ASYNC )

ill bash a *small* example up for the forum.

again cheers jim!

edit - just tested it and the player without music attached is only 11.5k and crunched 6.5k so its a far better solution for just playing mp3`s than most others
« Last Edit: May 17, 2007 by ninogenio »
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: question regarding mp3 playback
« Reply #8 on: May 17, 2007 »
Excellent to see it all works when you put it together :)  You're right, it's an extremely efficient way to play mp3s from RAM, especially as it just uses one Windows API call.

Jim
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: question regarding mp3 playback
« Reply #9 on: May 17, 2007 »
here is the source.
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: question regarding mp3 playback
« Reply #10 on: May 17, 2007 »
and here is the exe.
Challenge Trophies Won: