December 04, 2020, 02:00:04 PM

Author Topic: Plotting a Wav file  (Read 1733 times)

Offline Mikey

  • Jr. Member
  • **
  • Posts: 63
Plotting a Wav file
« on: October 27, 2018, 01:01:59 AM »
It this code I'm trying to plot a .wav file.
Code: [Select]
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?

Offline GW

  • Full Member
  • ***
  • Posts: 202
Re: Plotting a Wav file
« Reply #1 on: October 27, 2018, 03:22:19 AM »
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.

Offline Mikey

  • Jr. Member
  • **
  • Posts: 63
Plotting a Wav file
« Reply #2 on: October 27, 2018, 10:22:58 PM »
Should be  the same algorithm for either.
If someone could point me to a tutorial so that I can write a better algorithm.

Thank

Offline Matty

  • Hero Member
  • *****
  • Posts: 1258
    • MattiesGames
Re: Plotting a Wav file
« Reply #3 on: October 28, 2018, 03:23:22 AM »
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.

Offline Qube

  • Administrator
  • Hero Member
  • *****
  • Posts: 2567
  • I mostly code at night... Mostly.
    • SyntaxBomb - Indie Coders
Re: Plotting a Wav file
« Reply #4 on: October 28, 2018, 06:16:35 AM »
Code: [Select]
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 mini ( 2018 / 2020 ), 3 GHz 6-Core Intel Core i5, 16 GB 2667 MHz DDR4, 1TB NVMe, eGPU Radeon Pro 580 8 GB, LG Ultragear 27GL83A-B 27 Inch
Commodore VIC-20, 1.1Mhz MOS 6502 CPU, 5KB RAM, VIC ( 6560 ) GPU

Until the next time...

Offline TomToad

  • Hero Member
  • *****
  • Posts: 517
Re: Plotting a Wav file
« Reply #5 on: October 28, 2018, 10:19:17 AM »
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.

Offline Mikey

  • Jr. Member
  • **
  • Posts: 63
Plotting a Wav file
« Reply #6 on: November 01, 2018, 08:03:19 PM »
@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.

Offline peteswansen

  • Jr. Member
  • **
  • Posts: 57
Re: Plotting a Wav file
« Reply #7 on: November 04, 2018, 05:51:27 AM »
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.......  :)

Offline Mikey

  • Jr. Member
  • **
  • Posts: 63
Plotting a Wav file
« Reply #8 on: November 04, 2018, 11:23:47 PM »
It's in the archive somewhere?

Offline Mikey

  • Jr. Member
  • **
  • Posts: 63
Re: Plotting a Wav file
« Reply #9 on: November 04, 2018, 11:54:09 PM »
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.
 

Offline windman

  • Jr. Member
  • **
  • Posts: 30
Plotting a Wav file
« Reply #10 on: January 03, 2019, 09:18:58 PM »

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.

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal