Page 4 of 4 FirstFirst ... 234
Results 31 to 36 of 36

Thread: Byte-by-byte allocated data manipulation

  1. #31

    Byte-by-byte allocated data manipulation

    Do you need this block?
    [pascal]if (j < Samples[i].SampleLength div 2 - 1) then[/pascal]
    It isn't needed in my opinion and actually should make buffers reading samples partially overlapped.

    Other than that, what happens before the big loop? It's also important to know how pointers are tied to or which are direct parameters.

  2. #32
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    Byte-by-byte allocated data manipulation

    I just realized that you were indicating the conditional for weither or not we are at the end of our segment of data. Imagine if I tried to increment the address one more time... I'd get an error for trying to access memory that was not allocated. So... all it does is restrict the pointer from incrementing on it's last iteration through the data.

    As for what I've done with this data before...

    [pascal] {Sample Data}
    for j := NumberOfSamples - XmInstrument.NumOfSamples to NumberOfSamples - 1 do
    begin
    GetMem(Samples[j].SampleData, Samples[j].SampleLength);

    BlockRead(FileStream, Samples[j].SampleData^, Samples[j].SampleLength);
    end;[/pascal]

    This is the block of code that allocates the memory for each music sample/instrument and copies it. Samples[j].SampleLength is the length in bytes of the sample. Samples[j].SampleData is the Pointer that I use to address the data.

    You may ask why the for loop is so odd looking. It has to do with the FastTracker2/XM format and how it's stored. [size=9px](Oh how I'm missing the ease and simplicity of S3M. :?)[/size]

    If this really gives you guys no clue I can post the entire project up for download and trials on your own systems. It'll be all a part of an opensource api down the road anyhow.
    Jason McMillen
    Pascal Game Development
    Co-Founder





  3. #33

    Byte-by-byte allocated data manipulation

    Oh my mistake, didn't notice these:

    AudioBuffer_16bit_Signed := @Samples[i].SampleData;
    AudioBuffer_16bit_Unsigned := @Samples[i].SampleData;

    So ignore my comment about overlapping, but instead noticed a new thing.

    So Samples[i].SampleData is pointer already. In that case @Samples[i].SampleData means pointer to pointer... Try instead
    [pascal]AudioBuffer_16bit_Signed := Samples[i].SampleData;
    AudioBuffer_16bit_Unsigned := Samples[i].SampleData;

    or

    AudioBuffer_16bit_Signed := @Samples[i].SampleData^;
    AudioBuffer_16bit_Unsigned := @Samples[i].SampleData^;[/pascal]

  4. #34
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    Byte-by-byte allocated data manipulation

    Whoa... that totally threw me off kilter... The memory error went away. :lol:

    So if thats how you properly assign a pointer to another pointer, what was I actually doing

    [size=9px]It's obviously either been way too long since I studied pointers and pointer operations OR I'm just not too familiar with how FPC does it.[/size]
    Jason McMillen
    Pascal Game Development
    Co-Founder





  5. #35

    Byte-by-byte allocated data manipulation

    You assigned address of the pointer variable, not the pointer itself. The reason you got SIGSEGV not immediately but only after some loops is that AudioBuffer16_ variables pointed to some place on the stack and it kept working until it reached end of the allocated stack space.

  6. #36
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    Byte-by-byte allocated data manipulation

    Well that makes perfect sense then...

    Well I'm past this problem and back to the decoding issue again.

    Big THANKS guys! :thumbup:
    Jason McMillen
    Pascal Game Development
    Co-Founder





Page 4 of 4 FirstFirst ... 234

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •