[tuxdroid-svn] r156 - api/python/trunk
Status: Beta
Brought to you by:
ks156
From: remi <c2m...@c2...> - 2007-03-14 12:27:04
|
Author: remi Date: 2007-03-14 13:26:52 +0100 (Wed, 14 Mar 2007) New Revision: 156 Modified: api/python/trunk/tuxapi_wav_merger.py Log: UPD : - The licence is added in the header. - Limiting of the size of the merged wave file to 70 seconds Modified: api/python/trunk/tuxapi_wav_merger.py =================================================================== --- api/python/trunk/tuxapi_wav_merger.py 2007-03-14 12:24:21 UTC (rev 155) +++ api/python/trunk/tuxapi_wav_merger.py 2007-03-14 12:26:52 UTC (rev 156) @@ -1,24 +1,51 @@ -## @package TuxFlashUploader -# Class for uploading TUX flash memory +# ----------------------------------------------------------------------------- +# Tux Droid - API Wav merger +# Copyright (C) 2007 C2ME Sa <rem...@c2...> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +# 02111-1307, USA. +# ----------------------------------------------------------------------------- +# $Id$ +# ----------------------------------------------------------------------------- import tuxapi_class +#============================================================================== ## Class for uploading TUX flash memory +#============================================================================== class WavMerger(object): + # ------------------------------------------------------------------------- ## Constructor of object ## @param tux : TUXTCPCommunicator object + # ------------------------------------------------------------------------- def __init__(self,tux): self.wav_paths =[] self.wav_sizes =[] + # ------------------------------------------------------------------------- ## Add a wav path to wavs list ## @param path : Path of wav file + # ------------------------------------------------------------------------- def add_wav_path(self,path): self.wav_paths.append(path) self.add_wav_length(path) + # ------------------------------------------------------------------------- ## SYSTEM function + # ------------------------------------------------------------------------- def add_wav_length(self,path): f = open(path,'rb') wh = f.read(44) @@ -27,33 +54,41 @@ f.close() self.wav_sizes.append(wav_length) + # ------------------------------------------------------------------------- ## SYSTEM function + # ------------------------------------------------------------------------- def done_wavs_size(self): size = 0 for w_size in self.wav_sizes: size = size+w_size return size + # ------------------------------------------------------------------------- ## Merge all the wav files contained in the wavs list ## @param path : Path of output wav file merged + # ------------------------------------------------------------------------- def wavs_merging(self,path): - merged = open(path,'wb') - whfile = open(self.wav_paths[0],'rb') - header = whfile.read(40) - whfile.close() - merged.write(header) - full_size = self.done_wavs_size() + int(self.done_wavs_size() * 0.07) - st = chr(full_size & 0x000000FF) + \ - chr((full_size & 0x0000FF00) >> 8) + \ - chr((full_size & 0x00FF0000)>>16) + \ - chr((full_size & 0xFF000000)>>24) - merged.write(st) - for i, pathw in enumerate(self.wav_paths): - wwfile = open(pathw,'rb') - wwfile.seek(44) - stream = wwfile.read(self.wav_sizes[i]) - merged.write(stream) - wwfile.close() - while(merged.tell() < (full_size + 44) ): - merged.write(" ") - merged.close() + merged = open(path,'wb') + whfile = open(self.wav_paths[0],'rb') + header = whfile.read(40) + whfile.close() + merged.write(header) + full_size = self.done_wavs_size() + int(self.done_wavs_size() * 0.07) + if full_size>560000: + print "Wavs selection exceded 70 seconds !" + return False + st = chr(full_size & 0x000000FF) + \ + chr((full_size & 0x0000FF00) >> 8) + \ + chr((full_size & 0x00FF0000)>>16) + \ + chr((full_size & 0xFF000000)>>24) + merged.write(st) + for i, pathw in enumerate(self.wav_paths): + wwfile = open(pathw,'rb') + wwfile.seek(44) + stream = wwfile.read(self.wav_sizes[i]) + merged.write(stream) + wwfile.close() + while(merged.tell() < (full_size + 44) ): + merged.write(" ") + merged.close() + return True |