Concatenating binary files?

Ned Konz ned at bike-nomad.com
Mon Mar 31 21:11:53 UTC 2003


On Monday 31 March 2003 12:59 pm, Jimmie Houchin wrote:
> 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?

Yes, when you go "wave3 nextPutAll: wave1" you're sending a ReadStream to a StandardFileStream when it wants a ByteArray.

That is, you're doing too much work <g>.

Try this (untested) code:

"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 contentsOfEntireFile.
  wave2 := (StandardFileStream fileNamed: file2) binary contentsOfEntireFile.
  wave3 := (StandardFileStream fileNamed: file3) binary.
  wave3 nextPutAll: wave1.
  wave3 nextPutAll: wave2.
  wave3 close.
  wave2 close.
  wave1 close.

-- 
Ned Konz
http://bike-nomad.com
GPG key ID: BEEA7EFE



More information about the Squeak-dev mailing list