Reply
Thread Tools
Posts: 20 | Thanked: 11 times | Joined on Feb 2010
#1
Hi to all,

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!

Code:
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_())
 
Posts: 6 | Thanked: 3 times | Joined on May 2010
#2
Originally Posted by saveas View 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?
It worked fine for me on a Kubuntu setup. Does the code actually crash on that line or on the line with the print statement just before it?
 
Posts: 20 | Thanked: 11 times | Joined on Feb 2010
#3
Yeah, on every other platform I tested it, it works normally.
On maemo, it crashes on that line, not on the "print self.data" statement.

 
Posts: 3,319 | Thanked: 5,610 times | Joined on Aug 2008 @ Finland
#4
QtMultimedia is AFAIK somewhat of an uncharted territory, both Qt and PyQt-wise. You might need to play around with some settings (48000 for freq, check with different codecs, byteorder, that sort of stuff). It would be best if you could check a C++ equivalent if you think that PyQt is at fault (or, easier - simply try PySide for comparison).
__________________
Blogging about mobile linux - The Penguin Moves!
Maintainer of PyQt (see introduction and docs), AppWatch, QuickBrownFox, etc
 
Posts: 20 | Thanked: 11 times | Joined on Feb 2010
#5
I tried PySide and it also produces the same error.
The Qt C++ equivalent example here http://doc.qt.nokia.com/stable/multi...utput-cpp.html works normally (ok it is not perfect equivalent, but it has the same logic).
I will try to play with the settings Attila suggested.
Thanks all for your replies!
 

The Following User Says Thank You to saveas For This Useful Post:
Reply


 
Forum Jump


All times are GMT. The time now is 09:51.