RIFFReader.st
changeset 1437 b4cc563c0895
parent 1434 9675c5ea14df
child 1446 47e9fb4be3b5
--- a/RIFFReader.st	Thu Nov 23 18:16:50 2000 +0100
+++ b/RIFFReader.st	Thu Nov 23 19:40:46 2000 +0100
@@ -13,7 +13,7 @@
 "{ Package: 'stx:libview2' }"
 
 Object subclass:#RIFFReader
-	instanceVariableNames:'inStream chunkSize streamTypes client'
+	instanceVariableNames:'inStream fileType streamTypes client'
 	classVariableNames:'UnsupportedFormatErrorSignal'
 	poolDictionaries:''
 	category:'System-Support-FileFormats'
@@ -76,7 +76,7 @@
 
     |data1 inStream|
 
-    inStream := self streamReadingFile:aFileName.
+    inStream := aFileName asFilename readStream.
     inStream isNil ifTrue:[^ false].
     inStream binary.
 
@@ -88,8 +88,44 @@
 
     "
      RIFFReader isRIFFFile:'bitmaps/magtape.xpm'    
-     RIFFReader isRIFFFile:'/home2/pd_stuff/movies/avi/drlair.avi'      
+     RIFFReader isRIFFFile:'/phys/exept/home/pd_stuff/movies/avi/drlair.avi'      
      RIFFReader isRIFFFile: '/usr/share/sounds/alsa/test.wav'      
+     RIFFReader isRIFFFile: '../../goodies/sounds/testSounds/wav/gong.wav'      
+     RIFFReader isRIFFFile: '../../goodies/sounds/testSounds/aif/instr/conga_hi.aiff'      
+    "
+
+    "Created: 4.4.1997 / 22:35:52 / cg"
+    "Modified: 5.4.1997 / 16:12:16 / cg"
+!
+
+isRIFFFile:aFileName withType:type
+    "return true, if aFileName contains RIFF-encoded data of format:type"
+
+    |data1 len data3 inStream|
+
+    inStream := aFileName asFilename readStream.
+    inStream isNil ifTrue:[^ false].
+    inStream binary.
+
+    data1 := String new:4.
+    inStream nextBytes:4 into:data1.
+    len := inStream nextLongMSB:true.
+    data3 := String new:4.
+    inStream nextBytes:4 into:data3.
+
+    inStream close.
+
+    data3 := data3 withoutTrailingSeparators.
+    ((data1 = 'RIFF')
+    and:[data3 = type]) ifTrue:[
+        ^ true
+    ].
+    ^ false.
+
+    "
+     RIFFReader isRIFFFile:'bitmaps/magtape.xpm' withType:'AVI '   
+     RIFFReader isRIFFFile:'/phys/exept/home/pd_stuff/movies/avi/drlair.avi' withType:'AVI'     
+     RIFFReader isRIFFFile: '/usr/share/sounds/alsa/test.wav' withType:'WAVE'      
     "
 
     "Created: 4.4.1997 / 22:35:52 / cg"
@@ -144,7 +180,7 @@
 getChunk
     "get a single chunk"
 
-    |id sel sTyp|
+    |id sel sTyp chunkSize|
 
     'getChunk -> ' infoPrint.
 
@@ -161,11 +197,11 @@
 
 "/id infoPrint. ' -> ' infoPrint. sel infoPrintCR.
         sel := sel asSymbolIfInterned.
-        (sel isNil or:[(self respondsTo:sel) not]) ifTrue:[
+        (sel isNil or:[(client respondsTo:sel) not and:[(self respondsTo:sel) not]]) ifTrue:[
             sel := 'getChunk_' , sTyp , '_Unknown:'.
 "/'  ' infoPrint. id infoPrint. ' -> ' infoPrint. sel infoPrintCR.
             sel := sel asSymbolIfInterned.
-            (sel isNil or:[(self respondsTo:sel) not]) ifTrue:[
+            (sel isNil or:[(client respondsTo:sel) not and:[(self respondsTo:sel) not]]) ifTrue:[
                 '[' infoPrint. ('getChunk_' , sTyp , '_' , (id copyFrom:3)) infoPrint. '] ' infoPrint.
                 sel := #'getChunk_Unknown:'.    
 "/'    ' infoPrint. id infoPrint. ' -> ' infoPrint. sel infoPrintCR.
@@ -176,7 +212,7 @@
             id := id copyTo:3
         ].
         sel := ('getChunk_' , id , ':') asSymbolIfInterned.
-        (sel isNil or:[(self respondsTo:sel) not]) ifTrue:[
+        (sel isNil or:[(client respondsTo:sel) not and:[(self respondsTo:sel) not]]) ifTrue:[
             '[' infoPrint. ('getChunk_' , id) infoPrint. '] ' infoPrint.
             sel := #'getChunk_Unknown:'    
         ].
@@ -235,7 +271,7 @@
 
     'getChunk_RIFF' infoPrint.
 
-    inStream skip:4.
+    fileType := (inStream next:4) asString.
 !
 
 getChunk_Unknown:chunkSize
@@ -284,6 +320,6 @@
 !RIFFReader class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview2/RIFFReader.st,v 1.4 2000-11-23 17:08:13 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview2/RIFFReader.st,v 1.5 2000-11-23 18:40:29 cg Exp $'
 ! !
 RIFFReader initialize!