<commit_before>import portaudio as PA
from math import sin, pi

type
  TUserData = object
    count : int64
  TFloatBuffer {.unchecked.} = array[0..0, float32]

let samplerate = 44100.0

proc streamCallback(inBuf, outBuf: pointer,
                    framesPerBuf: culong,
                    timeInfo: ptr TStreamCallbackTimeInfo,
                    statusFlags: TStreamCallbackFlags,
                    userData: pointer): cint {.cdecl.} =
  var
    outBuf = cast[ptr TFloatBuffer](outBuf)
    userData = cast[ptr TUserData](userData)

  for i in 0.. <framesPerBuf.int:
    var val = 0.4 * sin((2.0 * pi * 440.0 * userData.count.float32) / samplerate)
    outBuf[i] = val
    userData.count += 1

  PA.scrContinue.cint

template check(call : expr) =
  assert(cast[TErrorCode](call) == PA.noError)

var
  stream: PStream
  userData = TUserData(count:0)

check(PA.initialize())
check(PA.openDefaultStream(cast[PStream](stream.addr),
                           numInputChannels = 0,
                           numOutputChannels = 1,
                           sampleFormat = sfFloat32,
                           sampleRate = samplerate,
                           framesPerBuffer = 512,
                           streamCallback = streamCallback,
                           userData = cast[pointer](userData.addr)))
check(PA.startStream(stream))
PA.sleep(2000)
check(PA.stopStream(stream))
check(PA.closeStream(stream))
check(PA.terminate())<commit_msg>case needed to be changed in symbols for nim 0.10.2 for some reason<commit_after>import portaudio as PA
from math import sin, PI

type
  TUserData = object
    count : int64
  TFloatBuffer {.unchecked.} = array[0..0, float32]

let samplerate = 44100.0

proc streamCallback(inBuf, outBuf: pointer,
                    framesPerBuf: culong,
                    timeInfo: ptr TStreamCallbackTimeInfo,
                    statusFlags: TStreamCallbackFlags,
                    userData: pointer): cint {.cdecl.} =
  var
    outBuf = cast[ptr TFloatBuffer](outBuf)
    userData = cast[ptr TUserData](userData)

  for i in 0.. <framesPerBuf.int:
    var val = 0.4 * sin((2.0 * PI * 440.0 * userData.count.float32) / samplerate)
    outBuf[i] = val
    userData.count += 1

  PA.scrContinue.cint

template check(call : expr) =
  assert(cast[TErrorCode](call) == PA.NoError)

var
  stream: PStream
  userData = TUserData(count:0)

check(PA.Initialize())
check(PA.OpenDefaultStream(cast[PStream](stream.addr),
                           numInputChannels = 0,
                           numOutputChannels = 1,
                           sampleFormat = sfFloat32,
                           sampleRate = samplerate,
                           framesPerBuffer = 512,
                           streamCallback = streamCallback,
                           userData = cast[pointer](userData.addr)))
check(PA.StartStream(stream))
PA.Sleep(2000)
check(PA.StopStream(stream))
check(PA.CloseStream(stream))
check(PA.Terminate())
{'fraction_non_alphanumeric': 0.10121457489878542, 'fraction_numerical': 0.02564102564102564, 'mean_word_length': 2.150903294367694, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '6573850', 'n_tokens_mistral': 933, 'n_tokens_neox': 873, 'n_words': 195}