WAVE file with cart chunks

Just starting out? Need help? Post your questions and find answers here.
spacewalker
User
User
Posts: 19
Joined: Tue Apr 27, 2010 4:35 pm
Location: Germany

WAVE file with cart chunks

Post by spacewalker »

Hello,

I need a way to read some information form WAVE files that have "cart chunks".

I'm not an expert with WAVE files but it seems that "cart chunks" are kind of an extension
I have found some code in the forum that deals with WAVE files but none of them could read the information I need.

All I have so far is the folling information - I'd need the read to information from CutID[64]

Code: Select all

typedef struct cartchunk_tag
{
     DWORD ckID;
     DWORD ckSize;
     BYTE ckData[ckSize];
}

typedef struct cart_exetension_tag
{
     CHAR Version[4];
     CHAR Title[64];
     CHAR Artist[64];
     CHAR CutID[64];				<--- need this
     CHAR ClilentID[64];
     CHAR Category[64];
     CHAR Classification[64];
     CHAR OutCue[64];
     CHAR StartDate[10];
     CHAR StartTime[8];
     CHAR EndDate[10];
     CHAR EndTime[8];
     CHAR ProducerAppID[64];
     CHAR ProducerAppVersion[64];
     CHAR UserDef[64];
     DWORD dwLevelRefference
     CART_TIMER PostTimer[8];
     CHAR Reserved[276];
     CHAR URL[1024];
     CHAR TagText[];
} CART_EXTENSION;

typedef struct cart_timer_tag
{
     FOURCC dwUsage;
     DWORD dwValue;
}



A demo WAV file be downloaded here:
http://www.cartchunk.org/samples.htm

thank you
infratec
Always Here
Always Here
Posts: 7582
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: WAVE file with cart chunks

Post by infratec »

Hi,

try this:

Code: Select all

EnableExplicit

Structure RIFFStructure
  Riff.a[4]
  Length.l
  Wave.a[4]
EndStructure


Structure chunkStructure
  Signature.a[4]
  Length.l
EndStructure

Structure fmtStructure
  fmt.a[4]
  Length.l
  Format.u
  Channels.u
  SampleRate.l
  BytesPerSecond.l
  BlockAlign.u
  BitsPerSample.u
EndStructure

Structure cartTimerStructure
  dwUsage.l
  dwValue.l
EndStructure

Structure cartStructure
  cart.a[4]
  Length.l
  
  Version.a[4]
  Title.a[64]
  Artist.a[64]
  CutID.a[64];            <--- need this
  ClientID.a[64]
  Category.a[64]
  Classification.a[64]
  OutCue.a[64]
  StartDate.a[10]
  StartTime.a[8]
  EndDate.a[10]
  EndTime.a[8]
  ProducerAppID.a[64]
  ProducerAppVersion.a[64]
  UserDef.a[64]
  dwLevelRefference.l
  PostTimer.cartTimerStructure[8]
  Reserved.a[276]
  URL.a[1024]
  TagText.a[0]
EndStructure


Define.i File, Size, Ptr, Factor, Flag, EMAXPtr
Define Filename$, Chunk$
Define *Buffer
Define *RiffPtr.RIFFStructure
Define *chunkPtr.chunkStructure
Define *fmtPtr.fmtStructure
Define *cartPtr.cartStructure


Filename$ = OpenFileRequester("Choose a file", "", "*.wav|*.wav", 0)
If Filename$
  File = ReadFile(#PB_Any, Filename$)
  If File
    Size = Lof(File)
    *Buffer = AllocateMemory(Size)
    If *Buffer
      If ReadData(File, *Buffer, Size) = Size
        *RiffPtr = *Buffer
        
        If PeekS(@*RiffPtr\Riff, 4, #PB_Ascii) = "RIFF" And *RiffPtr\Length = Size - 8 And PeekS(@*RiffPtr\Wave, 4, #PB_Ascii) = "WAVE"
          Debug "Header Ok"
          
          *chunkPtr = *Buffer + $0C
          
          Repeat
            ; check for data chunk
            
            Chunk$ = PeekS(@*chunkPtr\Signature, 4, #PB_Ascii)
            
            Debug "Chunk: " + Chunk$
            
            Select Chunk$
              Case "fmt "
                *fmtPtr = *chunkPtr
                Debug "Format: " + Str(*fmtPtr\Format)
                Debug "Length: " + Str(*fmtPtr\Length)
                Debug "Channels: " + Str(*fmtPtr\Channels)
                Debug "Samplerate: " + Str(*fmtPtr\SampleRate)
                Debug "BitsPerSample: " + Str(*fmtPtr\BitsPerSample)
                Debug "BlockAlign: " + Str(*fmtPtr\BlockAlign)
              Case "cart"
                *cartPtr = *chunkPtr
                Debug PeekS(@*cartPtr\Title, 64, #PB_Ascii)
                Debug PeekS(@*cartPtr\Artist, 64, #PB_Ascii)
                Debug PeekS(@*cartPtr\CutID, 64, #PB_Ascii)
                Debug PeekS(@*cartPtr\URL, 1024, #PB_Ascii)
                Debug PeekS(@*cartPtr\TagText, *cartPtr\Length - (@*cartPtr\TagText - @*cartPtr\Version), #PB_Ascii)
                
              Case "data"
                
            EndSelect
            
            *chunkPtr + 8 + *chunkPtr\Length
            
          Until *chunkPtr >= *Buffer + *RiffPtr\Length
            
        EndIf
      EndIf
      FreeMemory(*Buffer)
    EndIf
    CloseFile(File)
  EndIf
EndIf
It looks so ugly, because I tried todo it unicode compatibel.

Bernd
spacewalker
User
User
Posts: 19
Joined: Tue Apr 27, 2010 4:35 pm
Location: Germany

Re: WAVE file with cart chunks

Post by spacewalker »

Thank you Bernd- this works great!
Post Reply