Plotting a Wav file

Started by Mikey, October 27, 2018, 01:01:59

Previous topic - Next topic

Mikey

It this code I'm trying to plot a .wav file.

GWID=1024:GHEI=600
Graphics GWID,GHEI,16,2:FN1$="W:XSR.MP3"
AF1=OpenFile(FN1$)
FSZ=FileSize("W:XSR.MP3"):HRW=FSZ/((FSZ/GWID)+1):;HALT
While Not Eof(AF1)
ABY=ReadByte(AF1):Plot D,(GHEI/2)+ABY;:D=D+1
If XSR>(FSZ/GWID) Then D=D+1:XSR=0
XSR=XSR+1
Wend
HALT


What I get is a solid rectangle if I try to plot the whole file and dots if I plot just a selected few.
Where am I going wrong?

GW

Looks like you're loading an mp3 file, which is not a wav file.
If load a real wave file, you need to parse the header (roughly the first 64 bytes) to determine what kind of wav it is (bitdepth etc) and deal with the rest of the data.

Mikey

Should be  the same algorithm for either.
If someone could point me to a tutorial so that I can write a better algorithm.

Thank

Matty

Where are you going wrong?

Well, what are you trying to achieve?

An mp3 is a compressed format,the byte value you are reading does not equate to any meaningful pattern.

However your description of the output is precisely what I'd expect to see for effectively random byte values in a file several tens or hundreds of kilobytes in length.

Qube

Quote from: Mikey on October 27, 2018, 01:01:59

GWID=1024:GHEI=600
Graphics GWID,GHEI,16,2:FN1$="W:XSR.MP3"
AF1=OpenFile(FN1$)
FSZ=FileSize("W:XSR.MP3"):HRW=FSZ/((FSZ/GWID)+1):;HALT
While Not Eof(AF1)
ABY=ReadByte(AF1):Plot D,(GHEI/2)+ABY;:D=D+1
If XSR>(FSZ/GWID) Then D=D+1:XSR=0
XSR=XSR+1
Wend
HALT

What you are doing there is drawing based on the file byte values. You'll always end in a seemingly random mess. Reading a wav / mp3 in that raw way doesn't result in the structure you want. You'll need to understand the file format and through processing take those values into the drawing. In order to do that in Blitz you'll need to know the file structure of a wav / mp3 file.
Mac Studio M1 Max ( 10 core CPU - 24 core GPU ), 32GB LPDDR5, 512GB SSD,
Beelink SER7 Mini Gaming PC, Ryzen 7 7840HS 8-Core 16-Thread 5.1GHz Processor, 32G DDR5 RAM 1T PCIe 4.0 SSD
MSI MEG 342C 34" QD-OLED Monitor

Until the next time.

TomToad

You could use a .dll that will decompress the mp3 for you, such as fmod or OpenAL. I think there are userlib .decls files floating around somewhere, if not, shouldn't be too difficult to create one. 
------------------------------------------------
8 rabbits equals 1 rabbyte.

Mikey

@TomToad: After searching for what I'm looking for I see that you are right. Others who have been giving tutorials have been leaving out the decompression portion of their source and certain other portions.
The sources I have are useless to me.
Thanks for pointing out the decompression algorithm.

peteswansen

well I had a bit of fun tinkering with his code trying some stuff out... it basically just plots out random dots in columns that progress across the screen...when its done plotting my WAV file its just a rectangle of solid color.......  :)

Mikey

It's in the archive somewhere?

Mikey

Quote from: peteswansen on November 04, 2018, 05:51:27
well I had a bit of fun tinkering with his code trying some stuff out... it basically just plots out random dots in columns that progress across the screen...when its done plotting my WAV file its just a rectangle of solid color.......  :)

Oh, you mean my code.
Well, yes that's it. There is some decoding that needs too be done I was told before the values will display correctly.
Not finding too much info on the subject except for one web site that shows graphing using code the maker declares to be public, but he gives examples of what the library does, posting the examples demonstrating the library but not including, or posting, the source of, or the library compiled itself.

That you have might work if the erroneous header or other information is stripped off.

windman


Try plotting the sine cosine functions in a separate program then come back to this and try plotting your same .wav file.
You should get different results.