Concatenating binary files?

Jimmie Houchin jhouchin at texoma.net
Mon Mar 31 20:59:46 UTC 2003


Boris Gaertner wrote:
> Jimmie Houchin <jhouchin at texoma.net> wrote:
> 
>>I tried using StandardFileStream and #nextPutAll: to write the 2 wave 
>>files into a single then I got an error because #nextPutAll: accepts 
>>only strings. (I forgot) :)
>
> This is not always true.
> As soon as you have created the stream, you should send it the message
> binary. This messages replaces the standard buffer (an instance of String)
> with a buffer that is an instance of ByteArray.
> As soon as you have this buffer, you should be able to file out instances
> of ByteArray.
> 
> (Have a look at AbstractSound>>storeWAVOnFileNamed)
> 
> Hope this helps.
> Boris

Hello Boris,

Thanks for the help. Unfortunately I'm still having problems.

Below is the latest code I've attempted in a workspace.
I get this error:
StandardFileStream(Object)>>error:
error: aString
	"Throw a generic Error exception."
	^Error new signal: aString

"Concatenate 2 Wave Files"
| fileDir wave1 wave2 wave3 file1 file2 file3 |
fileDir := FileDirectory on: 'C:\Documents and Settings\Jimmie\My 
Documents\My Music\MP3\Alexander Scourby\waves'.
file1 := fileDir fullName, '\Genesis 37a.wav'.
file2 := fileDir fullName, '\Genesis 37b.wav'.
file3 := fileDir fullName, '\Genesis 37k.wav'.
  wave1 := (StandardFileStream fileNamed: file1) binary.
  wave1 := ReadStream on: wave1 contentsOfEntireFile.
  wave2 := (StandardFileStream fileNamed: file2) binary.
  wave2 := ReadStream on: wave2 contentsOfEntireFile.
  wave3 := (StandardFileStream fileNamed: file3) binary.
  wave3 nextPutAll: wave1.
  wave3 nextPutAll: wave2.
  wave3 flush.
  wave3 close.
  wave2 close.
  wave1 close.

I've browsed the WAV code. I don't understand most of it. I've browsed 
lots of code to find examples of writing binary data to files. I haven't 
succeded in learning yet. I don't know what I'm missing.

I've banged my head on this for a few hours browsing code trying to learn.

I'm no Python expert but in less that 5 minutes I did the below and was 
successful at accomplishing my task.

I am very pro Squeak. It is frustrating that I was able to accomplish 
this so easily in Python, but have heretofore failed in Squeak. :(

Anybody know where I'm failing above?

Thanks,

Jimmie Houchin



Python shell session.
 >>> cdir = 'C:\\Documents and Settings\\Jimmie\\My Documents\\My
 >>> Music\\MP3\\Alexander Scourby\\'
 >>> file1name = cdir + 'Genesis 37a.wav'
 >>> file2name = cdir + 'Genesis 37b.wav'
 >>> file3name = cdir + 'Genesis 37.wav'
 >>> file1 = file(file1name,'rb')
 >>> file2 = file(file2name,'rb')
 >>> file3 = file(file3name,'wb')
 >>> file1contents = file1.read()
 >>> file2contents = file2.read()
 >>> file3.write(file1contents + file2contents)
 >>> file3.flush()
 >>> file3.close()
 >>> file2.close()
 >>> file1.close()




More information about the Squeak-dev mailing list