How can I Peek data from MP3 using the LoadSound?

Blitz3D Forums/Blitz3D Programming/How can I Peek data from MP3 using the LoadSound?

dman(Posted 2016) [#1]
Hi, I'm trying to use the PEEK Command to get data from a Mp3 file in memory

after LoadSound is used.

Can I use the LoadSound command returned value as the address to PEEK the data ?


_PJ_(Posted 2016) [#2]
I don't think so, since PEEK / POKE need a dedicated litzBank handle referring to a reserved block of memory.

To access the RAM at (ironically) random with Blitz using PEEK , you will need to copy or move the relevant data into a Bank.

I believe the Kernel32.dll RtlMoveMemory() or similar method can facilitate this, but you will also need to ascertain the pointer for the stored address.

___

It is all rather complicated, so I would instead either read the file as is, or, load the data of the file into a bank with ReadBytes and then process it from there.

If you can wait until toorrow I have some old stuff which I was working on to retriieve the TAG data from mp3 files with the potential then to analyse the actual sound itself. It's late now and I am not sure I know where those old files are but I will try and dig them out for you tomorrow.


dman(Posted 2016) [#3]
yes i would be very appreciated for the files.
I was using a DLL file called FastPointers for Blitz3D basic.
Heres the web site http://www.fastlibs.com/

Thanks for the response.


Kryzon(Posted 2016) [#4]
This isn't an expected use case for Blitz3D, so you'll be swimming against the stream.
You should use BlitzMax for this. You can load a MP3 sound file and do what you want with the decoded data (the raw samples). And it supports pointers natively. I can write you a BMax example if it would help.


dman(Posted 2016) [#5]
YES I appreciate it.

Thank You


Kryzon(Posted 2016) [#6]
Okay, with small steps. BlitzMax comes with a WAV (for lossless audio) and OGG (for lossy audio) format support.
It supports OGG instead of MP3 because OGG has a permissive license. MP3 has some licensing requirements: http://www.mp3licensing.com/help/index.html#5 (If your program is non-profit or for personal use then you should be fine.)

There is a way to read and play MP3 files with BlitzMax, you can use a module (a library) for the BASS framework. There is a BlitzMax example here: https://github.com/maxmods/bah.mod/blob/master/bass.mod/examples/example04.bmx
With this module you can use functions TBassSample.GetInfo() and TBassSample.GetData() to access the raw decoded data of an audio file in memory.

And with the built-in OGG module in BlitzMax you can do something like this:
EDIT: corrected some comments.
SuperStrict 

Import brl.ramstream
Import brl.oggloader

Local address:Byte Ptr	= ... 'Pointer to the OGG data in memory.
Local size:Int			= ... 'Size of the OGG data in memory.
Local readable:Int		= True
Local writeable:Int		= False 
Local OGGStream:TStream	= CreateRamStream( address, size, readable, writeable )

Local audioSample:TAudioSample = LoadAudioSample( OGGStream ) 'Create a TAudioSample object from the ram stream of OGG data.

If audioSample <> Null Then 'If everything loaded fine.

	Print audioSample.format
	Print BytesPerSample[ audioSample.format ] 'BytesPerSample is a helper array from 'mod\brl.mod\audiosample.mod\sample.bmx'.
	
	'audioSample.samples 'Pointer to the sample data.

EndIf

End



dman(Posted 2016) [#7]
Thank You Very much for your assistance , I will play with this. I was trying to create a dj music software.

but because the MP3 license, I will use the wav and ogg format.

I will show you the demo when I create it.


_PJ_(Posted 2016) [#8]
...

Just to let you know, Ive not forgotten this... I am still looking for the old files...


dman(Posted 2016) [#9]
ok thanks
I was trying to use the Bass sdk libraries I paid for.


dman(Posted 2016) [#10]
Hey, is there a free sdk I can use to decode MP3 files?


dman(Posted 2016) [#11]
I just remembered, I can use the BlitzMax's dll if it has one.

is that possible ?


Kryzon(Posted 2016) [#12]
MP3 support is not BlitzMax's, it's from a third-party module for BlitzMax. BlitzMax's built-in modules support WAV and OGG.

That BASS module that adds the MP3 support happens to be made by a user called Brucey, and there's a forum area for discussing modules made by him:
http://www.blitzbasic.com/Community/topics.php?forum=124

That BASS module can be found in Brucey's repositories in GitHub, and in the documentation for that module it explains where you can find the runtime library:
https://github.com/maxmods/bah.mod/blob/master/bass.mod/doc/intro.bbdoc