Irrklang & Incbin / loading from stream

BlitzMax Forums/BlitzMax Programming/Irrklang & Incbin / loading from stream

Hi there,

I've got a problem: I'ld like to play my sounds out of incbin:: with Irrklang, does anybody know how to do this? Or is it not possible?

Alternatively I would like to play them out of a TStream or Bank (so I could encrypt them). The problem is, that I don't want the soundfiles laying around unsecured in my gamefolder's datadir.

Here is typically how I would encrypt my data: Give your sound types the DeSerialize(TStream) and Serialize(TStream) methods, and have them save (Serialize) and load (DeSerialize) in the same order. So you could, for example, serialize the type into a bankstream (in memory) and encrypt the bankstream (using RC4) before outputting to the external file. When DeSerializing you just have to load the stream into a bankstream again and decrypt before passing it off to the DeSerialize type.

Here is some example code (progressive saving):
'The TTile type..
		Method DeSerialize:TTile(stream:TStream)
			
			SetId(stream.ReadInt())
			SetName(ReadNString(stream))
			
			setFlags(stream.ReadInt())
			
			texture = TTileTexture.Load(stream)
			
		   Return Self
		   
		End Method
		
		Method Serialize(stream:TStream)
			
			stream.WriteInt(getID())
			WriteNString(stream, GetName())
			
			stream.WriteInt(GetFlags())
			
			texture.Serialize(stream)
			
		End Method

'The TTileTexture type
		Method Serialize(stream:TStream)
			
			PixmapDataType.WriteObject(getPixmap(), stream)
			
		End Method
		
		Method DeSerialize:TTileTexture(stream:TStream)
		  Local pix:Object
			
			pix = PixmapDataType.ReadObject(stream)
			
			SetPixmap(TPixmap(pix))
			
		   Return Self
		   
		End Method


Now, I'm not certain the sound module has implemented the saving of sound data, if it does there should be a SoundDataType (or similar) global instance defined somewhere in one of the sound/audio modules - you might have to figure out how to save it without!

And loading a 'soundmap,' if you will, could be done with a While...Wend loop (TTile.Load() is a wrapper function for creating and DeSerializing a TTile):
'The TTileMap type..
		Method DeSerialize:TTileMap(stream:TStream)
			
			While Not stream.Eof()
				
				InsertTile(TTile.Load(stream))
				
			Wend
			
		   Return Self
		   
		End Method


A Serializing example:
Local mainset:TTileMap = New(TTileMap).Create()
'Insert some tiles...

'Save the information in-memory and then output it to 'set00.dts'
Local stream:TBankStream = CreateBankStream(Null)
	
	mainset.Serialize(stream)
	
	CryptStream(stream, "inputkeyhere!")
	stream._bank.Save("set00.dts")
	
stream.Close()

'Since RC4 can be used the exact same way to encrypt and decrpyt information, this function can be used to Decrypt or Encrypt the stream
Function CryptStream:TBankStream(url:Object, Key:String)
  Local bstream:TBankStream = TBankStream(url)
	
	If bstream = Null
		
		bstream = TBankStream.Create(TBank.Load(url))
		
	End If
	
	If bstream <> Null
		
		RC4_Bytes(bstream._bank.Lock(), bstream._bank.Capacity(), Key)
		
	End If
	
   Return bstream
   
End Function


I'll be releasing all the memcrypt modules within the next few weeks.

hmm, thanks, but my problem is, that the Irrklang module can't read from streams, just from strings (=filepath). But I just figured out that it is possible to use "incbin::" with the modules function Play2DSound(). So:

< PROBLEM SOLVED >

By the way, i read that you're working on memcrypt modules? A few weeks ago I released the fdm.tcrypt module here in the module section, with aes encryption. But sadly my implementation is too slow... Maybe you want to take a look on that?

My current memcrypt code is basically just RC4_Bytes and CryptStream, which both work snappily.