トップ «前の日記(2008-04-30) 最新 次の日記(2008-05-02)» 編集

日々の破片

Subscribe with livedoor Reader
著作一覧

2008-05-01

_ 今日は何の日?

いたずらラッコのバンデッタ

_ スクリプト言語

ううむ、確かに疑う余地が入る余地もなく、スクリプティング言語だけど、おれもト止めをさした覚えがあるなあ。

多分、JavaScriptという言語名かscript要素につられたのかも知れない。

_ Java Sound API

昨日のJava PRESSのkeiskenさんの記事から興味のある個所をRubyに翻案。
require 'rjb'
 
module Java
  File = Rjb::import('java.io.File')
end
module Javax
  #interfaces
  Clip = Rjb::import('javax.sound.sampled.Clip')
  DataLine = Rjb::import('javax.sound.sampled.DataLine')
  Line = Rjb::import('javax.sound.sampled.Line')
  LineListner = Rjb::import('javax.sound.sampled.LineListener')
  Mixer = Rjb::import('javax.sound.sampled.Mixer')
  Port = Rjb::import('javax.sound.sampled.Port')
  SourceDataLine = Rjb::import('javax.sound.sampled.SourceDataLine')
  TargetDataLine = Rjb::import('javax.sound.sampled.TargetDataLine')
  #classes
  AudioFormat = Rjb::import('javax.sound.sampled.AudioFormat')
  AudioInputStream = Rjb::import('javax.sound.sampled.AudioInputStream')
  AudioSystem = Rjb::import('javax.sound.sampled.AudioSystem')
  DataLineInfo = Rjb::import('javax.sound.sampled.DataLine$Info')
end
 
module SoundSampled
  class SoundFile
    include Javax
    def initialize(file = nil)
      file = Java::File.new('/windows/media/ding.wav') unless file
      @ais = AudioSystem.getAudioInputStream(file)
      @clip = AudioSystem.line(DataLineInfo.new(Clip, @ais.format))
    end
    def play(count = 0)
      @clip.open(@ais)
      @clip.loop(count)
      while @clip.running?
        sleep 0.1
      end
      sleep 3
      @clip.close
    end
  end
  class Sin
    include Javax
    FREQ = 1000
    TERM = 5
    RATE = 8000
    DR = 2 * Math::PI * FREQ / RATE
    def initialize
      @format = AudioFormat.new(RATE, 8, 1, true, true)
      @line = AudioSystem.line(DataLineInfo.new(SourceDataLine, @format))
    end
    def generate
      @wave = Array.new(RATE) do |i|
        (Math.sin(DR * i) * 100).to_i
      end
      p @wave if $DEBUG
    end
    def play
      @line.open(@format)
      @line.start
      off = 0
      len = @wave.size
      while len > 0
        written = @line.write(@wave, off, len)
        off += written
        len -= written
      end        
      @line.drain
      @line.close
    end
  end
end
if __FILE__ == $0
#  SoundSampled::SoundFile.new.play
  s = SoundSampled::Sin.new
  s.generate
  s.play
end

2003|06|07|08|09|10|11|12|
2004|01|02|03|04|05|06|07|08|09|10|11|12|
2005|01|02|03|04|05|06|07|08|09|10|11|12|
2006|01|02|03|04|05|06|07|08|09|10|11|12|
2007|01|02|03|04|05|06|07|08|09|10|11|12|
2008|01|02|03|04|05|06|07|08|09|10|11|12|
2009|01|02|03|04|05|06|07|08|09|10|11|12|
2010|01|02|03|04|05|06|07|08|09|10|11|12|
2011|01|02|03|04|05|06|07|08|09|10|11|12|
2012|01|02|03|04|05|06|07|08|09|10|11|12|
2013|01|02|03|04|05|06|07|08|09|10|11|12|
2014|01|02|03|04|05|06|07|08|09|10|11|12|
2015|01|02|03|04|05|06|07|08|09|10|11|12|
2016|01|02|03|04|05|06|07|08|09|10|11|12|
2017|01|02|03|04|05|06|07|08|09|10|11|12|
2018|01|02|03|04|05|06|07|08|09|10|11|12|
2019|01|02|03|04|05|06|07|08|

ジェズイットを見習え