PeekL Seems to give wrong answer?

Just starting out? Need help? Post your questions and find answers here.
collectordave
Addict
Addict
Posts: 1310
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

PeekL Seems to give wrong answer?

Post by collectordave »

Attempting to get a 32 checksum from a buffer

After setting up the buffer I use 'Debug "Checksum = " + Str(PeekL(*SongBuffer + 22))'

The value returned is -1015688195

If I change to 'Debug "Checksum = " + Hex(PeekL(*SongBuffer + 22))'

The value returned is FFFFFFFFC375D3FD

The actual value should be C375D3FD

Other values are returned ok, am I missing something?

You will need an .ogg file to test.


The code I am using is here:-

Code: Select all

Structure Head
  Capture.s
  Version.a
  Type.a
  GranPos.d
  Serial.l
  Sequence.l
  Checksum.l
  PageSegments.a
EndStructure


Global OggHeader.Head

FileToSearch.s = OpenFileRequester("Please choose file to load", "", "All Files (*.*)|*.*", 0)

    If ReadFile(0, FileToSearch)
      length = Lof(0)
      *SongBuffer = AllocateMemory(length)
      If *SongBuffer
        bytes = ReadData(0, *SongBuffer, length)
      EndIf
      CloseFile(0)
    EndIf
  
    
    Debug "Capture Pattern = " + PeekS(*SongBuffer,4,#PB_UTF8)
    Debug "Version = " + Str(PeekA(*SongBuffer + 4))
    Debug "Type = " + Str(PeekA(*SongBuffer + 5))
    Debug "Granule Position = " + Str(PeekD(*SongBuffer + 6))
    Debug "Serial = " + Hex(PeekL(*SongBuffer + 14))
    Debug "Sequence = " + Hex(PeekL(*SongBuffer + 18))
    Debug "Checksum = " + Str(PeekL(*SongBuffer + 22))
    Debug "Number Of Segments = " + Str(PeekA(*SongBuffer + 26))
I know it will be something I am not seeing.

CD
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Re: PeekL Seems to give wrong answer?

Post by nco2k »

Code: Select all

Debug Hex(-1015688195, #PB_Long)
c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
collectordave
Addict
Addict
Posts: 1310
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: PeekL Seems to give wrong answer?

Post by collectordave »

Lovely

Thanks very much

CD
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
User avatar
Mijikai
Addict
Addict
Posts: 1520
Joined: Sun Sep 11, 2016 2:17 pm

Re: PeekL Seems to give wrong answer?

Post by Mijikai »

Besides the code i posted in the other thread: viewtopic.php?p=539643#p539643

Here is a very simple & fast way to get the ogg page offsets.

Code: Select all

EnableExplicit

Global NewList OggOffsets.i()

Procedure.i GetOggOffsets(File.s,List Offset.i())
  Protected handle.i
  Protected *buffer
  Protected buffer_size.i
  Protected *offset.Long
  Protected result.i
  Protected error.i
  If File
    handle = ReadFile(#PB_Any,File.s)
    If IsFile(handle)
      buffer_size = Lof(handle)
      If buffer_size > 4
        *buffer = AllocateMemory(buffer_size)
        If ReadData(handle,*buffer,buffer_size) = buffer_size
          For *offset = *buffer To (*buffer + buffer_size - 5)
            If *offset\l = 1399285583
              If AddElement(Offset())
                Offset() = *offset - *buffer
              Else
                error = #True
                Break
              EndIf
            EndIf
          Next
          result = Bool(error = #False)
        EndIf
        FreeMemory(*buffer)
      EndIf 
      CloseFile(handle)
    EndIf 
  EndIf 
  ProcedureReturn result
EndProcedure

If GetOggOffsets("yuna.ogg",OggOffsets())
  ForEach OggOffsets()
    Debug OggOffsets()
  Next
EndIf  
  
End
collectordave
Addict
Addict
Posts: 1310
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: PeekL Seems to give wrong answer?

Post by collectordave »

Hi Mijikai

Replied on this thread posting.php?mode=reply&f=13&t=73238 as more appropiate.

This is just about my confusion over PeekL()

Hope you do not mind?

Getting close now to writing ogg comments but better on the above thread.

King Regards

CD
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
Post Reply