I want to develop an audio editor using Qt. For this, I need to plot a waveform开发者_Python百科 of the music track which I think should be a plot of peak amplitude of sound versus time(please correct me if I am wrong).
Currently, I have been using Phonon::AudioOutput class object as an audio sink and connected it with my Phonon::MediaObject class object to play the audio file.
Now, to draw the waveform I need to know the amplitude of audio track at every second (,or so) from this AudioOutput object so that I can draw a line (using QPainter) of length proportional to sound frequency at different times and hence, obtain my waveform.
So, please help me on how to obtain amplitude of audio tracks at different times.
Secondly,am I using the correct way of plotting waveforms of audio tracks - plotting amplitudes of sound against time by plotting lines by QPainter object on a widget at different times.
Thanks.
There is code which does both of the things you ask about (calculating peak amplitude, and plotting audio waveforms) in the Spectrum Analyzer example which ships with Qt (in the demos/spectrum directory).
Screenshot of Spectrum Analyzer demo running on Symbian http://labs.trolltech.com/blogs/wp-content/uploads/2010/05/spectrum.png
This demo also calculates and displays a frequency spectrum. As another commenter points out, this is distinct from a waveform plot: the spectrum is a plot of amplitude against frequency, whereas the waveform plots amplitude against time.
The demo uses QtMultimedia rather than Phonon to capture and render audio. If you are only interested in playing audio, and don't need to record it, Phonon may be sufficient, but be aware that streaming support (i.e. Phonon::MediaSource(QIODevice *)
) is not available on all platforms. QAudioInput
and QAudioOutput
on the other hand are well supported, at least for PCM audio data, on all the main platform targetted by Qt.
精彩评论