title
Products            Buy            Support Forum            Professional            About            Codec Central
 
Results 1 to 7 of 7

Thread: The Lengthof a WAV file

  1. #1
    Unregistered

    Question The Lengthof a WAV file

    I work at San Francisco's PBS station, where we use many "broadcast wav" files. Fool that I am I volunteered to write a VB program that would rename them, using as part of that name their length. Both work and home use W2K.

    I have not found aor been able to write any code that gives me accurate length. dbPowerAmp's scripting abilities is my latest attempt. I put AOL's "You've Got Mail" file on my desktop, and then copied the following from the developer page and put put it also on my desktop:

    "
    Set Multiplayer = CreateObject("dBpowerAMP.Multiplayer") ' Access Multiplayer Object

    Multiplayer.FilePlaying = "gotmail.wav"

    le = Multiplayer.Length
    msgbox (le)
    "

    It gave me a length of zero. Then I noticed that when I dropped the gotmail.wav" file into the MUltiplayer with drag and drop directly, it played but there was no length shown.

    The same happened when I tried this code for VB's MMControl.ocx:

    "
    Public Function GetLength(fn As String) As Integer
    'microsoft multimedia control (provided with vb )
    Dim howlong As Integer

    Form1.MMControl1.FileName = fn
    Form1.MMControl1.DeviceType = "Waveaudio"

    Form1.MMControl1.TimeFormat = mciFormatMilliseconds
    Form1.MMControl1.Command = "open"
    howlong = Form1.MMControl1.Length
    Form1.MMControl1.Command = "close"

    End Function
    "

    Could someone tell me just how I screwing up?

    Thanks!

  2. #2
    Administrator
    Join Date
    Apr 2002
    Posts
    39,934

    Re: The Lengthof a WAV file

    Your best bet - load all the Waves into My Music Collection, then Collection >> Export

    depending upon how the files are named, just export Track Title, and Length. Then use some code to rename from there.

  3. #3
    TrinitySoftware
    Join Date
    Apr 2002
    Location
    Huizen, Holland
    Posts
    153

    Re: The Lengthof a WAV file

    Hi,

    It's a bit more complex, but I would read the BWF header from the file and
    calculate the length in mins and secs based on the data length, sample rate,
    (bitrate for MPEG) and bit depth values.

    The bonus is that the program will be completely 'stand-alone'.

    If you're interested I can dig-up the formula for you...

    Best regards,
    Daren.

  4. #4
    Unregistered

    Smile Re: The Lengthof a WAV file

    Quote Originally Posted by daren
    Hi,

    It's a bit more complex, but I would read the BWF header from the file and
    calculate the length in mins and secs based on the data length, sample rate,
    (bitrate for MPEG) and bit depth values.

    The bonus is that the program will be completely 'stand-alone'.

    If you're interested I can dig-up the formula for you...

    Best regards,
    Daren.
    I would appreciate that a lot! I have a .pdf file with the broadcast wave specification, which I could forward to you if you send me your email. Mine is birrell@well.com.

    A stand-alone program is exactly what we need to get out of this project.

    And thanks!

    Birrell Walsh
    San Francisco

  5. #5
    TrinitySoftware
    Join Date
    Apr 2002
    Location
    Huizen, Holland
    Posts
    153

    Re: The Lengthof a WAV file

    Hi Birrell,

    Thanks for the offer, but I already have the BWF specs docs.

    You will need to parse the file for the 'fmt' chunk and read the data which
    follows into the following data structure:

    // "fmt" chunk
    short wFormatTag; //audio data type
    short nChannels; //mono or stereo
    long nSamplesPerSec; //sample freq
    long nAvgBytesPerSec; //bit rate/8 (not always used)
    short nBlockAlign; //frame size
    short wBitsPerSample; //Bit depth (only for linear files)
    short cbSize; //22 - size of extra info
    short fwHeadLayer;
    long dwHeadBitRate; //bit rate
    short fwHeadMode;
    short fwHeadModeExt;
    short wHeadEmphasis;
    short fwHeadFlags;
    long dwPTSLow;
    long dwPTSHigh;

    I couldn't find the formula (lost it somewhere), but this should work for linear
    files:

    length in secs=(datalength*8)/(SamplesPerSec*nChannels*wBitsPerSample)

    For MPEG files you will have to use a multiplication factor based on the bitrate:
    factor=1536/bitrate in kbps.

    The "datalength" is the total filelength - size of the header, or the amount
    of bytes given at the start of the "data" chunk.

    The parsing is necessary due to the fact that the chunks can be in any
    order in the file (or some chunks could be missing).

    Sorry the above isn't in VB. You'll have to work that bit out ;-)

    I find the best way to experiment is to examine sample files with a HEX editor
    (with character representation of the values, for identifying the chunk tags).

    Hope this helps,
    Daren.

  6. #6

    Join Date
    Dec 2003
    Posts
    1

    Re: The Lengthof a WAV file

    Hi. I'm not really familiar when it comes to working with file objects. How do i actually get the values of the datalength, SamplesPerSec, nChannels, wBitsPerSample?

    By the way, Im using VB .NET.

    Thanks so much. Hope you guys could help.

  7. #7
    TrinitySoftware
    Join Date
    Apr 2002
    Location
    Huizen, Holland
    Posts
    153

    Re: The Lengthof a WAV file

    Quote Originally Posted by edgar23
    Hi. I'm not really familiar when it comes to working with file objects. How do i actually get the values of the datalength, SamplesPerSec, nChannels, wBitsPerSample?

    By the way, Im using VB .NET.

    Thanks so much. Hope you guys could help.
    Hi Edgar,

    Have a look here:

    http://www.jwcs.net/developers/code/...al.Audio&aid=1

    Best regards,
    Daren.

Posting Permissions

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