+ Reply to Thread
Results 1 to 14 of 14

Windows Media Audio (WMA) / ASF Data Structure

  1. #1
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Windows Media Audio (WMA) / ASF Data Structure

    I'm reading a wma file as a 1D array of bytes. I want to know which item in the array is the start of the music data.

    I understand that this can be calculated using the header data but I can't work it out. I've tried reading up on the WMA file structure (e.g. the first 128 bits being the Object ID, the next 64 bits being the Object Size and so on) but despite a lot of time spent on this, I'm still lost.

    Can anyone please end this headache?!
    Last edited by mc84excel; 05-05-2014 at 07:29 PM.
    *******************************************************

    HELP WANTED! (Links to Forum threads)
    Trying to create reusable code for Custom Events at Workbook (not Application) level

    *******************************************************

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Windows Media Audio (WMA) / ASF Data Structure

    Eh, why?

    This sort of encoding is usually proprietary, and to be honest I've no idea why you would want to decipher it.
    If posting code please use code tags, see here.

  3. #3
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Windows Media Audio (WMA) / ASF Data Structure

    Thanks Norie.

    The Data Structure for ASF (which includes WMA) is publicly available. Download the PDF from: http://www.microsoft.com/en-us/downl....aspx?id=14995

    I'm not seeking to decipher the stream data itself. I only want a VBA function which will return where the file property data ends/music data starts (where the argument is the wma file as a byte array)
    Last edited by mc84excel; 04-29-2014 at 08:35 PM.

  4. #4
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Windows Media Audio (WMA) / ASF Data Structure

    The annoying thing is that I know that the header object size can be calculated. But I haven't learnt python so I can't convert the code to VBA (I've tried).

  5. #5
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Windows Media Audio (WMA) / ASF Data Structure

    Quote Originally Posted by Norie View Post
    Eh, why? ... to be honest I've no idea why you would want to decipher it.
    I want to checksum wma files while ignoring any file property information etc.

    If I can determine the start/end of the raw music data, I can run the checksum calculation on that portion of the file only.

    I have this working fine for mp3, I now want it for wma.

  6. #6
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Windows Media Audio (WMA) / ASF Data Structure

    I'll try another approach:

    Is it possible to convert C++ code into VBA?

  7. #7
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Windows Media Audio (WMA) / ASF Data Structure

    To help anyone who is minded to help out on this thread, I am providing code which converts a filename string into an array

    You can test it on the WMA files in the Sample Music folder.

    I need to know which array element marks the start of the raw music data. (IIRC this happens immediately after the end of the file properties data. So if you can return the file header object size from the ASF properties, the thread is solved?)


    Please Login or Register  to view this content.
    Last edited by mc84excel; 06-01-2014 at 07:24 PM.

  8. #8
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Unhappy Re: Windows Media Audio (WMA) / ASF Data Structure

    Hmmm. It looks like I can't solve this by myself.

    There is C++ code which I can probably use part of it to give me what I need. Except. I don't know C++ so I can't convert C++ to VBA. (I've tried but it isn't easy converting from one language to another. Particularly when you don't know the original language!)
    And there are no bilingual (C++ & VBA) programmers on ExcelForum (or if there are - they are in hiding!)

    There are various Python scripts out there (which I found by googling) that I MAY be able to use part of their code to get the variable I'm seeking.
    Except (you guessed it) I don't know Python. So I can't convert Python to VBA (I've tried but etc. - same problem as converting C++ to VBA).

    I don't suppose there are any Python/VBA programmers on ExcelForum? (Although the C++ code looks far more promising)

  9. #9
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: Windows Media Audio (WMA) / ASF Data Structure

    Sorry no-one else has offered help on this yet (bumping it for you)
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  10. #10
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Windows Media Audio (WMA) / ASF Data Structure

    (shg converted this code from VB, thanks shg)
    I disavow that code -- it's terrible.
    Entia non sunt multiplicanda sine necessitate

  11. #11
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Windows Media Audio (WMA) / ASF Data Structure

    Quote Originally Posted by shg View Post
    I disavow that code -- it's terrible.
    I thought it was you who originally ported this VB code to VBA for me. My mistake. Sorry shg, I did not intend to offend you. (I have now removed the credit)

  12. #12
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Windows Media Audio (WMA) / ASF Data Structure

    I'm sure it is easier then what it seems. I just can't make that final connection.

    I quote from page 6 of the ASF Specification pdf (link provided in post #3):

    3.1 Header Object (mandatory, one only)

    The Header Object is a container that holds any combination of the standard objects listed in the
    following sections. A File Properties Object, a Header Extension Object and at least one
    Stream Properties Object are required to be present. Implementations shall ignore any objects
    that they do not understand.

    The Header Object is represented using the following structure.

    Field name Field type Size (bits)
    Object ID GUID 128
    Object Size QWORD 64
    Number of Header Objects DWORD 32
    Reserved1 BYTE 8
    Reserved2 BYTE 8

    The fields are defined as follows:

    Object ID
    Specifies the GUID for the Header Object. This field shall be set to ASF_Header_Object.

    Object Size
    Specifies the size of the Header Object. This includes the sum of 24 bytes plus the size of the objects contained in
    the Header Object. Valid values are at least 30 bytes.



    OK so I open the WMA file in a Hex Editor (or import the file into VBA as an array of bytes). Now I try to follow the above.

    The first field name according to the PDF is "Object ID". It has a size of 128 bits. 128 bits = 16 bytes. So I can ignore the first 16 elements in the array as they are useless for my goal.

    The second field name is "Object Size". I am not 100% certain (so correct me if you know) but I'm guessing that obtaining this value is the start towards returning the value I need.

    The Object Size field has a size of 64 bits. 64 bits = 8 bytes. So this means the byte values (000010 to 000017 in Hex Editing, elements 16 to 24 in byte array (base 0)).

    I'm testing this on a file and it gives me the following values:

    A6 14 00 00 00 00 00 00

    Now what? How do these bytes give me the size of the Header Object?
    Last edited by mc84excel; 06-04-2014 at 11:39 PM.

  13. #13
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Windows Media Audio (WMA) / ASF Data Structure

    Ha Ha Ha Ha Ha. I've cracked it!

    From the previous post, I have the following hex values from a test file:

    A6 14 00 00 00 00 00 00

    If I read these in REVERSE ORDER, I get: 00 00 00 00 00 00 14 A6

    And 14A6 appears to be the start of the music stream when hex editing this file!


    Now all I need is a VBA Function that takes an argument of a variant array and returns the start of the music stream as a long value.


    So. It would need to read the 16th to 24th elements (assuming base 0) of the array, reverse the order of these elements and then convert this to string and from string to long (converting from Hex to Dec)

  14. #14
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Windows Media Audio (WMA) / ASF Data Structure

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] activex windows media player
    By zaky in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-29-2013, 02:00 AM
  2. [SOLVED] Windows Media Player
    By zaky in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-28-2013, 03:38 PM
  3. Media Player versus Windows Media Player
    By teepee in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-15-2005, 02:05 PM
  4. Media Player versus Windows Media Player
    By teepee in forum Excel General
    Replies: 1
    Last Post: 10-13-2005, 10:05 PM
  5. Media Player versus Windows Media Player
    By teepee in forum Excel General
    Replies: 1
    Last Post: 10-13-2005, 10:05 PM

Tags for this Thread

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1