コード例 #1
0
ファイル: sndfiletest.py プロジェクト: rolodub/thesis
	def test_headerReadAndWrite_settingAUformat(self) :
		wavoutput = sndfile.sndfile("test.au","w", format= sndfile.AU | sndfile.FLOAT)
		wavoutput.close()
		wavinput = sndfile.sndfile("test.au","r")
		self.assertEqual(sndfile.AU | sndfile.FLOAT, wavinput.getFormat())
		self.assertEqual(1, wavinput.getChannels())
		self.assertEqual(44100, wavinput.getSampleRate())
コード例 #2
0
ファイル: sndfiletest.py プロジェクト: rolodub/thesis
	def test_headerReadAndWrite_byDefaultChangingExtensionToAU(self) :
		wavoutput = sndfile.sndfile("test.au","w")
		wavoutput.close()
		wavinput = sndfile.sndfile("test.au","r")
		self.assertEqual(sndfile.AU | sndfile.PCM16, wavinput.getFormat())
		self.assertEqual(1, wavinput.getChannels())
		self.assertEqual(44100, wavinput.getSampleRate())
コード例 #3
0
ファイル: sndfiletest.py プロジェクト: rolodub/thesis
	def test_headerReadAndWrite_settingEverything(self) :
		wavoutput = sndfile.sndfile("test.wav","w", format= sndfile.WAV | sndfile.PCM24, channels = 2, samplerate = 22050)
		wavoutput.close()
		wavinput = sndfile.sndfile("test.wav","r")
		self.assertEqual(sndfile.WAV | sndfile.PCM24, wavinput.getFormat())
		self.assertEqual(2, wavinput.getChannels())
		self.assertEqual(22050, wavinput.getSampleRate())
コード例 #4
0
ファイル: sndfiletest.py プロジェクト: rolodub/thesis
	def test_headerReadAndWrite_settingAIFFformat(self) :
		wavoutput = sndfile.sndfile("test.aiff","w", format= sndfile.AIFF | sndfile.PCM32)
		wavoutput.close()
		wavinput = sndfile.sndfile("test.aiff","r")
		self.assertEqual(sndfile.AIFF | sndfile.PCM32, wavinput.getFormat())
		self.assertEqual(1, wavinput.getChannels())
		self.assertEqual(44100, wavinput.getSampleRate())
コード例 #5
0
ファイル: sndfiletest.py プロジェクト: rolodub/thesis
	def test_headerReadAndWrite_settingFormat(self) :
		wavoutput = sndfile.sndfile("test.wav","w", format= sndfile.WAV | sndfile.PCM24)
		wavoutput.close()
		wavinput = sndfile.sndfile("test.wav","r")
		self.assertEqual(sndfile.WAV | sndfile.PCM24, wavinput.getFormat())
		self.assertEqual(1, wavinput.getChannels())
		self.assertEqual(44100, wavinput.getSampleRate())
コード例 #6
0
ファイル: sndfiletest.py プロジェクト: rolodub/thesis
	def test_readFile_whenMalformed(self) :
		waveoutput = open("test.wav", "w")
		print >> waveoutput, "This is not a wav"
		waveoutput.close()
		try :
			sndfile.sndfile("test.wav","r")
			self.fail("Should have thrown an exception")
		except sndfile.IOException, e :
			self.assertEqual(("File contains data in an unknown format.",), e.args)
コード例 #7
0
ファイル: sndfiletest.py プロジェクト: rolodub/thesis
	def test_readWriteToOneChannel(self):
		wavoutput = sndfile.sndfile("test.wav", "w")
		seconds = 10
		wav = numpy.ones((1, 44100 * seconds))
		wav[0,:]*=.6
		wavoutput.write(wav)
		wavoutput.close()
		wavinput = sndfile.sndfile("test.wav", "r")
		result = numpy.zeros((1, 44100 * seconds))
		self.assertEqual(1 * 44100 * seconds , wavinput.read(result)) #Number of items: CHANNELS * SAMPLERATE * SECONDS
		self.assertEqual(wav.all() , result.all())
コード例 #8
0
ファイル: sndfiletest.py プロジェクト: rolodub/thesis
	def test_writeReadGetFrames(self):
		wavoutput = sndfile.sndfile("test.wav", "w", channels=2)
		seconds = 60
		frames =  wavoutput.getSampleRate() * seconds
		wav = numpy.ones((wavoutput.getChannels(), frames))
		wav[0,:]*=.6
		wav[1,:]*=.3
		wavoutput.write(wav)
		wavoutput.close()
		wavinput = sndfile.sndfile("test.wav", "r")
		self.assertEqual(frames , wavinput.getFrames())
コード例 #9
0
ファイル: sndfiletest.py プロジェクト: rolodub/thesis
	def test_readWriteTwoChannels(self):
		wavoutput = sndfile.sndfile("test.wav", "w", channels=2)
		seconds = 60
		wav = numpy.ones((2, 44100 * seconds))
		wav[0,:]*=.6
		wav[1,:]*=.3
		wavoutput.write(wav)
		wavoutput.close()
		wavinput = sndfile.sndfile("test.wav", "r")
		result = numpy.zeros((2, 44100 * seconds))
		self.assertEqual(2 * 44100 * seconds , wavinput.read(result))
		self.assertEqual(wav.all() , result.all())
コード例 #10
0
ファイル: sndfiletest.py プロジェクト: rolodub/thesis
	def test_writeReadFourChannelsCreatingBufferWithFileInfo(self):
		channels = 4
		wavoutput = sndfile.sndfile("test.wav", "w", channels=channels)
		seconds = 60
		frames =  wavoutput.getSampleRate() * seconds
		wav = numpy.ones((channels, frames))
		wav[0,:]*=.8
		wav[1,:]*=.6
		wav[1,:]*=.4
		wav[1,:]*=.2
		self.assertEqual(channels * frames , wavoutput.write(wav))
		wavoutput.close()
		wavinput = sndfile.sndfile("test.wav", "r")
		result = numpy.zeros((wavinput.getChannels(), wavinput.getFrames())) #With this, we make sure that the buffer will hold all the data
		self.assertEqual(channels * frames, wavinput.read(result))
		self.assertEqual(wav.all() , result.all())
コード例 #11
0
ファイル: sndfiletest.py プロジェクト: rolodub/thesis
	def test_Metadata_settingTagNotSupported(self):
		wavoutput = sndfile.sndfile("test.wav","w")
		try :
			wavoutput.setString("TagNotSupported", "Trying to throw an exception")
			self.fail("Should have thrown an exception")
		except sndfile.TagNotSupported, e :
			self.assertEqual(("setString error : Tag not supported by sndfile.",), e.args)
			wavoutput.close()
コード例 #12
0
ファイル: sndfiletest.py プロジェクト: rolodub/thesis
	def _test_writeFile_withBadParameters(self) :
		try :
			wavoutput = sndfile.sndfile("test.wav","w", format=sndfile.WAV|sndfile.VORBIS )
			self.fail("Should have thrown an exception")
		except sndfile.UnsupportedFormatException, e :
			self.assertEqual("TODO: Lo que devuelva sf_strerror", e.args)
コード例 #13
0
ファイル: sndfiletest.py プロジェクト: rolodub/thesis
	def test_writeFile_closing(self) :
		wavoutput = sndfile.sndfile("test.wav","w")
		wavoutput.close()
		self.assertEqual(True, os.access("test.wav", os.R_OK))
コード例 #14
0
ファイル: sndfiletest.py プロジェクト: rolodub/thesis
	def test_Metadata_settingComment(self):
		wavoutput = sndfile.sndfile("test.wav","w")
		wavoutput.setString("comment", "Adding a comment")
		self.assertEqual("Adding a comment", wavoutput.getString("comment"))
		wavoutput.close()
コード例 #15
0
ファイル: sndfiletest.py プロジェクト: rolodub/thesis
	def test_readFile_whenDoesNotExist(self) :
		try :
			sndfile.sndfile("notexisting.wav","r")
			self.fail("Should have thrown an exception")
		except sndfile.IOException, e :
			self.assertEqual(("System error : No such file or directory.",), e.args)
コード例 #16
0
ファイル: sndfiletest.py プロジェクト: rolodub/thesis
	def test_Metadata_settingDate(self):
		wavoutput = sndfile.sndfile("test.wav","w")
		wavoutput.setString("date", "15-04-2010")
		self.assertEqual("15-04-2010", wavoutput.getString("date"))
		wavoutput.close()
コード例 #17
0
ファイル: sndfiletest.py プロジェクト: rolodub/thesis
	def test_Metadata_settingCopyright(self):
		wavoutput = sndfile.sndfile("test.wav","w")
		wavoutput.setString("copyright", "Testing the copyright")
		self.assertEqual("Testing the copyright", wavoutput.getString("copyright"))
		wavoutput.close()
コード例 #18
0
ファイル: sndfiletest.py プロジェクト: rolodub/thesis
	def test_Metadata_settingSoftware(self):
		wavoutput = sndfile.sndfile("test.wav","w")
		wavoutput.setString("software", "Python/C API")
		self.assertEqual("Python/C API (libsndfile-1.0.20)", wavoutput.getString("software"))
		wavoutput.close()
コード例 #19
0
ファイル: sndfiletest.py プロジェクト: rolodub/thesis
	def test_Metadata_settingArtist(self):
		wavoutput = sndfile.sndfile("test.wav","w")
		wavoutput.setString("artist", "Testing the Artist")
		self.assertEqual("Testing the Artist", wavoutput.getString("artist"))
		wavoutput.close()
コード例 #20
0
ファイル: sndfiletest.py プロジェクト: rolodub/thesis
	def test_Metadata_settingTitle(self):
		wavoutput = sndfile.sndfile("test.wav","w")
		wavoutput.setString("title", "Testing the Title")
		self.assertEqual("Testing the Title", wavoutput.getString("title"))
		wavoutput.close()