Advertisement
Guest User

adx_scanner.py

a guest
Jan 2nd, 2012
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.96 KB | None | 0 0
  1. '''
  2. from http://wiki.multimedia.cx/index.php?title=CRI_ADX_file
  3.  
  4. ADX format
  5.  
  6. --------------------------------------
  7. BYTE - usigned 1 byte
  8. SHORT- unsigned 2 bytes
  9. DWORD- unsigned 4 bytes
  10.  
  11. format is Big Endian
  12. --------------------------------------
  13.  
  14. SHORT - 0x000, header
  15. SHORT - data offset // In between the header and the audio data there is useless padding. Immediately before the audio data, the last 6 bytes of padding is the signature "(c)CRI" in ASCII.
  16. BYTE  - format, must be 3 for ADX
  17. BYTE  - block size (typically 18)
  18. BYTE  - bits per sample? (4)
  19. BYTE  - channel count, usually 1 or 2
  20. DWORD - sampling rate (Hz)
  21. DWORD - sample count
  22. SHORT - high-pass cutoff
  23. BYTE  - loop data type (03, 04, or 05)
  24. BYTE  - encryption flag (other flags?)
  25.  
  26. if "loop data" = 03:
  27.     DWORD - unknown
  28.     DWORD - loop flag
  29.     DWORD - loop start sample
  30.     DWORD - loop start byte
  31.     DWORD - loop end sample
  32.     DWORD - loop end byte
  33.    
  34. if "loop data" = 04:
  35.     BYTE[16] - unknown // It is possible that the extra 16 bytes for type 04 are involved in setting the initial decoder history; they are nonzero in the second segments of some AIXs (which may need some way to match up the history from one segment to another).
  36.     DWORD    - loop flag
  37.     DWORD - loop start sample
  38.     DWORD - loop start byte
  39.     DWORD - loop end sample
  40.     DWORD - loop end byte
  41.  
  42. # other loop types are unknown
  43. '''
  44.  
  45. import struct
  46. import sys
  47.  
  48. try:
  49.     filename = sys.argv[1]
  50. except:
  51.     filename = 'ay_getready.adx'
  52.  
  53. file = open(filename, 'rb')
  54.  
  55. header = hex(struct.unpack('>H', file.read(2))[0])
  56. print 'header:', header
  57.  
  58. dataoffset = struct.unpack('>H', file.read(2))[0]
  59. print 'data offset:', dataoffset
  60.  
  61. format = struct.unpack('>B', file.read(1))[0]
  62. print 'format:', format
  63.  
  64. blocksize = struct.unpack('>B', file.read(1))[0]
  65. print 'block size:', blocksize
  66.  
  67. bitspersample = struct.unpack('>B', file.read(1))[0]
  68. print 'bits per sample:', bitspersample
  69.  
  70. channelcount = struct.unpack('>B', file.read(1))[0]
  71. print 'channel count:', channelcount
  72.  
  73. samplingrate = struct.unpack('>I', file.read(4))[0]
  74. print 'sampling rate:', samplingrate, 'Hz'
  75.  
  76. samplecount = struct.unpack('>I', file.read(4))[0]
  77. print 'sample count:', samplecount
  78.  
  79. highpasscutoff = struct.unpack('>H', file.read(2))[0]
  80. print 'high pass cutoff:', highpasscutoff
  81.  
  82. loopdatatype = struct.unpack('>B', file.read(1))[0]
  83. print 'loop data type:', loopdatatype
  84.  
  85. if loopdatatype == 3:
  86.     unknown = file.read(4)
  87. elif loopdatatype == 4:
  88.     unknown = file.read(16)
  89. else:
  90.     print 'unknown loop data type'
  91.  
  92. loopflag = struct.unpack('>I', file.read(4))[0]
  93. print 'loop flag:', loopflag
  94.  
  95. loopstartsample = struct.unpack('>I', file.read(4))[0]
  96. print 'loop start sample:', loopstartsample
  97.  
  98. loopstartbyte = struct.unpack('>I', file.read(4))[0]
  99. print 'loop start byte:', loopstartbyte
  100.  
  101. loopendsample = struct.unpack('>I', file.read(4))[0]
  102. print 'loop end sample:', loopendsample
  103.  
  104. loopendbyte = struct.unpack('>I', file.read(4))[0]
  105. print 'loop end byte:', loopendbyte
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement