Java M4A atom tagging free space issue

Posted by Brett on Stack Overflow See other posts from Stack Overflow or by Brett
Published on 2010-06-12T20:53:11Z Indexed on 2010/06/12 21:02 UTC
Read the original article Hit count: 271

Filed under:
|
|
|

Hey, I've been trying to be able to read and write iTunes style M4A atoms and while I've successfully done the reading part, I've come to a bit of a halt in regards to the free space atoms. I figured that I should be able edit and shift the padding around to accommodate writing an atom with more data than it originally had. I've been stuck on this for about a day now, and I've been trying to figure out how to determine the closest free space atom with enough size to accommodate the new data. so far I have:

private freeAtom acquireFreeSpaceAtom( long position )
{
    long atomStart = Long.MAX_VALUE;

    freeAtom atom = null;
    for( freeAtom a : freeSpace )
    {
        if( Math.abs( position - atomStart ) > Math.abs( position - a.getAtomStart() ) )
            atomStart = ( atom = a ).getAtomStart();
    }

    return atom;
}

That code only takes into account the closest free space atom and completely disregards the fact that it should be greater than or equal to a certain size, but I can't quite figure out how I should check for both closeness and size efficiently.

© Stack Overflow or respective owner

Related posts about java

Related posts about audio