|
|
2010-09-05
, 01:26
|
|
Posts: 6 |
Thanked: 3 times |
Joined on May 2010
|
#2
|
i'm trying to run the following code on N900, but it produces "segmentation fault" error, and crashes.
The error is produced when the code enters the line "self.output.start(self.buffer)"
This code runs as it should on a Windows PyQt4 setup, but on N900 it refuses to work.
Can someone spot the problem? Has it something to do with the maemo PyQt4 or Qt implementation?
|
|
2010-09-05
, 08:22
|
|
Posts: 20 |
Thanked: 11 times |
Joined on Feb 2010
|
#3
|
|
|
2010-09-05
, 08:33
|
|
Posts: 3,319 |
Thanked: 5,610 times |
Joined on Aug 2008
@ Finland
|
#4
|
|
|
2010-09-05
, 08:48
|
|
Posts: 20 |
Thanked: 11 times |
Joined on Feb 2010
|
#5
|
| The Following User Says Thank You to saveas For This Useful Post: | ||
i'm trying to run the following code on N900, but it produces "segmentation fault" error, and crashes.
The error is produced when the code enters the line "self.output.start(self.buffer)"
This code runs as it should on a Windows PyQt4 setup, but on N900 it refuses to work.
Can someone spot the problem? Has it something to do with the maemo PyQt4 or Qt implementation?
Thanks!
from math import pi, sin import struct, sys from PyQt4.QtCore import QBuffer, QByteArray, QIODevice, Qt from PyQt4.QtGui import QApplication, QFormLayout, QLineEdit, QHBoxLayout, \ QPushButton, QSlider, QVBoxLayout, QWidget from PyQt4.QtMultimedia import QAudio, QAudioDeviceInfo, QAudioFormat, QAudioOutput class Window(QWidget): def __init__(self, parent = None): QWidget.__init__(self, parent) format = QAudioFormat() format.setChannels(1) format.setFrequency(44100) format.setSampleSize(16) format.setCodec("audio/pcm") format.setByteOrder(QAudioFormat.LittleEndian) format.setSampleType(QAudioFormat.SignedInt) self.output = QAudioOutput(QAudioDeviceInfo.availableDevices(QAudio.AudioOutput)[1],format, self) self.frequency = 440 self.volume = 0 self.buffer = QBuffer() self.data = QByteArray() self.deviceLineEdit = QLineEdit() self.deviceLineEdit.setReadOnly(True) self.deviceLineEdit.setText("default") self.pitchSlider = QSlider(Qt.Horizontal) self.pitchSlider.setMaximum(100) self.volumeSlider = QSlider(Qt.Horizontal) self.volumeSlider.setMaximum(32767) self.volumeSlider.setPageStep(1024) self.playButton = QPushButton(self.tr("&Play")) self.pitchSlider.valueChanged.connect(self.changeFrequency) self.volumeSlider.valueChanged.connect(self.changeVolume) self.playButton.clicked.connect(self.play) formLayout = QFormLayout() formLayout.addRow(self.tr("Device:"), self.deviceLineEdit) formLayout.addRow(self.tr("P&itch:"), self.pitchSlider) formLayout.addRow(self.tr("&Volume:"), self.volumeSlider) buttonLayout = QVBoxLayout() buttonLayout.addWidget(self.playButton) buttonLayout.addStretch() horizontalLayout = QHBoxLayout(self) horizontalLayout.addLayout(formLayout) horizontalLayout.addLayout(buttonLayout) def changeFrequency(self, value): self.frequency = 440 + (value * 2) def play(self): if self.output.state() == QAudio.ActiveState: self.output.stop() if self.buffer.isOpen(): self.buffer.close() self.createData() self.buffer.setData(self.data) self.buffer.open(QIODevice.ReadOnly) self.buffer.seek(0) print self.data self.output.start(self.buffer) def changeVolume(self, value): self.volume = value def createData(self): # Create 2 seconds of data with 44100 samples per second, each sample # being 16 bits (2 bytes). self.data.clear() for i in xrange(2 * 44100): t = i / 44100.0 value = int(self.volume * sin(2 * pi * self.frequency * t)) self.data.append(struct.pack("<h", value)) if __name__ == "__main__": app = QApplication(sys.argv) window = Window() window.show() sys.exit(app.exec_())