<commit_before>audioContext = null
canvas = null
canvasContext = null

copyBuffers = (buffers, dest) ->
  offset = 0
  for buffer in buffers
    dest.set buffer, offset
    offset += buffer.length

  dest

connectRecorder = (stream) ->
  audioContext = new AudioContext()

  hzElement = document.getElementById("hz")
  noteElement = document.getElementById("note")

  bufferSize = 2048
  recorder = audioContext.createScriptProcessor(bufferSize, 2, 2)
  recorder.onaudioprocess = (e) ->
    left = e.inputBuffer.getChannelData(0)
    drawWave(left)
    hz = Pitcher.pitch(left, audioContext.sampleRate)
    return unless hz >= 30
    note = new Note(hz)
    hzElement.innerHTML = 'hz = ' + hz
    noteElement.innerHTML = 'note = ' + note.name()

  # connect the recorder
  input = audioContext.createMediaStreamSource(stream)
  input.connect recorder
  recorder.connect audioContext.destination

setPixel = (imageData, x, y, color) ->
  width = imageData.width
  data = imageData.data
  index = ((width * y) + x) * 4
  data[index] = color.r unless isNaN(color.r)
  data[index + 1] = color.g unless isNaN(color.g)
  data[index + 2] = color.b unless isNaN(color.b)
  data[index + 3] = color.a unless isNaN(color.a)

drawWave = (buffer) ->
  canvasContext.save()
  canvasContext.fillStyle = "rgb(30, 30, 30)"
  canvasContext.fillRect 0, 0, canvas.width, canvas.height
  canvasContext.restore()
  imageData = canvasContext.getImageData(0, 0, canvas.width, canvas.height)
  color =
    r: 200
    g: 200
    b: 200
    a: 255

  width = imageData.width
  height = imageData.height

  for x in [0...width]
    y = Math.floor(height/2+buffer[x*2]*height)
    setPixel imageData, x, y, color

  canvasContext.putImageData imageData, 0, 0

@common.init = ->
  navigator.getUserMedia = navigator.getUserMedia or navigator.webkitGetUserMedia or navigator.mozGetUserMedia or navigator.msGetUserMedia unless navigator.getUserMedia
  window.AudioContext = window.webkitAudioContext unless window.AudioContext

  if navigator.getUserMedia and window.AudioContext
    navigator.getUserMedia
      audio: true
    ,connectRecorder, -> alert "error capturing audio."
  else
    alert "not supported in this browser."
    return

  canvas = document.getElementById("wave")
  canvasContext = canvas.getContext("2d")<commit_msg>remove a method<commit_after>audioContext = null
canvas = null
canvasContext = null

setPixel = (imageData, x, y, color) ->
  width = imageData.width
  data = imageData.data
  index = ((width * y) + x) * 4
  data[index] = color.r unless isNaN(color.r)
  data[index + 1] = color.g unless isNaN(color.g)
  data[index + 2] = color.b unless isNaN(color.b)
  data[index + 3] = color.a unless isNaN(color.a)

drawWave = (buffer) ->
  canvasContext.save()
  canvasContext.fillStyle = "rgb(30, 30, 30)"
  canvasContext.fillRect 0, 0, canvas.width, canvas.height
  canvasContext.restore()
  imageData = canvasContext.getImageData(0, 0, canvas.width, canvas.height)
  color =
    r: 200
    g: 200
    b: 200
    a: 255

  width = imageData.width
  height = imageData.height

  for x in [0...width]
    y = Math.floor(height/2+buffer[x*2]*height)
    setPixel imageData, x, y, color

  canvasContext.putImageData imageData, 0, 0

connectRecorder = (stream) ->
  audioContext = new AudioContext()

  hzElement = document.getElementById("hz")
  noteElement = document.getElementById("note")

  bufferSize = 2048
  recorder = audioContext.createScriptProcessor(bufferSize, 2, 2)
  recorder.onaudioprocess = (e) ->
    left = e.inputBuffer.getChannelData(0)
    drawWave(left)
    hz = Pitcher.pitch(left, audioContext.sampleRate)
    return unless hz >= 30
    note = new Note(hz)
    hzElement.innerHTML = 'hz = ' + hz
    noteElement.innerHTML = 'note = ' + note.name()

  # connect the recorder
  input = audioContext.createMediaStreamSource(stream)
  input.connect recorder
  recorder.connect audioContext.destination

@common.init = ->
  navigator.getUserMedia = navigator.getUserMedia or navigator.webkitGetUserMedia or navigator.mozGetUserMedia or navigator.msGetUserMedia unless navigator.getUserMedia
  window.AudioContext = window.webkitAudioContext unless window.AudioContext

  if navigator.getUserMedia and window.AudioContext
    navigator.getUserMedia
      audio: true
    ,connectRecorder, -> alert "error capturing audio."
  else
    alert "not supported in this browser."
    return

  canvas = document.getElementById("wave")
  canvasContext = canvas.getContext("2d")
{'fraction_non_alphanumeric': 0.10845793349698728, 'fraction_numerical': 0.018522651193929925, 'mean_word_length': 3.85590465872156, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1504711', 'n_tokens_mistral': 1513, 'n_tokens_neox': 1410, 'n_words': 354}