lib/shoes/swt/sound.rb in shoes-swt-4.0.0.pre6 vs lib/shoes/swt/sound.rb in shoes-swt-4.0.0.pre7
- old
+ new
@@ -15,11 +15,11 @@
JFile = java.io.File
import java.io.BufferedInputStream
import javax.sound.sampled
import java.io.IOException
- BufferSize = 4096
+ BUFFER_SIZE = 4096
def initialize(dsl, _app)
@dsl = dsl
end
@@ -49,65 +49,63 @@
puts ioex.inspect, ioex.backtrace
# rescue JIOException => jioex
# jioex.stacktrace
rescue LineUnavailableException => luex
puts luex.inspect, luex.backtrace
- rescue Exception => e
+ rescue => e
puts e.inspect, e.backtrace
end
end
end
def decode_input_stream(audio_format, audio_input_stream)
case audio_format.encoding
- when Java::JavazoomSpiVorbisSampledFile::VorbisEncoding, Java::JavazoomSpiMpegSampledFile::MpegEncoding
- decoded_format = AudioFormat.new(AudioFormat::Encoding::PCM_SIGNED,
- audio_format.getSampleRate,
- 16,
- audio_format.getChannels,
- audio_format.getChannels * 2,
- audio_format.getSampleRate,
- false)
- decoded_audio_input_stream = AudioSystem.getAudioInputStream(decoded_format, audio_input_stream)
+ when Java::JavazoomSpiVorbisSampledFile::VorbisEncoding, Java::JavazoomSpiMpegSampledFile::MpegEncoding
+ decoded_format = AudioFormat.new(AudioFormat::Encoding::PCM_SIGNED,
+ audio_format.getSampleRate,
+ 16,
+ audio_format.getChannels,
+ audio_format.getChannels * 2,
+ audio_format.getSampleRate,
+ false)
+ decoded_audio_input_stream = AudioSystem.getAudioInputStream(decoded_format, audio_input_stream)
- return decoded_format, decoded_audio_input_stream
+ return decoded_format, decoded_audio_input_stream
- else
- return audio_format, audio_input_stream
+ else
+ [audio_format, audio_input_stream]
end
end
def rawplay(decoded_audio_format, decoded_audio_input_stream)
# throws IOException, LineUnavailableException
- sampled_data = Java::byte[BufferSize].new
+ sampled_data = Java::byte[BUFFER_SIZE].new
line = getLine(decoded_audio_format)
unless line.nil?
# Start
line.start
bytes_read = 0
while bytes_read != -1
bytes_read = decoded_audio_input_stream.read(sampled_data, 0, sampled_data.length)
- if bytes_read != -1
- line.write(sampled_data, 0, bytes_read)
- end
+ line.write(sampled_data, 0, bytes_read) if bytes_read != -1
end
# Stop
line.drain
line.stop
line.close
decoded_audio_input_stream.close
end
end
- def getLine(audioFormat)
+ def getLine(audio_format)
# throws LineUnavailableException
- info = DataLine::Info.new(SourceDataLine.java_class, audioFormat)
+ info = DataLine::Info.new(SourceDataLine.java_class, audio_format)
res = AudioSystem.getLine(info)
- res.open(audioFormat)
+ res.open(audio_format)
res
end
end
end
end