Source

pyld / examples / pyside-algorithmic-music / mu.py

Full commit


if __name__ == '__pyld_init__':

  # imports

  import random
  import threading
  import PySide.QtCore
  import PySide.QtMultimedia

  # qt audio buffer
  audioBuffer = PySide.QtCore.QBuffer()

  # start qt in a separate thread

  PySide.QtCore.QThread(
    PySide.QtCore.QCoreApplication(''))

  # pyside audio setup

  audioFormat = PySide.QtMultimedia.QAudioFormat()
  audioFormat.setFrequency(8000)
  audioFormat.setChannels(1)
  audioFormat.setSampleSize(8)
  audioFormat.setCodec('audio/pcm')
  audioFormat.setByteOrder(PySide.QtMultimedia.QAudioFormat.LittleEndian)
  audioFormat.setSampleType(PySide.QtMultimedia.QAudioFormat.UnSignedInt)

  info = PySide.QtMultimedia.QAudioDeviceInfo(
    PySide.QtMultimedia.QAudioDeviceInfo.defaultOutputDevice())
  if not info.isFormatSupported(audioFormat):
    print 'raw audio format not supported by backend, cannot play audio.'
  else:
    print 'PySide accepted specified audio fromat.'

  audioOut = PySide.QtMultimedia.QAudioOutput(audioFormat)
  audioOut.start(audioBuffer)

if __name__ == '__pyld_reload__':

  print '__pyld_reload__'

  audioBuffer.setData('adijofpeoiqjfoijpkj')

if __name__ == '__pyld_tick__':
  pass