python code to java

CLOSED
Bids
5
Avg Bid (USD)
$28
Project Budget (USD)
$10 - $30

Project Description:
pure and simple, just convert this code to java, we shall validate it if the code works properly. if not, no payment.

#!/usr/bin/python

import numpy as N
import wave
import sys

class IrSoundFile:
def __init__( self, make, model, signal ):
self.shift = 0
dir = make + '/' + model
#`mkdir -p $dir`
self.file = wave.open( dir + '/' + signal + '.wav', 'wb' )
self.data = []

def write_data(self):
data_str = ''.join(self.data)
self.file.setparams( ( 2, 2, self.base_frequency, len( data_str ), 'NONE', 'noncompressed' ) )
self.file.writeframes(data_str)

def close(self):
self.file.close()

def add_vals(self, count, val):
counter = 0
half_base = self.base_frequency / 2
while counter < count:
if val == 1:
ir_val = 0xFF7F
if self.shift > ( half_base ):
ir_val = 0xFFFF - ir_val
else:
ir_val = 0x7FFF
#print( "IR_VAL: %d" % ( ir_val ) )
self.data.append( wave.struct.pack( '>H', ir_val ) ) # left channel
self.data.append( wave.struct.pack( '>H', ir_val ) ) # right channel
old_shift = self.shift
self.shift += self.frequency
if self.shift > self.base_frequency: # I guess this is faster than %
self.shift = self.shift - self.base_frequency
if not ( ( old_shift < half_base ) and ( self.shift < half_base ) or ( old_shift > half_base ) and ( self.shift > half_base ) ):
counter += 1

def add_pairs( self, ones, zeros ):
self.add_vals( int( ones, 16 ), 1 )
self.add_vals( int( zeros, 16 ), 0 )
sys.stdout.write( "%s %s | " % ( ones, zeros ) )


def write_ir_code( self, str ):
self.base_frequency = 44100 # the freq of the wav file
frequencies = { '006d' : 38200 / 2 } # IR freq / 2 (b/c we're using 2 of those)
codes = str.split( ' ' )
( self.frequency, sequence_1_len, sequence_2_len ) = ( frequencies[codes[1]], int( codes[2], 16 ), int( codes[3], 16 ) )
print "S1L:%d S2L:%d FRQ:%d BFRQ:%d" % ( sequence_1_len, sequence_2_len, self.frequency, self.base_frequency)
print "Writing sequence 1 240 times"
for j in range( 1, 4 ):
for i in range( 1, sequence_1_len + 1 ):
self.add_pairs( codes[i * 2 + 2], codes[i * 2 + 1 + 2] )
print "\nWriting sequence 2 one time"
for j in range( 1, 1 ):
for i in range( 1, sequence_2_len + 1 ):
self.add_pairs( codes[i * 2 + 2 + sequence_1_len], codes[i * 2 + 1 + 2 + sequence_1_len] )
print ""
self.write_data()

Skills required:
Java, Python
Hire thegroove
Project posted by:
thegroove India
Verified
Public Clarification Board
Bids are hidden by the project creator. Log in as the employer to view bids or to bid on this project.
You will not be able to bid on this project if you are not qualified in one of the job categories. To see your qualifications click here.


Hire poornachand
$ 30
in 2 days
Hire sousivw
$ 30
in 3 days
$ 25
in 3 days
Hire MartinMunoz
$ 25
in 3 days
Hire Carlangueitor
$ 30
in 3 days