introducing QxtAudioPlayer
This commit is contained in:
parent
c147c31e72
commit
f5a8801b7d
|
@ -33,6 +33,7 @@ width="32" height="32" border="0" /></a></td>
|
|||
</table>
|
||||
<!-- Generated by Doxygen 1.5.0 -->
|
||||
<h1>QtExtendedLibrary Data Structures</h1>Here are the data structures with brief descriptions:<table>
|
||||
<tr><td class="indexkey"><a class="el" href="classQxtAudioPlayer.html">QxtAudioPlayer</a></td><td class="indexvalue">Simple player using the <a class="el" href="classQxtAVFile.html">QxtAVFile</a> and portaudio </td></tr>
|
||||
<tr><td class="indexkey"><a class="el" href="classQxtAVFile.html">QxtAVFile</a></td><td class="indexvalue">AV decoder </td></tr>
|
||||
<tr><td class="indexkey"><a class="el" href="classQxtBlowFish.html">QxtBlowFish</a></td><td class="indexvalue">Blowfish Encryption Class </td></tr>
|
||||
<tr><td class="indexkey"><a class="el" href="structQxtNull.html">QxtNull</a></td><td class="indexvalue">An object representing the "null" value for <a class="el" href="classQxtNullable.html">QxtNullable</a> </td></tr>
|
||||
|
|
94
doc/classQxtAudioPlayer.html
Normal file
94
doc/classQxtAudioPlayer.html
Normal file
|
@ -0,0 +1,94 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
|
||||
<title>QtExtendedLibrary: QxtAudioPlayer Class Reference</title>
|
||||
<link href="stylesheet.css" rel="stylesheet" type="text/css">
|
||||
<link href="tabs.css" rel="stylesheet" type="text/css">
|
||||
</head><body>
|
||||
|
||||
<table border="0" cellpadding="0" cellspacing="0" width="100%">
|
||||
|
||||
<tr>
|
||||
<td align="left" valign="top" width="32"><a href="http://www.exys.org/qx"><img src="qx.jpg" align="left"
|
||||
width="32" height="32" border="0" /></a></td>
|
||||
|
||||
<td width="1"> </td>
|
||||
|
||||
<td class="postheader" valign="center">
|
||||
|
||||
<a href="index.html"> <font color="#004faf">Home</font></a> ·
|
||||
<a href="annotated.html"> <font color="#004faf">All Classes</font></a> ·
|
||||
<a href="classes.html"> <font color="#004faf">alphabetical Classes List</font></a> ·
|
||||
<a href="modules.html"> <font color="#004faf">Modules</font></a> ·
|
||||
<a href="functions.html"><font color="#004faf">Functions</font></a> ·
|
||||
<a href="building.html"><font color="#004faf">Building</font></a> ·
|
||||
<a href="https://sourceforge.net/project/showfiles.php?group_id=183158"><font color="#004faf">Download Snapshots</font></a>
|
||||
|
||||
|
||||
</td>
|
||||
|
||||
<td align="right" valign="top" width="230"></td></tr>
|
||||
|
||||
|
||||
|
||||
</table>
|
||||
<!-- Generated by Doxygen 1.5.0 -->
|
||||
<h1>QxtAudioPlayer Class Reference<br>
|
||||
<small>
|
||||
[<a class="el" href="group__media.html">Media</a>]</small>
|
||||
</h1><!-- doxytag: class="QxtAudioPlayer" -->simple player using the <a class="el" href="classQxtAVFile.html">QxtAVFile</a> and portaudio
|
||||
<a href="#_details">More...</a>
|
||||
<p>
|
||||
<code>#include <QxtAudioPlayer></code>
|
||||
<p>
|
||||
<table border="0" cellpadding="0" cellspacing="0">
|
||||
<tr><td></td></tr>
|
||||
<tr><td colspan="2"><br><h2>Public Slots</h2></td></tr>
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top">static void </td><td class="memItemRight" valign="bottom"><a class="el" href="classQxtAudioPlayer.html#29a6ab8036a27218930caf460dd28b1a">play</a> (QString url)</td></tr>
|
||||
|
||||
<tr><td colspan="2"><br><h2>Public Member Functions</h2></td></tr>
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="7b74eb59ec3dc3d192257bd9bf664e25"></a><!-- doxytag: member="QxtAudioPlayer::QxtAudioPlayer" ref="7b74eb59ec3dc3d192257bd9bf664e25" args="(QObject *parent=0)" -->
|
||||
</td><td class="memItemRight" valign="bottom"><b>QxtAudioPlayer</b> (QObject *parent=0)</td></tr>
|
||||
|
||||
</table>
|
||||
<hr><a name="_details"></a><h2>Detailed Description</h2>
|
||||
simple player using the <a class="el" href="classQxtAVFile.html">QxtAVFile</a> and portaudio
|
||||
<p>
|
||||
sometimes you just want to play a sound in your application. this is not meant to be a full blown media player and does not provide any functions for it.
|
||||
<p>
|
||||
<hr><h2>Member Function Documentation</h2>
|
||||
<a class="anchor" name="29a6ab8036a27218930caf460dd28b1a"></a><!-- doxytag: member="QxtAudioPlayer::play" ref="29a6ab8036a27218930caf460dd28b1a" args="(QString url)" -->
|
||||
<div class="memitem">
|
||||
<div class="memproto">
|
||||
<table class="memname">
|
||||
<tr>
|
||||
<td class="memname">void QxtAudioPlayer::play </td>
|
||||
<td>(</td>
|
||||
<td class="paramtype">QString </td>
|
||||
<td class="paramname"> <em>url</em> </td>
|
||||
<td> ) </td>
|
||||
<td width="100%"><code> [static, slot]</code></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="memdoc">
|
||||
|
||||
<p>
|
||||
usage:<p>
|
||||
<div class="fragment"><pre class="fragment"> <a class="code" href="classQxtAudioPlayer.html#29a6ab8036a27218930caf460dd28b1a">QxtAudioPlayer::play</a>(<span class="stringliteral">"sound/ding.wav"</span>);
|
||||
</pre></div> obviously you do not need to construct an object<p>
|
||||
calling this slot while another file is playing will interupt the current playback
|
||||
</div>
|
||||
</div><p>
|
||||
<address><hr />
|
||||
|
||||
<div align="center">
|
||||
|
||||
<table width="100%" cellspacing="0" border="0"><tr class="address">
|
||||
<td width="30%">(c) 2007<a href="http://libqxt.sf.net">A.Picciani and A.Higerd</a> LGPL</td>
|
||||
<td width="40%" align="center"></td>
|
||||
<td width="30%" align="right"><div align="right">libqxt 0.2</div></td>
|
||||
</tr></table></div></address></body>
|
||||
|
||||
</html>
|
||||
|
||||
|
|
@ -35,13 +35,13 @@ width="32" height="32" border="0" /></a></td>
|
|||
<h1>QtExtendedLibrary Data Structure Index</h1><p><div class="qindex"><a class="qindex" href="#letter_A">A</a> | <a class="qindex" href="#letter_B">B</a> | <a class="qindex" href="#letter_N">N</a> | <a class="qindex" href="#letter_P">P</a> | <a class="qindex" href="#letter_R">R</a> | <a class="qindex" href="#letter_S">S</a> | <a class="qindex" href="#letter_T">T</a></div><p>
|
||||
<table align="center" width="95%" border="0" cellspacing="0" cellpadding="0">
|
||||
<tr><td><a name="letter_A"></a><table border="0" cellspacing="0" cellpadding="0"><tr><td><div class="ah"> A </div></td></tr></table>
|
||||
</td><td><a class="el" href="structQxtNull.html">QxtNull</a> </td><td><a name="letter_R"></a><table border="0" cellspacing="0" cellpadding="0"><tr><td><div class="ah"> R </div></td></tr></table>
|
||||
</td><td><a class="el" href="classQxtSqlPackage.html">QxtSqlPackage</a> </td><td><a class="el" href="classQxtTreeWidget.html">QxtTreeWidget</a> </td></tr><tr><td><a class="el" href="classQxtAVFile.html">QxtAVFile</a> </td><td><a class="el" href="classQxtNullable.html">QxtNullable</a> </td><td><a class="el" href="classQxtRPCPeer.html">QxtRPCPeer</a> </td><td><a class="el" href="classQxtSqlPackageModel.html">QxtSqlPackageModel</a> </td><td><a class="el" href="classQxtTripple.html">QxtTripple</a> </td></tr><tr><td><a name="letter_B"></a><table border="0" cellspacing="0" cellpadding="0"><tr><td><div class="ah"> B </div></td></tr></table>
|
||||
</td><td><a name="letter_N"></a><table border="0" cellspacing="0" cellpadding="0"><tr><td><div class="ah"> N </div></td></tr></table>
|
||||
</td><td><a class="el" href="classQxtPimpl.html">QxtPimpl</a> </td><td><a class="el" href="classQxtSingleInstance.html">QxtSingleInstance</a> </td><td><a class="el" href="classQxtTreeWidget.html">QxtTreeWidget</a> </td></tr><tr><td><a class="el" href="classQxtAudioPlayer.html">QxtAudioPlayer</a> </td><td><a class="el" href="structQxtNull.html">QxtNull</a> </td><td><a name="letter_R"></a><table border="0" cellspacing="0" cellpadding="0"><tr><td><div class="ah"> R </div></td></tr></table>
|
||||
</td><td><a class="el" href="classQxtSqlPackage.html">QxtSqlPackage</a> </td><td><a class="el" href="classQxtTripple.html">QxtTripple</a> </td></tr><tr><td><a class="el" href="classQxtAVFile.html">QxtAVFile</a> </td><td><a class="el" href="classQxtNullable.html">QxtNullable</a> </td><td><a class="el" href="classQxtRPCPeer.html">QxtRPCPeer</a> </td><td><a class="el" href="classQxtSqlPackageModel.html">QxtSqlPackageModel</a> </td><td><a class="el" href="classQxtTrippleList.html">QxtTrippleList</a> </td></tr><tr><td><a name="letter_B"></a><table border="0" cellspacing="0" cellpadding="0"><tr><td><div class="ah"> B </div></td></tr></table>
|
||||
</td><td><a name="letter_P"></a><table border="0" cellspacing="0" cellpadding="0"><tr><td><div class="ah"> P </div></td></tr></table>
|
||||
</td><td><a name="letter_S"></a><table border="0" cellspacing="0" cellpadding="0"><tr><td><div class="ah"> S </div></td></tr></table>
|
||||
</td><td><a name="letter_T"></a><table border="0" cellspacing="0" cellpadding="0"><tr><td><div class="ah"> T </div></td></tr></table>
|
||||
</td><td><a class="el" href="classQxtTrippleList.html">QxtTrippleList</a> </td></tr><tr><td><a class="el" href="classQxtBlowFish.html">QxtBlowFish</a> </td><td><a class="el" href="classQxtPairList.html">QxtPairList</a> </td><td><a class="el" href="classQxtSignalWaiter.html">QxtSignalWaiter</a> </td><td><a class="el" href="classQxtTabWidget.html">QxtTabWidget</a> </td><td><a class="el" href="classQxtTuple.html">QxtTuple</a> </td></tr><tr><td><a name="letter_N"></a><table border="0" cellspacing="0" cellpadding="0"><tr><td><div class="ah"> N </div></td></tr></table>
|
||||
</td><td><a class="el" href="classQxtPimpl.html">QxtPimpl</a> </td><td><a class="el" href="classQxtSingleInstance.html">QxtSingleInstance</a> </td></tr></table><p><div class="qindex"><a class="qindex" href="#letter_A">A</a> | <a class="qindex" href="#letter_B">B</a> | <a class="qindex" href="#letter_N">N</a> | <a class="qindex" href="#letter_P">P</a> | <a class="qindex" href="#letter_R">R</a> | <a class="qindex" href="#letter_S">S</a> | <a class="qindex" href="#letter_T">T</a></div><p>
|
||||
</td><td><a class="el" href="classQxtTuple.html">QxtTuple</a> </td></tr><tr><td><a class="el" href="classQxtBlowFish.html">QxtBlowFish</a> </td><td><a class="el" href="classQxtPairList.html">QxtPairList</a> </td><td><a class="el" href="classQxtSignalWaiter.html">QxtSignalWaiter</a> </td><td><a class="el" href="classQxtTabWidget.html">QxtTabWidget</a> </td></tr></table><p><div class="qindex"><a class="qindex" href="#letter_A">A</a> | <a class="qindex" href="#letter_B">B</a> | <a class="qindex" href="#letter_N">N</a> | <a class="qindex" href="#letter_P">P</a> | <a class="qindex" href="#letter_R">R</a> | <a class="qindex" href="#letter_S">S</a> | <a class="qindex" href="#letter_T">T</a></div><p>
|
||||
<address><hr />
|
||||
|
||||
<div align="center">
|
||||
|
|
|
@ -160,6 +160,8 @@ Here is a list of all documented struct and union fields with links to the struc
|
|||
: <a class="el" href="classQxtRPCPeer.html#e3fd8e63aceea84eef2a70a8fa50418d">QxtRPCPeer</a>
|
||||
<li>peerError()
|
||||
: <a class="el" href="classQxtRPCPeer.html#cd89d8b304d38cfff4fef3e0c513e1da">QxtRPCPeer</a>
|
||||
<li>play()
|
||||
: <a class="el" href="classQxtAudioPlayer.html#29a6ab8036a27218930caf460dd28b1a">QxtAudioPlayer</a>
|
||||
</ul>
|
||||
<h3><a class="anchor" name="index_q">- q -</a></h3><ul>
|
||||
<li>qMakeTripple
|
||||
|
|
|
@ -158,6 +158,8 @@ width="32" height="32" border="0" /></a></td>
|
|||
: <a class="el" href="classQxtRPCPeer.html#e3fd8e63aceea84eef2a70a8fa50418d">QxtRPCPeer</a>
|
||||
<li>peerError()
|
||||
: <a class="el" href="classQxtRPCPeer.html#cd89d8b304d38cfff4fef3e0c513e1da">QxtRPCPeer</a>
|
||||
<li>play()
|
||||
: <a class="el" href="classQxtAudioPlayer.html#29a6ab8036a27218930caf460dd28b1a">QxtAudioPlayer</a>
|
||||
</ul>
|
||||
<h3><a class="anchor" name="index_q">- q -</a></h3><ul>
|
||||
<li>QxtAVFile()
|
||||
|
|
|
@ -35,6 +35,9 @@ width="32" height="32" border="0" /></a></td>
|
|||
<h1>Media</h1><table border="0" cellpadding="0" cellspacing="0">
|
||||
<tr><td></td></tr>
|
||||
<tr><td colspan="2"><br><h2>Data Structures</h2></td></tr>
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top">class </td><td class="memItemRight" valign="bottom"><a class="el" href="classQxtAudioPlayer.html">QxtAudioPlayer</a></td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </td><td class="mdescRight">simple player using the <a class="el" href="classQxtAVFile.html">QxtAVFile</a> and portaudio <a href="classQxtAudioPlayer.html#_details">More...</a><br></td></tr>
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top">class </td><td class="memItemRight" valign="bottom"><a class="el" href="classQxtAVFile.html">QxtAVFile</a></td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </td><td class="mdescRight">AV decoder. <a href="classQxtAVFile.html#_details">More...</a><br></td></tr>
|
||||
|
|
1
include/media/QxtAudioPlayer
Normal file
1
include/media/QxtAudioPlayer
Normal file
|
@ -0,0 +1 @@
|
|||
#include "QxtAudioPlayer.h"
|
|
@ -53,6 +53,7 @@ QxtAVFile::QxtAVFile(QString filename,int fliplen,QObject *parent):QThread(paren
|
|||
fliplen_m=0;
|
||||
resample_m=0;
|
||||
playbacktime=0.0;
|
||||
eof_f=false;
|
||||
|
||||
/// \bug buffsize must be at least 2048
|
||||
assert(fliplen>=2048);
|
||||
|
@ -110,7 +111,7 @@ QxtAVFile::QxtAVFile(QString filename,int fliplen,QObject *parent):QThread(paren
|
|||
|
||||
QxtAVFile::~QxtAVFile()
|
||||
{
|
||||
|
||||
terminate();
|
||||
//!clean up ffmpeg
|
||||
avcodec_close(codec_context);
|
||||
av_close_input_file(format_context);
|
||||
|
@ -179,6 +180,9 @@ double QxtAVFile::length()
|
|||
//-------------------------------------------------------------
|
||||
int QxtAVFile::flip(float* out)
|
||||
{
|
||||
|
||||
if (eof_f && HF==WF){emit(eof());qWarning("called flip after eof, doing nothing.");return -1;}
|
||||
|
||||
///if we have an xrun try to wait for the buffer
|
||||
while (HF==WF && decoderlock_b != NULL){usleep(10);qWarning("warning: underrun detected, waiting 10 usecs.");}
|
||||
|
||||
|
@ -186,6 +190,7 @@ int QxtAVFile::flip(float* out)
|
|||
{
|
||||
decoderlock_b=OUT2;
|
||||
memcpy(out,OUT1,fliplen_m*sizeof(float));
|
||||
|
||||
WF=false;
|
||||
}
|
||||
else
|
||||
|
@ -227,7 +232,7 @@ int QxtAVFile::getFrame(float * out)
|
|||
forever
|
||||
{
|
||||
/// read a packet
|
||||
if (av_read_frame(format_context, &pkt)<0){emit(eof());return -1;}
|
||||
if (av_read_frame(format_context, &pkt)<0){return -1;}
|
||||
|
||||
//!skip packages that don't belong to the wanted stream
|
||||
if (pkt.stream_index==AudioStreamIndex)break;
|
||||
|
@ -288,6 +293,7 @@ void QxtAVFile::run()
|
|||
HF=(decoderlock_b==OUT2);
|
||||
refill(decoderlock_b);
|
||||
decoderlock_b=NULL;
|
||||
if (eof_f)return;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -310,8 +316,14 @@ void QxtAVFile::refill(float * WRITE)
|
|||
while(resampler.numSamples()<fliplen_m+1)
|
||||
{
|
||||
DSRC_LEN=getFrame(DSRC);
|
||||
if(DSRC_LEN<0)
|
||||
{
|
||||
resampler.flush();
|
||||
break;
|
||||
}
|
||||
|
||||
resampler.putSamples(DSRC,DSRC_LEN/2);
|
||||
|
||||
assert((unsigned)DSRC_LEN<=fliplen_m*4);
|
||||
}
|
||||
assert(resampler.receiveSamples(WRITE,fliplen_m/2)==fliplen_m/2);
|
||||
return;
|
||||
|
@ -335,9 +347,19 @@ void QxtAVFile::refill(float * WRITE)
|
|||
DSRC_LEN=getFrame(DSRC);
|
||||
}
|
||||
|
||||
///beg it doesn't exploede
|
||||
assert((unsigned)DSRC_LEN<=fliplen_m*4);
|
||||
|
||||
if(DSRC_LEN<0)
|
||||
{
|
||||
for (int i=0;i<write;i++)
|
||||
*out++=0.0f;
|
||||
eof_f=true;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
///if something went wrong, we return 0
|
||||
assert((unsigned)DSRC_LEN<=fliplen_m*4);
|
||||
|
||||
///get as much data as avilable but not more then requested
|
||||
int l= qMin(DSRC_LEN,(long)write);
|
||||
///push
|
||||
|
|
|
@ -80,7 +80,6 @@ class QxtAVFile : public QThread
|
|||
signals:
|
||||
/**
|
||||
End of File Signal.
|
||||
There is still data available in the pipe, this is just to inform you the file has been fully read
|
||||
*/
|
||||
void eof();
|
||||
|
||||
|
@ -129,6 +128,9 @@ class QxtAVFile : public QThread
|
|||
///playbacktime
|
||||
double playbacktime;
|
||||
|
||||
///indicate that the next buffer is the last
|
||||
bool eof_f;///flip
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
153
src/media/QxtAudioPlayer.cpp
Normal file
153
src/media/QxtAudioPlayer.cpp
Normal file
|
@ -0,0 +1,153 @@
|
|||
/*******************************************************************
|
||||
Qt extended Library
|
||||
Copyright (C) 2006 Arvid Picciani
|
||||
released under the Terms of LGPL (see the LICENSE file)
|
||||
*******************************************************************/
|
||||
#include "QxtAudioPlayer.h"
|
||||
#include <portaudio.h>
|
||||
#include <QCoreApplication>
|
||||
#include <QxtAVFile.h>
|
||||
|
||||
#define FRAMES_PER_BUFFER 1024
|
||||
|
||||
|
||||
static QxtAVFile * avfile=NULL;
|
||||
|
||||
|
||||
/*!
|
||||
Portaudio will decide itself when to call this function. it expects to get 'frames' numbers of frames * channels to be pushed to out. interleaved
|
||||
This function allowes us to pass around a pointer to any object we like. we'll store our object pointer in it
|
||||
*/
|
||||
static int PortaudioCallback(const void *, void *outputBuffer,unsigned long framerate,const PaStreamCallbackTimeInfo* ,PaStreamCallbackFlags ,void * )
|
||||
{
|
||||
///prepare the buffer
|
||||
float *out = (float*)outputBuffer;
|
||||
|
||||
///if there is no avfile we will pass silence
|
||||
if (!avfile)
|
||||
{
|
||||
for (unsigned long i=0;i<framerate;i++)
|
||||
*out++=0.0f;
|
||||
return paContinue;
|
||||
}
|
||||
|
||||
///flip the data to portaudios callback buffer
|
||||
avfile->flip(out);
|
||||
|
||||
return paContinue;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class AUDIOOUT
|
||||
{
|
||||
public:
|
||||
AUDIOOUT()
|
||||
{
|
||||
///init portaudio
|
||||
Q_ASSERT(Pa_Initialize()==paNoError);
|
||||
|
||||
/// make sure the default audio out is available.for the sake of simplicity we do not check for other outputs then oss on unix
|
||||
Q_ASSERT(Pa_GetDeviceInfo( Pa_GetDefaultOutputDevice()));
|
||||
|
||||
///open the default stream
|
||||
Q_ASSERT(Pa_OpenDefaultStream (
|
||||
&stream,
|
||||
0, ///no input channels
|
||||
2, ///stereo output
|
||||
paFloat32, ///32 bit floating output
|
||||
Pa_GetDeviceInfo( Pa_GetDefaultOutputDevice() )->defaultSampleRate,
|
||||
FRAMES_PER_BUFFER,
|
||||
PortaudioCallback,
|
||||
&avfile
|
||||
)==paNoError);
|
||||
|
||||
///start playback
|
||||
Q_ASSERT(Pa_StartStream( stream )==paNoError);
|
||||
}
|
||||
|
||||
~AUDIOOUT()
|
||||
{
|
||||
///cleanup
|
||||
Pa_StopStream( stream );
|
||||
Pa_CloseStream( stream );
|
||||
Pa_Terminate();
|
||||
}
|
||||
|
||||
PaStream *stream;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
static AUDIOOUT * audiout=NULL;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static QxtAudioPlayerStaticEofObjectHolder * eofo=NULL;
|
||||
|
||||
|
||||
|
||||
|
||||
QxtAudioPlayer::QxtAudioPlayer(QObject * parent):QObject(parent){}
|
||||
|
||||
|
||||
void QxtAudioPlayer::play(QString url)
|
||||
{
|
||||
if (!eofo)
|
||||
eofo=new QxtAudioPlayerStaticEofObjectHolder();
|
||||
|
||||
|
||||
if (!audiout)
|
||||
audiout = new AUDIOOUT();
|
||||
|
||||
if (avfile)
|
||||
{
|
||||
///set null before delete to avoid crash of callback
|
||||
QxtAVFile * B=avfile;
|
||||
avfile=NULL;
|
||||
delete (B);
|
||||
}
|
||||
|
||||
///intialise QxtAVFile. take care of the *2 QxtAVFile wants the amount of samples to push whereas portaudio means the amount per channel
|
||||
avfile = new QxtAVFile(url,FRAMES_PER_BUFFER*2);
|
||||
|
||||
connect(avfile,SIGNAL(eof()),eofo,SLOT(f__eof()));
|
||||
|
||||
|
||||
///tell avfile to resample its output to the soundcards samplerate
|
||||
avfile->resample((int)Pa_GetDeviceInfo( Pa_GetDefaultOutputDevice() )->defaultSampleRate);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void QxtAudioPlayerStaticEofObjectHolder::f__eof()
|
||||
{
|
||||
Pa_StopStream(audiout->stream );
|
||||
QxtAVFile * B=avfile;
|
||||
avfile=NULL;
|
||||
if (B) delete (B);
|
||||
}
|
||||
|
||||
|
||||
void QxtAudioPlayer::close()
|
||||
{
|
||||
if (audiout) delete(audiout);
|
||||
if (avfile) delete(avfile);
|
||||
}
|
||||
|
||||
|
||||
|
||||
QxtAudioPlayer::~QxtAudioPlayer()
|
||||
{
|
||||
if (eofo) delete(eofo);
|
||||
if (audiout) delete(audiout);
|
||||
if (avfile) delete(avfile);
|
||||
}
|
65
src/media/QxtAudioPlayer.h
Normal file
65
src/media/QxtAudioPlayer.h
Normal file
|
@ -0,0 +1,65 @@
|
|||
/*******************************************************************
|
||||
Qt extended Library
|
||||
Copyright (C) 2006 Arvid Picciani
|
||||
released under the Terms of LGPL (see the LICENSE file)
|
||||
*******************************************************************/
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
|
||||
|
||||
/**
|
||||
\class QxtAudioPlayer QxtAudioPlayer
|
||||
|
||||
\ingroup media
|
||||
|
||||
\brief simple player using the QxtAVFile and portaudio
|
||||
|
||||
sometimes you just want to play a sound in your application.
|
||||
this is not meant to be a full blown media player and does not provide any functions for it.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
class QxtAudioPlayerStaticEofObjectHolder: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public slots:
|
||||
void f__eof();
|
||||
};
|
||||
|
||||
|
||||
|
||||
class QxtAudioPlayer : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QxtAudioPlayer(QObject * parent =0);
|
||||
~QxtAudioPlayer();
|
||||
|
||||
public slots:
|
||||
|
||||
/**
|
||||
usage:
|
||||
|
||||
\code
|
||||
QxtAudioPlayer::play("sound/ding.wav");
|
||||
\endcode
|
||||
obviously you do not need to construct an object
|
||||
|
||||
calling this slot while another file is playing will interupt the current playback
|
||||
*/
|
||||
|
||||
static void play(QString url);
|
||||
|
||||
|
||||
/**
|
||||
if you do not need sound a longer time, you should close the sound out.
|
||||
It will automaticly be reopened the next play();
|
||||
*/
|
||||
static void close();
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -11,18 +11,23 @@ QT = core gui
|
|||
|
||||
|
||||
QXT_MEDIA += QxtAVFile
|
||||
QXT_HEADERS_QxtAVFile = QxtAVFile.h
|
||||
QXT_SOURCES_QxtAVFile = QxtAVFile.cpp
|
||||
QXT_STABILITY_QxtAVFile = +linux-g++
|
||||
QXT_HEADERS_QxtAVFile = QxtAVFile.h
|
||||
QXT_SOURCES_QxtAVFile = QxtAVFile.cpp
|
||||
QXT_STABILITY_QxtAVFile = +linux-g++
|
||||
|
||||
|
||||
QXT_MEDIA += QxtSdlWidget
|
||||
QXT_HEADERS_QxtSdlWidget = QxtSdlWidget.h
|
||||
QXT_SOURCES_QxtSdlWidget = QxtSdlWidget.cpp
|
||||
QXT_STABILITY_QxtSdlWidgt = +linux-g++
|
||||
|
||||
QXT_HEADERS_QxtSdlWidget = QxtSdlWidget.h
|
||||
QXT_SOURCES_QxtSdlWidget = QxtSdlWidget.cpp
|
||||
QXT_STABILITY_QxtSdlWidgt = +linux-g++
|
||||
|
||||
QXT_MEDIA += QxtAudioPlayer
|
||||
QXT_HEADERS_QxtAudioPlayer = QxtAudioPlayer.h
|
||||
QXT_SOURCES_QxtAudioPlayer = QxtAudioPlayer.cpp
|
||||
QXT_STABILITY_QxtAudioPlayer =
|
||||
|
||||
|
||||
LIBS+= -lavcodec -lavformat -lportaudio -lSoundTouch -lSDL
|
||||
|
||||
include (../parts.pri)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user