mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-24 17:59:42 +01:00
Merge remote branch 'origin/master' into single-file-cache
This commit is contained in:
commit
a8253c4abd
@ -93,11 +93,6 @@ ENDIF( WIN32 )
|
||||
|
||||
#show dep log
|
||||
macro_display_feature_log()
|
||||
MESSAGE("WARNING!")
|
||||
MESSAGE("Phonon is going to replace our own audio abstraction layer soon so we didn't")
|
||||
MESSAGE("add checks for libmad, libvorbis and libflac. Make sure they are installed!")
|
||||
MESSAGE("")
|
||||
MESSAGE("-----------------------------------------------------------------------------")
|
||||
|
||||
SET( INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" )
|
||||
|
||||
|
5
README
5
README
@ -31,15 +31,10 @@ Dependencies
|
||||
TagLib 1.6.2 http://developer.kde.org/~wheeler/taglib.html
|
||||
Boost 1.3x http://www.boost.org/
|
||||
CLucene 0.9.23 (0.9.21 will fail) http://clucene.sourceforge.net/download.shtml
|
||||
libmad 0.15.1b http://www.underbit.com/products/mad/
|
||||
libvorbis 1.2.3 http://xiph.org/vorbis/
|
||||
libogg 1.1.4 http://xiph.org/ogg/
|
||||
libflac++ 1.2.0 http://flac.sourceforge.net/
|
||||
libechonest 1.1.4 http://projects.kde.org/projects/playground/libs/libechonest/
|
||||
|
||||
Third party libraries that we ship with our source:
|
||||
|
||||
RtAudio 4.0.7 http://www.music.mcgill.ca/~gary/rtaudio/
|
||||
MiniUPnP http://miniupnp.free.fr/
|
||||
liblastfm 0.4.0 http://github.com/jonocole/liblastfm/
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
SET( OS_SPECIFIC_LINK_LIBRARIES
|
||||
${OS_SPECIFIC_LINK_LIBRARIES}
|
||||
alsaplayback
|
||||
tomahawklib
|
||||
)
|
||||
|
||||
|
@ -10,8 +10,6 @@ SET( OS_SPECIFIC_LINK_LIBRARIES
|
||||
/System/Library/Frameworks/DiskArbitration.framework
|
||||
/System/Library/Frameworks/Foundation.framework
|
||||
/System/Library/Frameworks/IOKit.framework
|
||||
|
||||
rtaudio
|
||||
)
|
||||
|
||||
|
||||
|
@ -7,6 +7,7 @@ ENDIF()
|
||||
SET( QT_USE_QTSQL TRUE )
|
||||
SET( QT_USE_QTNETWORK TRUE )
|
||||
SET( QT_USE_QTXML TRUE )
|
||||
SET( QT_USE_PHONON TRUE )
|
||||
SET( QT_USE_QTWEBKIT TRUE )
|
||||
|
||||
INCLUDE( ${QT_USE_FILE} )
|
||||
@ -129,8 +130,6 @@ INCLUDE_DIRECTORIES(
|
||||
libtomahawk
|
||||
mac
|
||||
|
||||
${THIRDPARTY_DIR}/alsa-playback
|
||||
${THIRDPARTY_DIR}/rtaudio
|
||||
${THIRDPARTY_DIR}/qxt/qxtweb-standalone/qxtweb
|
||||
${THIRDPARTY_DIR}/qtweetlib/qtweetlib/src
|
||||
${THIRDPARTY_DIR}/qtweetlib/tomahawk-custom
|
||||
|
@ -15,7 +15,6 @@ SET( OS_SPECIFIC_LINK_LIBRARIES
|
||||
${QTSPARKLE_LIBRARIES}
|
||||
|
||||
# third party shipped with tomahawk
|
||||
${CMAKE_BINARY_DIR}/thirdparty/rtaudio/librtaudio.dll
|
||||
|
||||
# system libs
|
||||
"secur32.dll"
|
||||
|
@ -159,7 +159,7 @@ AudioControls::AudioControls( QWidget* parent )
|
||||
connect( AudioEngine::instance(), SIGNAL( paused() ), SLOT( onPlaybackPaused() ) );
|
||||
connect( AudioEngine::instance(), SIGNAL( resumed() ), SLOT( onPlaybackResumed() ) );
|
||||
connect( AudioEngine::instance(), SIGNAL( stopped() ), SLOT( onPlaybackStopped() ) );
|
||||
connect( AudioEngine::instance(), SIGNAL( timerSeconds( unsigned int ) ), SLOT( onPlaybackTimer( unsigned int ) ) );
|
||||
connect( AudioEngine::instance(), SIGNAL( timerMilliSeconds( qint64 ) ), SLOT( onPlaybackTimer( qint64 ) ) );
|
||||
connect( AudioEngine::instance(), SIGNAL( volumeChanged( int ) ), SLOT( onVolumeChanged( int ) ) );
|
||||
|
||||
m_defaultCover = QPixmap( RESPATH "images/no-album-art-placeholder.png" )
|
||||
@ -289,7 +289,7 @@ AudioControls::onPlaybackLoading( const Tomahawk::result_ptr& result )
|
||||
if ( ui->timeLeftLabel->text().isEmpty() )
|
||||
ui->timeLeftLabel->setText( "-" + TomahawkUtils::timeToString( result->duration() ) );
|
||||
|
||||
ui->seekSlider->setRange( 0, m_currentTrack->duration() );
|
||||
ui->seekSlider->setRange( 0, m_currentTrack->duration() * 1000 );
|
||||
ui->seekSlider->setVisible( true );
|
||||
|
||||
/* m_playAction->setEnabled( false );
|
||||
@ -352,14 +352,15 @@ AudioControls::onPlaybackStopped()
|
||||
|
||||
|
||||
void
|
||||
AudioControls::onPlaybackTimer( unsigned int seconds )
|
||||
AudioControls::onPlaybackTimer( qint64 msElapsed )
|
||||
{
|
||||
if ( m_currentTrack.isNull() )
|
||||
return;
|
||||
|
||||
const int seconds = msElapsed / 1000;
|
||||
ui->timeLabel->setText( TomahawkUtils::timeToString( seconds ) );
|
||||
ui->timeLeftLabel->setText( "-" + TomahawkUtils::timeToString( m_currentTrack->duration() - seconds ) );
|
||||
ui->seekSlider->setValue( seconds );
|
||||
ui->seekSlider->setValue( msElapsed );
|
||||
}
|
||||
|
||||
|
||||
|
@ -56,7 +56,7 @@ private slots:
|
||||
void onPlaybackResumed();
|
||||
void onPlaybackStopped();
|
||||
|
||||
void onPlaybackTimer( unsigned int seconds );
|
||||
void onPlaybackTimer( qint64 msElapsed );
|
||||
void onVolumeChanged( int volume );
|
||||
|
||||
void onRepeatClicked();
|
||||
|
@ -4,7 +4,8 @@ SET( QT_USE_QTGUI TRUE )
|
||||
SET( QT_USE_QTSQL TRUE )
|
||||
SET( QT_USE_QTNETWORK TRUE )
|
||||
SET( QT_USE_QTXML TRUE )
|
||||
SET(QT_USE_QTUITOOLS TRUE)
|
||||
SET( QT_USE_PHONON TRUE )
|
||||
SET( QT_USE_QTUITOOLS TRUE )
|
||||
|
||||
include( ${QT_USE_FILE} )
|
||||
|
||||
@ -31,10 +32,6 @@ set( libSources
|
||||
sip/SipPlugin.cpp
|
||||
sip/SipHandler.cpp
|
||||
|
||||
audio/madtranscode.cpp
|
||||
audio/dummytranscode.cpp
|
||||
audio/vorbistranscode.cpp
|
||||
audio/flactranscode.cpp
|
||||
audio/audioengine.cpp
|
||||
|
||||
database/database.cpp
|
||||
@ -190,11 +187,6 @@ set( libHeaders
|
||||
sip/SipPlugin.h
|
||||
sip/SipHandler.h
|
||||
|
||||
audio/transcodeinterface.h
|
||||
audio/madtranscode.h
|
||||
audio/dummytranscode.h
|
||||
audio/vorbistranscode.h
|
||||
audio/flactranscode.h
|
||||
audio/audioengine.h
|
||||
|
||||
database/database.h
|
||||
@ -353,8 +345,6 @@ include_directories( . ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/.
|
||||
|
||||
${THIRDPARTY_DIR}/libportfwd/include
|
||||
${THIRDPARTY_DIR}/qxt/qxtweb-standalone/qxtweb
|
||||
${THIRDPARTY_DIR}/rtaudio
|
||||
${THIRDPARTY_DIR}/alsa-playback
|
||||
${THIRDPARTY_DIR}/jdns
|
||||
${THIRDPARTY_DIR}/jdns/jdns
|
||||
${THIRDPARTY_DIR}/jdns/jdnsshared
|
||||
@ -364,13 +354,9 @@ include_directories( . ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/.
|
||||
|
||||
|
||||
IF( WIN32 )
|
||||
SET( libSources ${libSources} audio/rtaudiooutput.cpp )
|
||||
SET( libHeaders ${libHeaders} audio/rtaudiooutput.h )
|
||||
|
||||
SET( OS_SPECIFIC_LINK_LIBRARIES
|
||||
${OS_SPECIFIC_LINK_LIBRARIES}
|
||||
# Thirdparty
|
||||
${CMAKE_BINARY_DIR}/thirdparty/rtaudio/librtaudio.dll
|
||||
${QJSON_LDFLAGS}
|
||||
# System
|
||||
"iphlpapi.a"
|
||||
@ -387,14 +373,10 @@ IF( APPLE )
|
||||
FIND_LIBRARY( COREFOUNDATION_LIBRARY CoreFoundation )
|
||||
MARK_AS_ADVANCED( COREAUDIO_LIBRARY COREFOUNDATION_LIBRARY )
|
||||
|
||||
SET( libSources ${libSources} audio/rtaudiooutput.cpp )
|
||||
SET( libHeaders ${libHeaders} audio/rtaudiooutput.h )
|
||||
|
||||
SET( OS_SPECIFIC_LINK_LIBRARIES
|
||||
${OS_SPECIFIC_LINK_LIBRARIES}
|
||||
# Thirdparty
|
||||
${QJSON_LIBRARIES}
|
||||
rtaudio
|
||||
# System
|
||||
${COREAUDIO_LIBRARY}
|
||||
${COREFOUNDATION_LIBRARY}
|
||||
@ -405,7 +387,6 @@ IF( UNIX AND NOT APPLE )
|
||||
SET( OS_SPECIFIC_LINK_LIBRARIES
|
||||
${OS_SPECIFIC_LINK_LIBRARIES}
|
||||
# Thirdparty
|
||||
alsaplayback
|
||||
${QJSON_LDFLAGS}
|
||||
)
|
||||
ENDIF( UNIX AND NOT APPLE )
|
||||
@ -429,12 +410,6 @@ target_link_libraries( tomahawklib
|
||||
# Thirdparty shipped with tomahawk
|
||||
portfwd
|
||||
|
||||
# soon to be removed by phonon-dependency
|
||||
FLAC++
|
||||
ogg
|
||||
vorbisfile
|
||||
mad
|
||||
|
||||
# External deps
|
||||
${TAGLIB_LIBRARIES}
|
||||
${CLUCENE_LIBRARIES}
|
||||
|
@ -19,7 +19,6 @@
|
||||
#include "audioengine.h"
|
||||
|
||||
#include <QUrl>
|
||||
#include <QMutexLocker>
|
||||
|
||||
#include "playlistinterface.h"
|
||||
|
||||
@ -27,15 +26,6 @@
|
||||
#include "database/databasecommand_logplayback.h"
|
||||
#include "network/servent.h"
|
||||
|
||||
#include "madtranscode.h"
|
||||
#include "dummytranscode.h"
|
||||
#ifndef NO_OGG
|
||||
#include "vorbistranscode.h"
|
||||
#endif
|
||||
#ifndef NO_FLAC
|
||||
#include "flactranscode.h"
|
||||
#endif
|
||||
|
||||
AudioEngine* AudioEngine::s_instance = 0;
|
||||
|
||||
|
||||
@ -47,49 +37,46 @@ AudioEngine::instance()
|
||||
|
||||
|
||||
AudioEngine::AudioEngine()
|
||||
: QThread()
|
||||
: QObject()
|
||||
, m_playlist( 0 )
|
||||
, m_currentTrackPlaylist( 0 )
|
||||
, m_queue( 0 )
|
||||
, m_timeElapsed( 0 )
|
||||
, m_i( 0 )
|
||||
, m_expectStop( false )
|
||||
{
|
||||
s_instance = this;
|
||||
qDebug() << "Init AudioEngine";
|
||||
|
||||
moveToThread( this );
|
||||
qRegisterMetaType< AudioErrorCode >("AudioErrorCode");
|
||||
|
||||
#ifdef Q_WS_X11
|
||||
m_audio = new AlsaPlayback();
|
||||
#else
|
||||
m_audio = new RTAudioOutput();
|
||||
#endif
|
||||
connect( m_audio, SIGNAL( timeElapsed( unsigned int ) ), SLOT( timerTriggered( unsigned int ) ), Qt::DirectConnection );
|
||||
m_mediaObject = new Phonon::MediaObject( this );
|
||||
m_audioOutput = new Phonon::AudioOutput( Phonon::MusicCategory, this );
|
||||
Phonon::createPath( m_mediaObject, m_audioOutput );
|
||||
|
||||
start();
|
||||
m_mediaObject->setTickInterval( 150 );
|
||||
connect( m_mediaObject, SIGNAL( stateChanged( Phonon::State, Phonon::State ) ), SLOT( onStateChanged( Phonon::State, Phonon::State ) ) );
|
||||
connect( m_mediaObject, SIGNAL( tick( qint64 ) ), SLOT( timerTriggered( qint64 ) ) );
|
||||
}
|
||||
|
||||
|
||||
AudioEngine::~AudioEngine()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << "waiting for event loop to finish...";
|
||||
quit();
|
||||
wait( 1000 );
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
|
||||
m_input.clear();
|
||||
delete m_audio;
|
||||
stop();
|
||||
|
||||
delete m_audioOutput;
|
||||
delete m_mediaObject;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AudioEngine::playPause()
|
||||
{
|
||||
if( m_audio->isPlaying() )
|
||||
if ( isPlaying() )
|
||||
pause();
|
||||
else
|
||||
play();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -98,10 +85,9 @@ AudioEngine::play()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
|
||||
if ( m_audio->isPaused() )
|
||||
if ( isPaused() )
|
||||
{
|
||||
QMutexLocker lock( &m_mutex );
|
||||
m_audio->resume();
|
||||
m_mediaObject->play();
|
||||
emit resumed();
|
||||
}
|
||||
else
|
||||
@ -113,9 +99,8 @@ void
|
||||
AudioEngine::pause()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
QMutexLocker lock( &m_mutex );
|
||||
|
||||
m_audio->pause();
|
||||
m_mediaObject->pause();
|
||||
emit paused();
|
||||
}
|
||||
|
||||
@ -124,7 +109,9 @@ void
|
||||
AudioEngine::stop()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
QMutexLocker lock( &m_mutex );
|
||||
|
||||
m_expectStop = true;
|
||||
m_mediaObject->stop();
|
||||
|
||||
if ( !m_input.isNull() )
|
||||
{
|
||||
@ -132,11 +119,6 @@ AudioEngine::stop()
|
||||
m_input.clear();
|
||||
}
|
||||
|
||||
if ( !m_transcode.isNull() )
|
||||
m_transcode->clearBuffers();
|
||||
|
||||
m_audio->stopPlayback();
|
||||
|
||||
setCurrentTrack( Tomahawk::result_ptr() );
|
||||
emit stopped();
|
||||
}
|
||||
@ -146,7 +128,6 @@ void
|
||||
AudioEngine::previous()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
clearBuffers();
|
||||
loadPreviousTrack();
|
||||
}
|
||||
|
||||
@ -155,7 +136,6 @@ void
|
||||
AudioEngine::next()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
clearBuffers();
|
||||
loadNextTrack();
|
||||
}
|
||||
|
||||
@ -166,8 +146,7 @@ AudioEngine::setVolume( int percentage )
|
||||
//qDebug() << Q_FUNC_INFO;
|
||||
|
||||
percentage = qBound( 0, percentage, 100 );
|
||||
|
||||
m_audio->setVolume( percentage );
|
||||
m_audioOutput->setVolume( (qreal)percentage / 100.0 );
|
||||
emit volumeChanged( percentage );
|
||||
}
|
||||
|
||||
@ -180,13 +159,9 @@ AudioEngine::mute()
|
||||
|
||||
|
||||
void
|
||||
AudioEngine::onTrackAboutToClose()
|
||||
AudioEngine::onTrackAboutToFinish()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
// the only way the iodev we are reading from closes itself, is if
|
||||
// there was a failure, usually network went away.
|
||||
// but we might as well play the remaining data we received
|
||||
// stop();
|
||||
}
|
||||
|
||||
|
||||
@ -196,9 +171,7 @@ AudioEngine::loadTrack( const Tomahawk::result_ptr& result )
|
||||
qDebug() << Q_FUNC_INFO << thread() << result;
|
||||
bool err = false;
|
||||
|
||||
// in a separate scope due to the QMutexLocker!
|
||||
{
|
||||
QMutexLocker lock( &m_mutex );
|
||||
QSharedPointer<QIODevice> io;
|
||||
|
||||
if ( result.isNull() )
|
||||
@ -207,21 +180,12 @@ AudioEngine::loadTrack( const Tomahawk::result_ptr& result )
|
||||
{
|
||||
setCurrentTrack( result );
|
||||
io = Servent::instance()->getIODeviceForUrl( m_currentTrack );
|
||||
if ( m_currentTrack->url().startsWith( "http://" ) )
|
||||
{
|
||||
m_readReady = false;
|
||||
connect( io.data(), SIGNAL( downloadProgress( qint64, qint64 ) ), SLOT( onDownloadProgress( qint64, qint64 ) ) );
|
||||
}
|
||||
else
|
||||
m_readReady = true;
|
||||
|
||||
if ( !io || io.isNull() )
|
||||
{
|
||||
qDebug() << "Error getting iodevice for item";
|
||||
err = true;
|
||||
}
|
||||
else
|
||||
connect( io.data(), SIGNAL( aboutToClose() ), SLOT( onTrackAboutToClose() ), Qt::DirectConnection );
|
||||
}
|
||||
|
||||
if ( !err )
|
||||
@ -229,56 +193,35 @@ AudioEngine::loadTrack( const Tomahawk::result_ptr& result )
|
||||
qDebug() << "Starting new song from url:" << m_currentTrack->url();
|
||||
emit loading( m_currentTrack );
|
||||
|
||||
qDebug() << "input is:" << m_input.isNull();
|
||||
if ( !m_input.isNull() )
|
||||
{
|
||||
m_input->close();
|
||||
m_input.clear();
|
||||
m_expectStop = true;
|
||||
}
|
||||
|
||||
if( !m_lastTrack.isNull() ) qDebug() << "LAST TRACK:" << m_lastTrack->mimetype();
|
||||
qDebug() << "LOADING SONG:" << m_currentTrack->mimetype();
|
||||
if ( m_lastTrack.isNull() || ( m_currentTrack->mimetype() != m_lastTrack->mimetype() ) )
|
||||
m_input = io;
|
||||
|
||||
if ( !m_currentTrack->url().startsWith( "http://" ) )
|
||||
{
|
||||
if ( !m_transcode.isNull() )
|
||||
{
|
||||
m_transcode.clear();
|
||||
}
|
||||
|
||||
if ( m_currentTrack->mimetype() == "audio/basic" )
|
||||
{
|
||||
m_transcode = QSharedPointer<TranscodeInterface>(new DummyTranscode());
|
||||
} else if ( m_currentTrack->mimetype() == "audio/mpeg" )
|
||||
{
|
||||
m_transcode = QSharedPointer<TranscodeInterface>(new MADTranscode());
|
||||
}
|
||||
#ifndef NO_OGG
|
||||
else if ( m_currentTrack->mimetype() == "application/ogg" )
|
||||
{
|
||||
m_transcode = QSharedPointer<TranscodeInterface>(new VorbisTranscode());
|
||||
}
|
||||
#endif
|
||||
#ifndef NO_FLAC
|
||||
else if ( m_currentTrack->mimetype() == "audio/flac" )
|
||||
{
|
||||
m_transcode = QSharedPointer<TranscodeInterface>(new FLACTranscode());
|
||||
}
|
||||
#endif
|
||||
else
|
||||
qDebug() << "Could NOT find suitable transcoder! Stopping audio.";
|
||||
|
||||
if ( !m_transcode.isNull() )
|
||||
connect( m_transcode.data(), SIGNAL( streamInitialized( long, int ) ), SLOT( setStreamData( long, int ) ), Qt::DirectConnection );
|
||||
m_mediaObject->setCurrentSource( io.data() );
|
||||
}
|
||||
|
||||
if ( !m_transcode.isNull() )
|
||||
else
|
||||
{
|
||||
m_transcode->clearBuffers();
|
||||
m_input = io;
|
||||
|
||||
if ( m_audio->isPaused() )
|
||||
m_audio->resume();
|
||||
QUrl furl = m_currentTrack->url();
|
||||
if ( m_currentTrack->url().contains( "?" ) )
|
||||
{
|
||||
furl = QUrl( m_currentTrack->url().left( m_currentTrack->url().indexOf( '?' ) ) );
|
||||
furl.setEncodedQuery( QString( m_currentTrack->url().mid( m_currentTrack->url().indexOf( '?' ) + 1 ) ).toLocal8Bit() );
|
||||
qDebug() << Q_FUNC_INFO << furl;
|
||||
}
|
||||
m_mediaObject->setCurrentSource( furl );
|
||||
}
|
||||
m_mediaObject->currentSource().setAutoDelete( true );
|
||||
m_mediaObject->play();
|
||||
|
||||
emit started( m_currentTrack );
|
||||
|
||||
DatabaseCommand_LogPlayback* cmd = new DatabaseCommand_LogPlayback( m_currentTrack, DatabaseCommand_LogPlayback::Started );
|
||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
|
||||
}
|
||||
}
|
||||
|
||||
@ -288,14 +231,7 @@ AudioEngine::loadTrack( const Tomahawk::result_ptr& result )
|
||||
return false;
|
||||
}
|
||||
|
||||
// needs to be out of the mutexlocker scope
|
||||
if ( m_transcode.isNull() )
|
||||
{
|
||||
stop();
|
||||
emit error( AudioEngine::DecodeError );
|
||||
}
|
||||
|
||||
return !m_transcode.isNull();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -347,8 +283,6 @@ AudioEngine::playItem( PlaylistInterface* playlist, const Tomahawk::result_ptr&
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
|
||||
clearBuffers();
|
||||
|
||||
setPlaylist( playlist );
|
||||
m_currentTrackPlaylist = playlist;
|
||||
|
||||
@ -357,54 +291,41 @@ AudioEngine::playItem( PlaylistInterface* playlist, const Tomahawk::result_ptr&
|
||||
|
||||
|
||||
void
|
||||
AudioEngine::setStreamData( long sampleRate, int channels )
|
||||
AudioEngine::onStateChanged( Phonon::State newState, Phonon::State oldState )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << sampleRate << channels << thread();
|
||||
|
||||
if ( sampleRate < 44100 )
|
||||
sampleRate = 44100;
|
||||
|
||||
m_audio->initAudio( sampleRate, channels );
|
||||
if ( m_audio->startPlayback() )
|
||||
qDebug() << Q_FUNC_INFO << oldState << newState;
|
||||
if ( oldState == Phonon::PlayingState && newState == Phonon::StoppedState )
|
||||
{
|
||||
emit started( m_currentTrack );
|
||||
|
||||
DatabaseCommand_LogPlayback* cmd = new DatabaseCommand_LogPlayback( m_currentTrack, DatabaseCommand_LogPlayback::Started );
|
||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "Can't open device for audio output!";
|
||||
stop();
|
||||
emit error( AudioEngine::AudioDeviceError );
|
||||
if ( !m_expectStop )
|
||||
{
|
||||
m_expectStop = false;
|
||||
loadNextTrack();
|
||||
}
|
||||
}
|
||||
|
||||
qDebug() << Q_FUNC_INFO << sampleRate << channels << "done";
|
||||
m_expectStop = false;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AudioEngine::timerTriggered( unsigned int seconds )
|
||||
AudioEngine::timerTriggered( qint64 time )
|
||||
{
|
||||
m_timeElapsed = seconds;
|
||||
emit timerSeconds( seconds );
|
||||
|
||||
if ( m_currentTrack->duration() == 0 )
|
||||
if ( m_timeElapsed != time / 1000 )
|
||||
{
|
||||
emit timerPercentage( 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
emit timerPercentage( (unsigned int)( seconds / m_currentTrack->duration() ) );
|
||||
}
|
||||
}
|
||||
m_timeElapsed = time / 1000;
|
||||
emit timerSeconds( m_timeElapsed );
|
||||
|
||||
if ( m_currentTrack->duration() == 0 )
|
||||
{
|
||||
emit timerPercentage( 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
emit timerPercentage( ( (double)m_timeElapsed / (double)m_currentTrack->duration() ) * 100.0 );
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
AudioEngine::clearBuffers()
|
||||
{
|
||||
QMutexLocker lock( &m_mutex );
|
||||
m_audio->clearBuffers();
|
||||
emit timerMilliSeconds( time );
|
||||
}
|
||||
|
||||
|
||||
@ -430,102 +351,3 @@ AudioEngine::setCurrentTrack( const Tomahawk::result_ptr& result )
|
||||
|
||||
m_currentTrack = result;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AudioEngine::onDownloadProgress( qint64 recv, qint64 total )
|
||||
{
|
||||
if ( ( recv > 1024 * 32 ) || recv > total )
|
||||
m_readReady = true;
|
||||
|
||||
// qDebug() << "Got onDownloadProgress from reading http stream, received enough?" << m_readReady << "(" << recv << "> 1024 * 32 and" << recv << "<" << total << ")";
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AudioEngine::run()
|
||||
{
|
||||
QTimer::singleShot( 0, this, SLOT( engineLoop() ) );
|
||||
exec();
|
||||
qDebug() << "AudioEngine event loop stopped";
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AudioEngine::engineLoop()
|
||||
{
|
||||
qDebug() << "AudioEngine thread:" << this->thread();
|
||||
loop();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AudioEngine::loop()
|
||||
{
|
||||
m_i++;
|
||||
// if( m_i % 500 == 0 ) qDebug() << Q_FUNC_INFO << thread();
|
||||
|
||||
{
|
||||
QMutexLocker lock( &m_mutex );
|
||||
|
||||
// if ( m_i % 200 == 0 )
|
||||
// {
|
||||
// if ( !m_input.isNull() )
|
||||
// qDebug() << "Outer audio loop" << m_input->bytesAvailable() << m_audio->needData();
|
||||
// }
|
||||
|
||||
if ( m_i % 10 == 0 && m_audio->isPlaying() )
|
||||
m_audio->triggerTimers();
|
||||
|
||||
// qDebug() << !m_transcode.isNull() << !m_input.isNull() << m_audio->needData() << !m_audio->isPaused();
|
||||
// if( !m_input.isNull() ) qDebug() << "INPUT has bytes:" << m_input->bytesAvailable();
|
||||
if( !m_transcode.isNull() &&
|
||||
!m_input.isNull() &&
|
||||
m_input->bytesAvailable() &&
|
||||
m_audio->needData() &&
|
||||
!m_audio->isPaused() )
|
||||
{
|
||||
// if ( m_i % 50 == 0 )
|
||||
// qDebug() << "Inner audio loop";
|
||||
|
||||
if ( m_transcode->needData() > 0 )
|
||||
{
|
||||
QByteArray encdata = m_input->read( m_transcode->preferredDataSize() );
|
||||
m_transcode->processData( encdata, m_input->atEnd() );
|
||||
}
|
||||
|
||||
if ( m_transcode->haveData() )
|
||||
{
|
||||
QByteArray rawdata = m_transcode->data();
|
||||
m_audio->processData( rawdata );
|
||||
}
|
||||
|
||||
QTimer::singleShot( 0, this, SLOT( loop() ) );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int nextdelay = 50;
|
||||
// are we cleanly at the end of a track, and ready for the next one?
|
||||
if ( !m_input.isNull() &&
|
||||
m_input->atEnd() &&
|
||||
m_readReady &&
|
||||
!m_input->bytesAvailable() &&
|
||||
!m_audio->haveData() &&
|
||||
!m_audio->isPaused() )
|
||||
{
|
||||
qDebug() << !m_input.isNull() << m_input->atEnd() << m_readReady << !m_input->bytesAvailable() << !m_audio->haveData() << !m_audio->isPaused();
|
||||
qDebug() << "Starting next track then";
|
||||
loadNextTrack();
|
||||
// will need data immediately:
|
||||
nextdelay = 0;
|
||||
}
|
||||
else if ( !m_input.isNull() && !m_input->isOpen() )
|
||||
{
|
||||
qDebug() << "AudioEngine IODev closed. errorString:" << m_input->errorString();
|
||||
loadNextTrack();
|
||||
nextdelay = 0;
|
||||
}
|
||||
|
||||
QTimer::singleShot( nextdelay, this, SLOT( loop() ) );
|
||||
}
|
||||
|
@ -19,24 +19,21 @@
|
||||
#ifndef AUDIOENGINE_H
|
||||
#define AUDIOENGINE_H
|
||||
|
||||
#include <QThread>
|
||||
#include <QMutex>
|
||||
#include <QBuffer>
|
||||
#include <QObject>
|
||||
|
||||
#include <MediaObject>
|
||||
#include <AudioOutput>
|
||||
|
||||
#include "result.h"
|
||||
#include "typedefs.h"
|
||||
|
||||
#include "rtaudiooutput.h"
|
||||
#include "alsaplayback.h"
|
||||
#include "transcodeinterface.h"
|
||||
|
||||
#include "dllmacro.h"
|
||||
|
||||
#define AUDIO_VOLUME_STEP 5
|
||||
|
||||
class PlaylistInterface;
|
||||
|
||||
class DLLEXPORT AudioEngine : public QThread
|
||||
class DLLEXPORT AudioEngine : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@ -48,9 +45,9 @@ public:
|
||||
explicit AudioEngine();
|
||||
~AudioEngine();
|
||||
|
||||
unsigned int volume() const { if ( m_audio ) return m_audio->volume() * 100.0; else return 0; }; // in percent
|
||||
bool isPaused() const { return m_audio->isPaused(); }
|
||||
bool isPlaying() const { return m_audio->isPlaying(); }
|
||||
unsigned int volume() const { return m_audioOutput->volume() * 100.0; } // in percent
|
||||
bool isPlaying() const { return m_mediaObject->state() == Phonon::PlayingState; }
|
||||
bool isPaused() const { return m_mediaObject->state() == Phonon::PausedState; }
|
||||
|
||||
/* Returns the PlaylistInterface of the currently playing track. Note: This might be different to the current playlist! */
|
||||
PlaylistInterface* currentTrackPlaylist() const { return m_currentTrackPlaylist; }
|
||||
@ -77,7 +74,7 @@ public slots:
|
||||
void setPlaylist( PlaylistInterface* playlist );
|
||||
void setQueue( PlaylistInterface* queue ) { m_queue = queue; }
|
||||
|
||||
void onTrackAboutToClose();
|
||||
void onTrackAboutToFinish();
|
||||
|
||||
signals:
|
||||
void loading( const Tomahawk::result_ptr& track );
|
||||
@ -89,6 +86,7 @@ signals:
|
||||
|
||||
void volumeChanged( int volume /* in percent */ );
|
||||
|
||||
void timerMilliSeconds( qint64 msElapsed );
|
||||
void timerSeconds( unsigned int secondsElapsed );
|
||||
void timerPercentage( unsigned int percentage );
|
||||
|
||||
@ -101,39 +99,25 @@ private slots:
|
||||
void loadPreviousTrack();
|
||||
void loadNextTrack();
|
||||
|
||||
void onDownloadProgress( qint64 recv, qint64 total );
|
||||
|
||||
void setStreamData( long sampleRate, int channels );
|
||||
void timerTriggered( unsigned int seconds );
|
||||
|
||||
void engineLoop();
|
||||
void loop();
|
||||
void onStateChanged( Phonon::State newState, Phonon::State oldState );
|
||||
void timerTriggered( qint64 time );
|
||||
|
||||
void setCurrentTrack( const Tomahawk::result_ptr& result );
|
||||
|
||||
private:
|
||||
void run();
|
||||
void clearBuffers();
|
||||
|
||||
QSharedPointer<QIODevice> m_input;
|
||||
QSharedPointer<TranscodeInterface> m_transcode;
|
||||
|
||||
#ifdef Q_WS_X11
|
||||
AlsaPlayback* m_audio;
|
||||
#else
|
||||
RTAudioOutput* m_audio;
|
||||
#endif
|
||||
|
||||
Tomahawk::result_ptr m_currentTrack;
|
||||
Tomahawk::result_ptr m_lastTrack;
|
||||
PlaylistInterface* m_playlist;
|
||||
PlaylistInterface* m_currentTrackPlaylist;
|
||||
PlaylistInterface* m_queue;
|
||||
QMutex m_mutex;
|
||||
|
||||
bool m_readReady;
|
||||
Phonon::MediaObject* m_mediaObject;
|
||||
Phonon::AudioOutput* m_audioOutput;
|
||||
|
||||
unsigned int m_timeElapsed;
|
||||
int m_i;
|
||||
bool m_expectStop;
|
||||
|
||||
static AudioEngine* s_instance;
|
||||
};
|
||||
|
@ -1,166 +0,0 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||
*
|
||||
* Tomahawk is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Tomahawk is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "flactranscode.h"
|
||||
|
||||
|
||||
FLACTranscode::FLACTranscode()
|
||||
: m_FLACRunning( false )
|
||||
, m_finished( false )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
|
||||
init();
|
||||
set_metadata_respond_all();
|
||||
}
|
||||
|
||||
|
||||
FLACTranscode::~FLACTranscode()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
FLACTranscode::onSeek( int seconds )
|
||||
{
|
||||
Q_UNUSED( seconds );
|
||||
QMutexLocker locker( &m_mutex );
|
||||
|
||||
m_buffer.clear();
|
||||
m_outBuffer.clear();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
FLACTranscode::clearBuffers()
|
||||
{
|
||||
QMutexLocker locker( &m_mutex );
|
||||
|
||||
m_FLACRunning = false;
|
||||
m_finished = false;
|
||||
|
||||
m_buffer.clear();
|
||||
m_outBuffer.clear();
|
||||
|
||||
flush();
|
||||
reset();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
FLACTranscode::processData( const QByteArray& data, bool finish )
|
||||
{
|
||||
m_mutex.lock();
|
||||
m_buffer.append( data );
|
||||
m_mutex.unlock();
|
||||
|
||||
while ( m_buffer.size() >= FLAC_BUFFER || ( finish && !m_buffer.isEmpty() ) )
|
||||
{
|
||||
process_single();
|
||||
}
|
||||
|
||||
m_finished = finish;
|
||||
}
|
||||
|
||||
|
||||
::FLAC__StreamDecoderReadStatus
|
||||
FLACTranscode::read_callback( FLAC__byte buffer[], size_t *bytes )
|
||||
{
|
||||
QMutexLocker locker( &m_mutex );
|
||||
|
||||
if ( *bytes > (unsigned int)m_buffer.size() )
|
||||
*bytes = m_buffer.size();
|
||||
|
||||
memcpy( buffer, (char*)m_buffer.data(), *bytes );
|
||||
m_buffer.remove( 0, *bytes );
|
||||
|
||||
return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
|
||||
}
|
||||
|
||||
|
||||
::FLAC__StreamDecoderWriteStatus
|
||||
FLACTranscode::write_callback( const ::FLAC__Frame *frame, const FLAC__int32 *const buffer[] )
|
||||
{
|
||||
union PCMDATA
|
||||
{
|
||||
FLAC__int32 i;
|
||||
unsigned char b[2];
|
||||
} pcmDataLeft, pcmDataRight;
|
||||
|
||||
for ( unsigned int sample = 0; sample < frame->header.blocksize; sample++ )
|
||||
{
|
||||
pcmDataLeft.i = buffer[0][sample];
|
||||
pcmDataRight.i = buffer[1][sample];
|
||||
|
||||
m_outBuffer.append( pcmDataLeft.b[0] );
|
||||
m_outBuffer.append( pcmDataLeft.b[1] );
|
||||
m_outBuffer.append( pcmDataRight.b[0] );
|
||||
m_outBuffer.append( pcmDataRight.b[1] );
|
||||
}
|
||||
|
||||
return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
|
||||
}
|
||||
|
||||
|
||||
::FLAC__StreamDecoderSeekStatus
|
||||
FLACTranscode::seek_callback(FLAC__uint64 absolute_byte_offset)
|
||||
{
|
||||
Q_UNUSED( absolute_byte_offset );
|
||||
return FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
FLACTranscode::metadata_callback( const ::FLAC__StreamMetadata *metadata )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << metadata->is_last;
|
||||
|
||||
switch ( metadata->type )
|
||||
{
|
||||
case FLAC__METADATA_TYPE_STREAMINFO:
|
||||
{
|
||||
FLAC::Metadata::StreamInfo stream_info( (::FLAC__StreamMetadata *)metadata, true );
|
||||
|
||||
// Try to determine samplerate
|
||||
qDebug() << "FLACTranscode( BitsPerSample:" << stream_info.get_bits_per_sample() << "Samplerate:" << stream_info.get_sample_rate() << "Channels:" << stream_info.get_channels() << ")";
|
||||
emit streamInitialized( stream_info.get_sample_rate(), stream_info.get_channels() );
|
||||
|
||||
m_FLACRunning = true;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
qDebug() << "Not handling type:" << metadata->type;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
FLACTranscode::error_callback( ::FLAC__StreamDecoderErrorStatus status )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << status;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
FLACTranscode::eof_callback()
|
||||
{
|
||||
return ( m_buffer.isEmpty() && m_finished );
|
||||
}
|
@ -1,87 +0,0 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||
*
|
||||
* Tomahawk is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Tomahawk is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*! \class FLACTranscode
|
||||
\brief Transcoding plugin for FLAC streams.
|
||||
*/
|
||||
|
||||
#ifndef FLAC_TRANSCODE_H
|
||||
#define FLAC_TRANSCODE_H
|
||||
|
||||
#include "transcodeinterface.h"
|
||||
|
||||
#include <FLAC/format.h>
|
||||
#include <FLAC++/decoder.h>
|
||||
#include <FLAC++/metadata.h>
|
||||
|
||||
#include <QObject>
|
||||
#include <QMutex>
|
||||
#include <QDebug>
|
||||
|
||||
#include "dllmacro.h"
|
||||
|
||||
#define FLAC_BUFFER 32768 * 36
|
||||
#define FLAC_BUFFER_PREFERRED 32768
|
||||
|
||||
class DLLEXPORT FLACTranscode : public TranscodeInterface , protected FLAC::Decoder::Stream
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
FLACTranscode();
|
||||
~FLACTranscode();
|
||||
|
||||
const QStringList supportedTypes() const { QStringList l; l << "audio/flac" << "flac"; return l; }
|
||||
|
||||
int needData() { return FLAC_BUFFER - m_buffer.count(); }
|
||||
bool haveData() { return !m_outBuffer.isEmpty(); }
|
||||
|
||||
unsigned int preferredDataSize() { return FLAC_BUFFER_PREFERRED; }
|
||||
|
||||
QByteArray data() { QByteArray b = m_outBuffer; m_outBuffer.clear(); return b; }
|
||||
|
||||
QMutex* mutex() { return &m_mutex; }
|
||||
QByteArray* buffer() { return &m_buffer; }
|
||||
|
||||
signals:
|
||||
void streamInitialized( long sampleRate, int channels );
|
||||
|
||||
public slots:
|
||||
void onSeek( int seconds );
|
||||
void clearBuffers();
|
||||
void processData( const QByteArray& data, bool finish );
|
||||
|
||||
protected:
|
||||
virtual ::FLAC__StreamDecoderReadStatus read_callback( FLAC__byte buffer[], size_t *bytes );
|
||||
virtual ::FLAC__StreamDecoderWriteStatus write_callback( const ::FLAC__Frame *frame, const FLAC__int32 *const buffer[] );
|
||||
virtual ::FLAC__StreamDecoderSeekStatus seek_callback( FLAC__uint64 absolute_byte_offset );
|
||||
virtual bool eof_callback();
|
||||
virtual void metadata_callback( const ::FLAC__StreamMetadata *metadata );
|
||||
void error_callback( ::FLAC__StreamDecoderErrorStatus status );
|
||||
|
||||
private:
|
||||
QByteArray m_outBuffer;
|
||||
|
||||
QMutex m_mutex;
|
||||
QByteArray m_buffer;
|
||||
|
||||
bool m_FLACRunning;
|
||||
bool m_finished;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,222 +0,0 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||
*
|
||||
* Tomahawk is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Tomahawk is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "madtranscode.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
typedef struct audio_dither
|
||||
{
|
||||
mad_fixed_t error[3];
|
||||
mad_fixed_t random;
|
||||
} audio_dither;
|
||||
|
||||
|
||||
/* fast 32-bit pseudo-random number generator */
|
||||
/* code from madplay */
|
||||
static inline unsigned long prng( unsigned long state )
|
||||
{
|
||||
return (state * 0x0019660dL + 0x3c6ef35fL) & 0xffffffffL;
|
||||
}
|
||||
|
||||
|
||||
/* dithers 24-bit output to 16 bits instead of simple rounding */
|
||||
/* code from madplay */
|
||||
static inline signed int dither( mad_fixed_t sample, audio_dither *dither )
|
||||
{
|
||||
unsigned int scalebits;
|
||||
mad_fixed_t output, mask, random;
|
||||
|
||||
enum
|
||||
{
|
||||
MIN = -MAD_F_ONE,
|
||||
MAX = MAD_F_ONE - 1
|
||||
};
|
||||
|
||||
/* noise shape */
|
||||
sample += dither->error[0] - dither->error[1] + dither->error[2];
|
||||
|
||||
dither->error[2] = dither->error[1];
|
||||
dither->error[1] = dither->error[0] / 2;
|
||||
|
||||
/* bias */
|
||||
output = sample + (1L << (MAD_F_FRACBITS + 1 - 16 - 1));
|
||||
|
||||
scalebits = MAD_F_FRACBITS + 1 - 16;
|
||||
mask = (1L << scalebits) - 1;
|
||||
|
||||
/* dither */
|
||||
random = prng(dither->random);
|
||||
output += (random & mask) - (dither->random & mask);
|
||||
|
||||
dither->random = random;
|
||||
|
||||
/* clip */
|
||||
/* TODO: better clipping function */
|
||||
if (sample >= MAD_F_ONE)
|
||||
sample = MAD_F_ONE - 1;
|
||||
else if (sample < -MAD_F_ONE)
|
||||
sample = -MAD_F_ONE;
|
||||
if (output >= MAD_F_ONE)
|
||||
output = MAD_F_ONE - 1;
|
||||
else if (output < -MAD_F_ONE)
|
||||
output = -MAD_F_ONE;
|
||||
|
||||
/* quantize */
|
||||
output &= ~mask;
|
||||
|
||||
/* error feedback */
|
||||
dither->error[0] = sample - output;
|
||||
|
||||
/* scale */
|
||||
return output >> scalebits;
|
||||
}
|
||||
|
||||
|
||||
MADTranscode::MADTranscode() :
|
||||
m_decodedBufferCapacity( 32 * 1024 ),
|
||||
m_mpegInitialised( false )
|
||||
{
|
||||
qDebug() << "Initialising MAD Transcoding";
|
||||
|
||||
mad_stream_init( &stream );
|
||||
mad_frame_init( &frame );
|
||||
mad_synth_init( &synth );
|
||||
timer = mad_timer_zero;
|
||||
last_timer = mad_timer_zero;
|
||||
}
|
||||
|
||||
|
||||
MADTranscode::~MADTranscode()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
|
||||
mad_synth_finish( &synth );
|
||||
mad_frame_finish( &frame );
|
||||
mad_stream_finish( &stream );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MADTranscode::processData( const QByteArray &buffer, bool finish )
|
||||
{
|
||||
static audio_dither left_dither, right_dither;
|
||||
|
||||
int err = 0;
|
||||
m_encodedBuffer.append( buffer );
|
||||
|
||||
while ( err == 0 && ( m_encodedBuffer.count() >= MP3_BUFFER || finish ) )
|
||||
{
|
||||
mad_stream_buffer( &stream, (const unsigned char*)m_encodedBuffer.data(), m_encodedBuffer.count() );
|
||||
err = mad_frame_decode( &frame, &stream );
|
||||
|
||||
if ( stream.next_frame != 0 )
|
||||
{
|
||||
size_t r = stream.next_frame - stream.buffer;
|
||||
m_encodedBuffer.remove( 0, r );
|
||||
}
|
||||
|
||||
if ( err )
|
||||
{
|
||||
// if ( stream.error != MAD_ERROR_LOSTSYNC )
|
||||
// qDebug() << "libmad error:" << mad_stream_errorstr( &stream );
|
||||
|
||||
if ( !MAD_RECOVERABLE( stream.error ) )
|
||||
return;
|
||||
|
||||
err = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
mad_timer_add( &timer, frame.header.duration );
|
||||
mad_synth_frame( &synth, &frame );
|
||||
|
||||
if ( !m_mpegInitialised )
|
||||
{
|
||||
long sampleRate = synth.pcm.samplerate;
|
||||
int channels = synth.pcm.channels;
|
||||
|
||||
qDebug() << "madTranscode( Samplerate:" << sampleRate << "- Channels:" << channels << ")";
|
||||
|
||||
m_mpegInitialised = true;
|
||||
emit streamInitialized( sampleRate, channels > 0 ? channels : 2 );
|
||||
}
|
||||
|
||||
for ( int i = 0; i < synth.pcm.length; i++ )
|
||||
{
|
||||
union PCMDATA
|
||||
{
|
||||
short i;
|
||||
unsigned char b[2];
|
||||
} pcmData;
|
||||
|
||||
pcmData.i = dither( synth.pcm.samples[0][i], &left_dither );
|
||||
m_decodedBuffer.append( pcmData.b[0] );
|
||||
m_decodedBuffer.append( pcmData.b[1] );
|
||||
|
||||
if ( synth.pcm.channels == 2 )
|
||||
{
|
||||
pcmData.i = dither( synth.pcm.samples[1][i], &right_dither );
|
||||
m_decodedBuffer.append( pcmData.b[0] );
|
||||
m_decodedBuffer.append( pcmData.b[1] );
|
||||
}
|
||||
}
|
||||
|
||||
if ( timer.seconds != last_timer.seconds )
|
||||
emit timeChanged( timer.seconds );
|
||||
|
||||
last_timer = timer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MADTranscode::onSeek( int seconds )
|
||||
{
|
||||
mad_timer_t t;
|
||||
t.seconds = seconds;
|
||||
t.fraction = 0;
|
||||
|
||||
timer = mad_timer_zero;
|
||||
mad_timer_add( &timer, t );
|
||||
|
||||
m_encodedBuffer.clear();
|
||||
m_decodedBuffer.clear();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MADTranscode::clearBuffers()
|
||||
{
|
||||
mad_synth_finish( &synth );
|
||||
mad_frame_finish( &frame );
|
||||
mad_stream_finish( &stream );
|
||||
|
||||
m_mpegInitialised = false;
|
||||
timer = mad_timer_zero;
|
||||
last_timer = mad_timer_zero;
|
||||
|
||||
m_encodedBuffer.clear();
|
||||
m_decodedBuffer.clear();
|
||||
|
||||
mad_stream_init( &stream );
|
||||
mad_frame_init( &frame );
|
||||
mad_synth_init( &synth );
|
||||
}
|
||||
|
@ -1,83 +0,0 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||
*
|
||||
* Tomahawk is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Tomahawk is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*! \class MadTranscode
|
||||
\brief Transcoding plugin for MP3 streams, using libmad.
|
||||
*/
|
||||
|
||||
#ifndef MADTRANSCODE_H
|
||||
#define MADTRANSCODE_H
|
||||
|
||||
#include "transcodeinterface.h"
|
||||
|
||||
#include "mad.h"
|
||||
|
||||
#include <QStringList>
|
||||
#include <QByteArray>
|
||||
#include <QObject>
|
||||
#include <QMutex>
|
||||
|
||||
#include "dllmacro.h"
|
||||
|
||||
#define MP3_BUFFER 32768
|
||||
#define MP3_BUFFER_PREFERRED 32768
|
||||
|
||||
class DLLEXPORT MADTranscode : public TranscodeInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MADTranscode();
|
||||
virtual ~MADTranscode();
|
||||
|
||||
const QStringList supportedTypes() const { QStringList l; l << "application/x-mp3" << "mp3"; return l; }
|
||||
|
||||
int needData() { return MP3_BUFFER - m_encodedBuffer.count(); }
|
||||
bool haveData() { return !m_decodedBuffer.isEmpty(); }
|
||||
|
||||
unsigned int preferredDataSize() { return MP3_BUFFER_PREFERRED; }
|
||||
|
||||
QByteArray data() { QByteArray b = m_decodedBuffer; m_decodedBuffer.clear(); return b; }
|
||||
|
||||
virtual void setBufferCapacity( int bytes ) { m_decodedBufferCapacity = bytes; }
|
||||
int bufferSize() { return m_decodedBuffer.size(); }
|
||||
|
||||
public slots:
|
||||
virtual void clearBuffers();
|
||||
virtual void onSeek( int seconds );
|
||||
virtual void processData( const QByteArray& data, bool finish );
|
||||
|
||||
signals:
|
||||
void streamInitialized( long sampleRate, int channels );
|
||||
void timeChanged( int seconds );
|
||||
|
||||
private:
|
||||
QByteArray m_encodedBuffer;
|
||||
QByteArray m_decodedBuffer;
|
||||
int m_decodedBufferCapacity;
|
||||
|
||||
bool m_mpegInitialised;
|
||||
struct mad_decoder decoder;
|
||||
struct mad_stream stream;
|
||||
struct mad_frame frame;
|
||||
struct mad_synth synth;
|
||||
mad_timer_t timer;
|
||||
mad_timer_t last_timer;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,281 +0,0 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||
*
|
||||
* Tomahawk is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Tomahawk is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <QMutexLocker>
|
||||
#include <QStringList>
|
||||
#include <QMessageBox>
|
||||
#include <QDebug>
|
||||
|
||||
#include "rtaudiooutput.h"
|
||||
|
||||
#define BUFFER_SIZE 512
|
||||
|
||||
int
|
||||
audioCallback( void *outputBuffer, void *inputBuffer, unsigned int bufferSize, double streamTime, RtAudioStreamStatus status, void* data_src )
|
||||
{
|
||||
RTAudioOutput* parent = (RTAudioOutput*)data_src;
|
||||
QMutexLocker locker( parent->mutex() );
|
||||
|
||||
char* buffer = (char*)outputBuffer;
|
||||
|
||||
if ( !buffer || bufferSize != BUFFER_SIZE )
|
||||
return 0;
|
||||
|
||||
int bufs = bufferSize * 2 * parent->sourceChannels();
|
||||
memset( buffer, 0, bufs );
|
||||
|
||||
if ( parent->buffer()->size() >= bufs && !parent->isPaused() )
|
||||
{
|
||||
// Apply volume scaling
|
||||
for ( int i = 0; i < bufs / 2; i++ )
|
||||
{
|
||||
union PCMDATA
|
||||
{
|
||||
short i;
|
||||
unsigned char b[2];
|
||||
} pcmData;
|
||||
|
||||
pcmData.b[0] = parent->buffer()->at( i * 2 );
|
||||
pcmData.b[1] = parent->buffer()->at( i * 2 + 1 );
|
||||
|
||||
float pcmValue = (float)pcmData.i * parent->volume();
|
||||
pcmData.i = (short)pcmValue;
|
||||
|
||||
buffer[i * 2] = pcmData.b[0];
|
||||
buffer[i * 2 + 1] = pcmData.b[1];
|
||||
}
|
||||
|
||||
parent->m_pcmCounter += bufs;
|
||||
parent->buffer()->remove( 0, bufs );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
RTAudioOutput::RTAudioOutput() :
|
||||
m_pcmCounter( 0 ),
|
||||
m_audio( new RtAudio() ),
|
||||
m_bufferEmpty( true ),
|
||||
m_volume( 0.75 ),
|
||||
m_paused( false ),
|
||||
m_playing( false ),
|
||||
m_bps( -1 )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << m_audio->getCurrentApi();
|
||||
devices();
|
||||
}
|
||||
|
||||
|
||||
RTAudioOutput::~RTAudioOutput()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
stopPlayback();
|
||||
}
|
||||
|
||||
|
||||
QStringList
|
||||
RTAudioOutput::soundSystems()
|
||||
{
|
||||
QStringList l;
|
||||
|
||||
#ifdef WIN32
|
||||
l << "DirectSound";
|
||||
#endif
|
||||
|
||||
#ifdef Q_WS_X11
|
||||
l << "Alsa";
|
||||
#endif
|
||||
|
||||
#ifdef Q_WS_MAC
|
||||
l << "CoreAudio";
|
||||
#endif
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
|
||||
QStringList
|
||||
RTAudioOutput::devices()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
QStringList l;
|
||||
|
||||
try
|
||||
{
|
||||
qDebug() << "Device nums:" << m_audio->getDeviceCount();
|
||||
|
||||
for ( unsigned int i = 0; i < m_audio->getDeviceCount(); i++ )
|
||||
{
|
||||
RtAudio::DeviceInfo info;
|
||||
info = m_audio->getDeviceInfo( i );
|
||||
qDebug() << "Device found:" << i << QString::fromStdString( info.name ) << info.outputChannels << info.duplexChannels << info.isDefaultOutput;
|
||||
|
||||
if ( info.outputChannels > 0 )
|
||||
l << QString::fromStdString( info.name ); // FIXME make it utf8 compatible
|
||||
}
|
||||
}
|
||||
catch ( RtError &error )
|
||||
{
|
||||
}
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
RTAudioOutput::startPlayback()
|
||||
{
|
||||
qDebug () << Q_FUNC_INFO;
|
||||
|
||||
if ( m_audio->isStreamOpen() )
|
||||
{
|
||||
m_audio->startStream();
|
||||
m_playing = true;
|
||||
}
|
||||
|
||||
return m_audio->isStreamOpen();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
RTAudioOutput::stopPlayback()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
QMutexLocker locker( &m_mutex );
|
||||
|
||||
delete m_audio; // FIXME
|
||||
m_audio = new RtAudio();
|
||||
m_buffer.clear();
|
||||
m_paused = false;
|
||||
m_playing = false;
|
||||
m_bps = -1;
|
||||
m_pcmCounter = 0;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
RTAudioOutput::initAudio( long sampleRate, int channels )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << sampleRate << channels;
|
||||
QMutexLocker locker( &m_mutex );
|
||||
try
|
||||
{
|
||||
delete m_audio;
|
||||
m_audio = new RtAudio();
|
||||
m_bps = sampleRate * channels * 2;
|
||||
m_pcmCounter = 0;
|
||||
|
||||
RtAudio::StreamParameters parameters;
|
||||
parameters.deviceId = m_audio->getDefaultOutputDevice();
|
||||
parameters.nChannels = channels;
|
||||
parameters.firstChannel = 0;
|
||||
unsigned int bufferFrames = BUFFER_SIZE;
|
||||
|
||||
RtAudio::StreamOptions options;
|
||||
options.numberOfBuffers = 32;
|
||||
//options.flags = RTAUDIO_SCHEDULE_REALTIME;
|
||||
|
||||
m_sourceChannels = channels;
|
||||
m_buffer.clear();
|
||||
|
||||
/* if ( m_audio->isStreamRunning() )
|
||||
m_audio->abortStream();
|
||||
|
||||
if ( m_audio->isStreamOpen() )
|
||||
m_audio->closeStream();*/
|
||||
|
||||
m_audio->openStream( ¶meters, NULL, RTAUDIO_SINT16, sampleRate, &bufferFrames, &audioCallback, this, &options );
|
||||
}
|
||||
catch ( RtError &error )
|
||||
{
|
||||
qDebug() << "Starting stream failed. RtAudio error type: " << error.getType();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
RTAudioOutput::needData()
|
||||
{
|
||||
if ( m_buffer.isEmpty() && !m_bufferEmpty )
|
||||
{
|
||||
m_bufferEmpty = true;
|
||||
emit bufferEmpty();
|
||||
}
|
||||
|
||||
return ( m_buffer.size() < 65535 ); // FIXME constant value
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
RTAudioOutput::processData( const QByteArray &buffer )
|
||||
{
|
||||
QMutexLocker locker( &m_mutex );
|
||||
|
||||
m_buffer.append( buffer );
|
||||
if ( m_bufferEmpty && !buffer.isEmpty() )
|
||||
{
|
||||
m_bufferEmpty = false;
|
||||
emit bufferFull();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
RTAudioOutput::clearBuffers()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
QMutexLocker locker( &m_mutex );
|
||||
|
||||
m_buffer.clear();
|
||||
m_bufferEmpty = true;
|
||||
emit bufferEmpty();
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
RTAudioOutput::internalSoundCardID( int settingsID )
|
||||
{
|
||||
if ( settingsID < 0 )
|
||||
settingsID = 0;
|
||||
|
||||
try
|
||||
{
|
||||
int card = 0;
|
||||
|
||||
for ( unsigned int i = 1; i <= m_audio->getDeviceCount(); i++ )
|
||||
{
|
||||
RtAudio::DeviceInfo info;
|
||||
info = m_audio->getDeviceInfo( i );
|
||||
if ( info.outputChannels > 0 )
|
||||
{
|
||||
if ( card++ == settingsID )
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( RtError &error )
|
||||
{
|
||||
}
|
||||
|
||||
#ifdef Q_WS_MAC
|
||||
return 3; // FIXME?
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
@ -1,89 +0,0 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||
*
|
||||
* Tomahawk is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Tomahawk is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef RTAUDIOPLAYBACK_H
|
||||
#define RTAUDIOPLAYBACK_H
|
||||
|
||||
#include "RtAudio.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QMutex>
|
||||
|
||||
class RTAudioOutput : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
RTAudioOutput();
|
||||
~RTAudioOutput();
|
||||
|
||||
void initAudio( long sampleRate, int channels );
|
||||
|
||||
float volume() { return m_volume; }
|
||||
bool isPaused() { return m_paused; }
|
||||
virtual bool isPlaying() { return m_playing; }
|
||||
|
||||
bool haveData() { return m_buffer.length() > 2048; }
|
||||
bool needData();
|
||||
void processData( const QByteArray &buffer );
|
||||
|
||||
QStringList soundSystems();
|
||||
QStringList devices();
|
||||
int sourceChannels() { return m_sourceChannels; }
|
||||
|
||||
QMutex* mutex() { return &m_mutex; }
|
||||
QByteArray* buffer() { return &m_buffer; }
|
||||
|
||||
int m_pcmCounter;
|
||||
|
||||
public slots:
|
||||
void clearBuffers();
|
||||
|
||||
bool startPlayback();
|
||||
void stopPlayback();
|
||||
|
||||
void pause() { m_paused = true; }
|
||||
void resume() { m_paused = false; }
|
||||
|
||||
void setVolume( int volume ) { m_volume = ((float)(volume)) / (float)100.0; emit volumeChanged( m_volume ); }
|
||||
virtual void triggerTimers() { if ( m_bps > 0 ) emit timeElapsed( m_pcmCounter / m_bps ); else emit timeElapsed( 0 ); }
|
||||
|
||||
signals:
|
||||
void bufferEmpty();
|
||||
void bufferFull();
|
||||
|
||||
void volumeChanged( float volume );
|
||||
void timeElapsed( unsigned int seconds );
|
||||
|
||||
private:
|
||||
RtAudio *m_audio;
|
||||
bool m_bufferEmpty;
|
||||
|
||||
float m_volume;
|
||||
QByteArray m_buffer;
|
||||
QMutex m_mutex;
|
||||
|
||||
int m_sourceChannels;
|
||||
bool m_paused;
|
||||
bool m_playing;
|
||||
int m_bps;
|
||||
|
||||
int internalSoundCardID( int settingsID );
|
||||
};
|
||||
|
||||
#endif
|
@ -1,54 +0,0 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||
*
|
||||
* Tomahawk is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Tomahawk is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TRANSCODEINTERFACE_H
|
||||
#define TRANSCODEINTERFACE_H
|
||||
|
||||
#include <QStringList>
|
||||
#include <QByteArray>
|
||||
#include <QObject>
|
||||
#include <QMutex>
|
||||
|
||||
#include "dllmacro.h"
|
||||
|
||||
class DLLEXPORT TranscodeInterface : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
virtual ~TranscodeInterface() {}
|
||||
|
||||
virtual const QStringList supportedTypes() const = 0;
|
||||
|
||||
virtual int needData() = 0;
|
||||
virtual bool haveData() = 0;
|
||||
|
||||
virtual unsigned int preferredDataSize() = 0;
|
||||
|
||||
virtual QByteArray data() = 0;
|
||||
|
||||
// virtual void setBufferCapacity( int bytes ) = 0;
|
||||
// virtual int bufferSize() = 0;
|
||||
|
||||
public slots:
|
||||
virtual void clearBuffers() = 0;
|
||||
virtual void onSeek( int seconds ) = 0;
|
||||
virtual void processData( const QByteArray& data, bool finish ) = 0;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,144 +0,0 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||
*
|
||||
* Tomahawk is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Tomahawk is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "vorbistranscode.h"
|
||||
|
||||
|
||||
size_t
|
||||
vorbis_read( void* data_ptr, size_t byteSize, size_t sizeToRead, void* data_src )
|
||||
{
|
||||
VorbisTranscode* parent = (VorbisTranscode*)data_src;
|
||||
QMutexLocker locker( parent->mutex() );
|
||||
|
||||
int r = byteSize * sizeToRead;
|
||||
if ( r > parent->buffer()->size() )
|
||||
r = parent->buffer()->size();
|
||||
|
||||
memcpy( data_ptr, (char*)parent->buffer()->data(), r );
|
||||
parent->buffer()->remove( 0, r );
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
vorbis_seek( void* data_src, ogg_int64_t offset, int origin )
|
||||
{
|
||||
Q_UNUSED( data_src );
|
||||
Q_UNUSED( offset );
|
||||
Q_UNUSED( origin );
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
vorbis_close( void* data_src )
|
||||
{
|
||||
Q_UNUSED( data_src );
|
||||
// done ;-)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
long
|
||||
vorbis_tell( void* data_src )
|
||||
{
|
||||
Q_UNUSED( data_src );
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
VorbisTranscode::VorbisTranscode()
|
||||
: m_vorbisInit( false )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
}
|
||||
|
||||
|
||||
VorbisTranscode::~VorbisTranscode()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
VorbisTranscode::onSeek( int seconds )
|
||||
{
|
||||
Q_UNUSED( seconds );
|
||||
QMutexLocker locker( &m_mutex );
|
||||
|
||||
m_buffer.clear();
|
||||
m_outBuffer.clear();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
VorbisTranscode::clearBuffers()
|
||||
{
|
||||
QMutexLocker locker( &m_mutex );
|
||||
|
||||
m_vorbisInit = false;
|
||||
m_buffer.clear();
|
||||
m_outBuffer.clear();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
VorbisTranscode::processData( const QByteArray& data, bool )
|
||||
{
|
||||
m_mutex.lock();
|
||||
m_buffer.append( data );
|
||||
m_mutex.unlock();
|
||||
|
||||
if ( !m_vorbisInit && m_buffer.size() >= OGG_BUFFER )
|
||||
{
|
||||
ov_callbacks oggCallbacks;
|
||||
|
||||
oggCallbacks.read_func = vorbis_read;
|
||||
oggCallbacks.close_func = vorbis_close;
|
||||
oggCallbacks.seek_func = vorbis_seek;
|
||||
oggCallbacks.tell_func = vorbis_tell;
|
||||
|
||||
ov_open_callbacks( this, &m_vorbisFile, 0, 0, oggCallbacks );
|
||||
m_vorbisInit = true;
|
||||
|
||||
// Try to determine samplerate
|
||||
vorbis_info* vi = ov_info( &m_vorbisFile, -1 );
|
||||
qDebug() << "vorbisTranscode( Samplerate:" << vi->rate << "Channels:" << vi->channels << ")";
|
||||
|
||||
emit streamInitialized( vi->rate, vi->channels );
|
||||
}
|
||||
|
||||
long result = 1;
|
||||
int currentSection = 0;
|
||||
|
||||
while ( m_buffer.size() >= OGG_BUFFER && result > 0 )
|
||||
{
|
||||
char tempBuffer[16384];
|
||||
result = ov_read( &m_vorbisFile, tempBuffer, sizeof( tempBuffer ), 0, 2, 1, ¤tSection );
|
||||
|
||||
if ( result > 0 )
|
||||
{
|
||||
for ( int i = 0; i < ( result / 2 ); i++ )
|
||||
{
|
||||
m_outBuffer.append( tempBuffer[i * 2] );
|
||||
m_outBuffer.append( tempBuffer[i * 2 + 1] );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,81 +0,0 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||
*
|
||||
* Tomahawk is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Tomahawk is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*! \class VorbisTranscode
|
||||
\brief Transcoding plugin for OGG/Vorbis streams.
|
||||
*/
|
||||
|
||||
#ifndef VORBIS_TRANSCODE_H
|
||||
#define VORBIS_TRANSCODE_H
|
||||
|
||||
#include "transcodeinterface.h"
|
||||
|
||||
#include <vorbis/codec.h>
|
||||
#include <vorbis/vorbisfile.h>
|
||||
|
||||
#include <QObject>
|
||||
#include <QMutex>
|
||||
#include <QDebug>
|
||||
#include <QStringList>
|
||||
|
||||
#include "dllmacro.h"
|
||||
|
||||
// Must not be smaller than 8500 bytes!
|
||||
#define OGG_BUFFER 8500
|
||||
#define OGG_BUFFER_PREFERRED 32768
|
||||
|
||||
class DLLEXPORT VorbisTranscode : public TranscodeInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
VorbisTranscode();
|
||||
~VorbisTranscode();
|
||||
|
||||
const QStringList supportedTypes() const { QStringList l; l << "application/ogg" << "ogg"; return l; }
|
||||
|
||||
int needData() { return OGG_BUFFER - m_buffer.count(); }
|
||||
bool haveData() { return !m_outBuffer.isEmpty(); }
|
||||
|
||||
unsigned int preferredDataSize() { return OGG_BUFFER_PREFERRED; }
|
||||
|
||||
QByteArray data() { QByteArray b = m_outBuffer; m_outBuffer.clear(); return b; }
|
||||
|
||||
QMutex* mutex() { return &m_mutex; }
|
||||
QByteArray* buffer() { return &m_buffer; }
|
||||
|
||||
public slots:
|
||||
void clearBuffers();
|
||||
void onSeek( int seconds );
|
||||
void processData( const QByteArray& data, bool finish );
|
||||
|
||||
signals:
|
||||
void streamInitialized( long sampleRate, int channels );
|
||||
void timeChanged( int seconds );
|
||||
|
||||
private:
|
||||
QByteArray m_outBuffer;
|
||||
|
||||
QMutex m_mutex;
|
||||
QByteArray m_buffer;
|
||||
|
||||
OggVorbis_File m_vorbisFile;
|
||||
bool m_vorbisInit;
|
||||
};
|
||||
|
||||
#endif
|
@ -119,13 +119,13 @@ MusicScanner::MusicScanner( const QStringList& dirs, bool recursive, quint32 bs
|
||||
, m_dirListerThreadController( 0 )
|
||||
{
|
||||
m_ext2mime.insert( "mp3", TomahawkUtils::extensionToMimetype( "mp3" ) );
|
||||
|
||||
#ifndef NO_OGG
|
||||
m_ext2mime.insert( "ogg", TomahawkUtils::extensionToMimetype( "ogg" ) );
|
||||
#endif
|
||||
#ifndef NO_FLAC
|
||||
m_ext2mime.insert( "flac", TomahawkUtils::extensionToMimetype( "flac" ) );
|
||||
#endif
|
||||
m_ext2mime.insert( "mpc", TomahawkUtils::extensionToMimetype( "mpc" ) );
|
||||
m_ext2mime.insert( "wma", TomahawkUtils::extensionToMimetype( "wma" ) );
|
||||
m_ext2mime.insert( "aac", TomahawkUtils::extensionToMimetype( "aac" ) );
|
||||
m_ext2mime.insert( "m4a", TomahawkUtils::extensionToMimetype( "m4a" ) );
|
||||
m_ext2mime.insert( "mp4", TomahawkUtils::extensionToMimetype( "mp4" ) );
|
||||
}
|
||||
|
||||
|
||||
|
@ -539,12 +539,15 @@ SourceDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, co
|
||||
bool status = !( !sti || sti->source().isNull() || !sti->source()->isOnline() );
|
||||
QPixmap avatar( RESPATH "images/user-avatar.png" );
|
||||
QString tracks;
|
||||
QString name = index.data().toString();
|
||||
int figWidth = 0;
|
||||
|
||||
if ( status && sti && !sti->source().isNull() )
|
||||
{
|
||||
tracks = QString::number( sti->source()->trackCount() );
|
||||
figWidth = painter->fontMetrics().width( tracks );
|
||||
|
||||
name = sti->source()->friendlyName();
|
||||
if ( !sti->source()->avatar().isNull() )
|
||||
avatar = sti->source()->avatar();
|
||||
}
|
||||
@ -560,7 +563,7 @@ SourceDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, co
|
||||
QRect textRect = option.rect.adjusted( iconRect.width() + 8, 6, -figWidth - 24, 0 );
|
||||
if ( status || sti->source().isNull() )
|
||||
painter->setFont( bold );
|
||||
QString text = painter->fontMetrics().elidedText( index.data().toString(), Qt::ElideRight, textRect.width() );
|
||||
QString text = painter->fontMetrics().elidedText( name, Qt::ElideRight, textRect.width() );
|
||||
painter->drawText( textRect, text );
|
||||
|
||||
QString desc = status ? sti->source()->textStatus() : tr( "Offline" );
|
||||
|
6
thirdparty/CMakeLists.txt
vendored
6
thirdparty/CMakeLists.txt
vendored
@ -3,9 +3,3 @@ ADD_SUBDIRECTORY( qtweetlib )
|
||||
ADD_SUBDIRECTORY( libportfwd )
|
||||
ADD_SUBDIRECTORY( qxt )
|
||||
ADD_SUBDIRECTORY( liblastfm2 )
|
||||
|
||||
IF( UNIX AND NOT APPLE )
|
||||
ADD_SUBDIRECTORY( alsa-playback )
|
||||
ELSE()
|
||||
ADD_SUBDIRECTORY( rtaudio )
|
||||
ENDIF( UNIX AND NOT APPLE )
|
||||
|
46
thirdparty/alsa-playback/CMakeLists.txt
vendored
46
thirdparty/alsa-playback/CMakeLists.txt
vendored
@ -1,46 +0,0 @@
|
||||
PROJECT(alsaplayback)
|
||||
|
||||
find_package( Qt4 REQUIRED )
|
||||
|
||||
include( ${QT_USE_FILE} )
|
||||
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 2.6 FATAL_ERROR)
|
||||
SET(CMAKE_VERBOSE_MAKEFILE ON)
|
||||
#SET(CMAKE_INSTALL_PREFIX ".")
|
||||
|
||||
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
|
||||
SET( CMAKE_C_FLAGS ${CLEAN_C_FLAGS} )
|
||||
|
||||
#ADD_DEFINITIONS(-Wall -O2 -DNDEBUG)
|
||||
ADD_DEFINITIONS(-fPIC)
|
||||
|
||||
SET(AUDIO_LIBS "")
|
||||
|
||||
if(UNIX AND NOT APPLE)
|
||||
SET(AUDIO_LIBS "asound")
|
||||
endif(UNIX AND NOT APPLE)
|
||||
|
||||
set( alsaplaybackSources
|
||||
alsaplayback.cpp
|
||||
alsaaudio.cpp
|
||||
xconvert.c
|
||||
)
|
||||
|
||||
set( alsaplaybackHeaders
|
||||
alsaplayback.h
|
||||
)
|
||||
|
||||
qt4_wrap_cpp( alsaplaybackMoc ${alsaplaybackHeaders} )
|
||||
SET(final_src ${alsaplaybackMoc} ${alsaplaybackSources} ${alsaplaybackHeaders})
|
||||
|
||||
ADD_LIBRARY(alsaplayback STATIC ${final_src})
|
||||
|
||||
target_link_libraries( alsaplayback
|
||||
${QT_LIBRARIES}
|
||||
${AUDIO_LIBS}
|
||||
)
|
||||
|
||||
#INSTALL(TARGETS alsaplayback ARCHIVE DESTINATION lib${LIB_SUFFIX})
|
920
thirdparty/alsa-playback/alsaaudio.cpp
vendored
920
thirdparty/alsa-playback/alsaaudio.cpp
vendored
@ -1,920 +0,0 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2007 by John Stamp, <jstamp@users.sourceforge.net> *
|
||||
* Copyright (C) 2007 by Max Howell, Last.fm Ltd. *
|
||||
* Copyright (C) 2010 by Christian Muehlhaeuser <muesli@gmail.com> *
|
||||
* *
|
||||
* Large portions of this code are shamelessly copied from audio.c: *
|
||||
* The XMMS ALSA output plugin *
|
||||
* Copyright (C) 2001-2003 Matthieu Sozeau <mattam@altern.org> *
|
||||
* Copyright (C) 1998-2003 Peter Alm, Mikael Alm, Olle Hallnas, *
|
||||
* Thomas Nilsson and 4Front Technologies *
|
||||
* Copyright (C) 1999-2007 Haavard Kvaalen *
|
||||
* Copyright (C) 2005 Takashi Iwai *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02110-1301, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#include "alsaaudio.h"
|
||||
|
||||
#include <qendian.h>
|
||||
#include <QDebug>
|
||||
|
||||
//no debug
|
||||
#define snd_pcm_hw_params_dump( hwparams, logs )
|
||||
#define snd_pcm_sw_params_dump( x, y )
|
||||
#define snd_pcm_dump( x, y )
|
||||
|
||||
pthread_t AlsaAudio::audio_thread;
|
||||
|
||||
char* AlsaAudio::thread_buffer = NULL;
|
||||
int AlsaAudio::thread_buffer_size = 0;
|
||||
int AlsaAudio::rd_index = 0;
|
||||
int AlsaAudio::wr_index = 0;
|
||||
unsigned int AlsaAudio::pcmCounter = 0;
|
||||
|
||||
snd_output_t* AlsaAudio::logs = NULL;
|
||||
bool AlsaAudio::going = false;
|
||||
snd_pcm_t *AlsaAudio::alsa_pcm = NULL;
|
||||
|
||||
ssize_t AlsaAudio::hw_period_size_in = 0;
|
||||
snd_format* AlsaAudio::inputf = NULL;
|
||||
snd_format* AlsaAudio::outputf = NULL;
|
||||
float AlsaAudio::volume = 1.0;
|
||||
bool AlsaAudio::paused = false;
|
||||
|
||||
convert_func_t AlsaAudio::alsa_convert_func = NULL;
|
||||
convert_channel_func_t AlsaAudio::alsa_stereo_convert_func = NULL;
|
||||
convert_freq_func_t AlsaAudio::alsa_frequency_convert_func = NULL;
|
||||
xmms_convert_buffers* AlsaAudio::convertb = NULL;
|
||||
|
||||
|
||||
AlsaAudio::AlsaAudio()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AlsaAudio::~AlsaAudio()
|
||||
{
|
||||
// Close here just to be sure
|
||||
// These are safe to call more than once
|
||||
stopPlayback();
|
||||
alsaClose();
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* Device Detection
|
||||
******************************************************************************/
|
||||
|
||||
int
|
||||
AlsaAudio::getCards( void )
|
||||
{
|
||||
int card = -1;
|
||||
int err = 0;
|
||||
m_devices.clear();
|
||||
|
||||
// First add the default PCM device
|
||||
AlsaDeviceInfo dev;
|
||||
dev.name = "Default PCM device (default)";
|
||||
dev.device = "default";
|
||||
m_devices.push_back( dev );
|
||||
|
||||
if ( (err = snd_card_next( &card )) != 0 )
|
||||
goto getCardsFailed;
|
||||
|
||||
while ( card > -1 )
|
||||
{
|
||||
getDevicesForCard( card );
|
||||
if ( (err = snd_card_next( &card )) != 0 )
|
||||
goto getCardsFailed;
|
||||
}
|
||||
|
||||
return m_devices.size();
|
||||
|
||||
getCardsFailed:
|
||||
qDebug() << __PRETTY_FUNCTION__ << "failed:" << snd_strerror( -err );
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AlsaAudio::getDevicesForCard( int card )
|
||||
{
|
||||
int pcm_device = -1, err;
|
||||
snd_pcm_info_t *pcm_info;
|
||||
snd_ctl_t *ctl;
|
||||
char *alsa_name;
|
||||
QString cardName = "Unknown soundcard";
|
||||
QString device_name = QString( "hw:%1" ).arg( card );
|
||||
|
||||
if ((err = snd_ctl_open( &ctl, device_name.toAscii(), 0 )) < 0) {
|
||||
qDebug() << "Failed:" << snd_strerror( -err );
|
||||
return;
|
||||
}
|
||||
|
||||
if ((err = snd_card_get_name( card, &alsa_name )) != 0)
|
||||
{
|
||||
qDebug() << "Failed:" << snd_strerror( -err );
|
||||
}
|
||||
else
|
||||
cardName = alsa_name;
|
||||
|
||||
snd_pcm_info_alloca( &pcm_info );
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if ((err = snd_ctl_pcm_next_device( ctl, &pcm_device )) < 0)
|
||||
{
|
||||
qDebug() << "Failed:" << snd_strerror( -err );
|
||||
pcm_device = -1;
|
||||
}
|
||||
if (pcm_device < 0)
|
||||
break;
|
||||
|
||||
snd_pcm_info_set_device( pcm_info, pcm_device );
|
||||
snd_pcm_info_set_subdevice( pcm_info, 0 );
|
||||
snd_pcm_info_set_stream( pcm_info, SND_PCM_STREAM_PLAYBACK );
|
||||
|
||||
if ((err = snd_ctl_pcm_info( ctl, pcm_info )) < 0)
|
||||
{
|
||||
if ( err != -ENOENT )
|
||||
qDebug() << "Failed: snd_ctl_pcm_info() failed"
|
||||
"(" << card << ":" << pcm_device << "): "
|
||||
<< snd_strerror( -err );
|
||||
continue;
|
||||
}
|
||||
|
||||
AlsaDeviceInfo dev;
|
||||
dev.device = QString( "hw:%1,%2" )
|
||||
.arg( card )
|
||||
.arg( pcm_device );
|
||||
dev.name = QString( "%1: %2 (%3)" )
|
||||
.arg( cardName )
|
||||
.arg( snd_pcm_info_get_name( pcm_info ) )
|
||||
.arg( dev.device );
|
||||
|
||||
m_devices.push_back( dev );
|
||||
}
|
||||
|
||||
snd_ctl_close( ctl );
|
||||
}
|
||||
|
||||
|
||||
AlsaDeviceInfo
|
||||
AlsaAudio::getDeviceInfo( int device )
|
||||
{
|
||||
return m_devices[device];
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
Device Setup
|
||||
******************************************************************************/
|
||||
|
||||
bool
|
||||
AlsaAudio::alsaOpen( QString device, AFormat format, unsigned int rate,
|
||||
unsigned int channels, snd_pcm_uframes_t periodSize,
|
||||
unsigned int periodCount, int minBufferCapacity )
|
||||
{
|
||||
int err, hw_buffer_size;
|
||||
ssize_t hw_period_size;
|
||||
snd_pcm_hw_params_t *hwparams;
|
||||
snd_pcm_sw_params_t *swparams;
|
||||
snd_pcm_uframes_t alsa_buffer_size, alsa_period_size;
|
||||
|
||||
inputf = snd_format_from_xmms( format, rate, channels );
|
||||
convertb = xmms_convert_buffers_new();
|
||||
snd_output_stdio_attach( &logs, stderr, 0 );
|
||||
|
||||
alsa_convert_func = NULL;
|
||||
alsa_stereo_convert_func = NULL;
|
||||
alsa_frequency_convert_func = NULL;
|
||||
|
||||
free( outputf );
|
||||
outputf = snd_format_from_xmms( inputf->xmms_format, inputf->rate, inputf->channels );
|
||||
|
||||
qDebug() << "Opening device:" << device;
|
||||
|
||||
// FIXME: Can snd_pcm_open() return EAGAIN?
|
||||
if ((err = snd_pcm_open( &alsa_pcm,
|
||||
device.toAscii(),
|
||||
SND_PCM_STREAM_PLAYBACK,
|
||||
SND_PCM_NONBLOCK )) < 0)
|
||||
{
|
||||
qDebug() << "Failed to open pcm device (" << device << "):" << snd_strerror( -err );
|
||||
alsa_pcm = NULL;
|
||||
free( outputf );
|
||||
outputf = NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
snd_pcm_info_t *info;
|
||||
int alsa_card, alsa_device, alsa_subdevice;
|
||||
|
||||
snd_pcm_info_alloca( &info );
|
||||
snd_pcm_info( alsa_pcm, info );
|
||||
alsa_card = snd_pcm_info_get_card( info );
|
||||
alsa_device = snd_pcm_info_get_device( info );
|
||||
alsa_subdevice = snd_pcm_info_get_subdevice( info );
|
||||
|
||||
// qDebug() << "Card:" << alsa_card;
|
||||
// qDebug() << "Device:" << alsa_device;
|
||||
// qDebug() << "Subdevice:" << alsa_subdevice;
|
||||
|
||||
snd_pcm_hw_params_alloca( &hwparams );
|
||||
|
||||
if ( (err = snd_pcm_hw_params_any( alsa_pcm, hwparams ) ) < 0 )
|
||||
{
|
||||
qDebug() << "No configuration available for playback:"
|
||||
<< snd_strerror( -err );
|
||||
alsaClose();
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ( err = snd_pcm_hw_params_set_access( alsa_pcm, hwparams,
|
||||
SND_PCM_ACCESS_RW_INTERLEAVED ) ) < 0 )
|
||||
{
|
||||
qDebug() << "Cannot set normal write mode:" << snd_strerror( -err );
|
||||
alsaClose();
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ( err = snd_pcm_hw_params_set_format( alsa_pcm, hwparams, outputf->format ) ) < 0 )
|
||||
{
|
||||
// Try if one of these format work (one of them should work
|
||||
// on almost all soundcards)
|
||||
|
||||
snd_pcm_format_t formats[] = { SND_PCM_FORMAT_S16_LE,
|
||||
SND_PCM_FORMAT_S16_BE,
|
||||
SND_PCM_FORMAT_U8 };
|
||||
|
||||
uint i;
|
||||
for ( i = 0; i < sizeof( formats ) / sizeof( formats[0] ); i++ )
|
||||
{
|
||||
if ( snd_pcm_hw_params_set_format( alsa_pcm, hwparams, formats[i] ) == 0 )
|
||||
{
|
||||
outputf->format = formats[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( outputf->format != inputf->format )
|
||||
{
|
||||
outputf->xmms_format = (AFormat)format_from_alsa( outputf->format );
|
||||
|
||||
qDebug() << "Converting format from" << inputf->xmms_format << "to" << outputf->xmms_format;
|
||||
|
||||
if ( outputf->xmms_format < 0 )
|
||||
return -1;
|
||||
alsa_convert_func = xmms_convert_get_func( outputf->xmms_format, inputf->xmms_format );
|
||||
if ( alsa_convert_func == NULL )
|
||||
{
|
||||
qDebug() << "Format translation needed, but not available. Input:" << inputf->xmms_format << "; Output:" << outputf->xmms_format ;
|
||||
alsaClose();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "Sample format not available for playback:" << snd_strerror( -err );
|
||||
alsaClose();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
snd_pcm_hw_params_set_channels_near( alsa_pcm, hwparams, &outputf->channels );
|
||||
if ( outputf->channels != inputf->channels )
|
||||
{
|
||||
qDebug() << "Converting channels from" << inputf->channels << "to" << outputf->channels;
|
||||
|
||||
alsa_stereo_convert_func =
|
||||
xmms_convert_get_channel_func( outputf->xmms_format,
|
||||
outputf->channels,
|
||||
inputf->channels );
|
||||
if ( alsa_stereo_convert_func == NULL )
|
||||
{
|
||||
qDebug() << "No stereo conversion available. Format:" << outputf->xmms_format << "; Input Channels:" << inputf->channels << "; Output Channels:" << outputf->channels ;
|
||||
alsaClose();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
snd_pcm_hw_params_set_rate_near( alsa_pcm, hwparams, &outputf->rate, 0 );
|
||||
if ( outputf->rate == 0 )
|
||||
{
|
||||
qDebug() << "No usable samplerate available.";
|
||||
alsaClose();
|
||||
return false;
|
||||
}
|
||||
if ( outputf->rate != inputf->rate )
|
||||
{
|
||||
qDebug() << "Converting samplerate from" << inputf->rate << "to" << outputf->rate ;
|
||||
if ( outputf->channels < 1 || outputf->channels > 2 )
|
||||
{
|
||||
qDebug() << "Unsupported number of channels:" << outputf->channels << "- Resample function not available" ;
|
||||
alsa_frequency_convert_func = NULL;
|
||||
alsaClose();
|
||||
return false;
|
||||
}
|
||||
alsa_frequency_convert_func =
|
||||
xmms_convert_get_frequency_func( outputf->xmms_format,
|
||||
outputf->channels );
|
||||
if ( alsa_frequency_convert_func == NULL )
|
||||
{
|
||||
qDebug() << "Resample function not available. Format" << outputf->xmms_format ;
|
||||
alsaClose();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
outputf->sample_bits = snd_pcm_format_physical_width( outputf->format );
|
||||
outputf->bps = ( outputf->rate * outputf->sample_bits * outputf->channels ) >> 3;
|
||||
|
||||
if ( ( err = snd_pcm_hw_params_set_period_size_near( alsa_pcm, hwparams,
|
||||
&periodSize, NULL ) ) < 0 )
|
||||
{
|
||||
qDebug() << "Set period size failed:" << snd_strerror( -err );
|
||||
alsaClose();
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ( err = snd_pcm_hw_params_set_periods_near( alsa_pcm, hwparams,
|
||||
&periodCount, 0 ) ) < 0 )
|
||||
{
|
||||
qDebug() << "Set period count failed:" << snd_strerror( -err );
|
||||
alsaClose();
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( snd_pcm_hw_params( alsa_pcm, hwparams ) < 0 )
|
||||
{
|
||||
snd_pcm_hw_params_dump( hwparams, logs );
|
||||
qDebug() << "Unable to install hw params";
|
||||
alsaClose();
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ( err = snd_pcm_hw_params_get_buffer_size( hwparams, &alsa_buffer_size ) ) < 0 )
|
||||
{
|
||||
qDebug() << "snd_pcm_hw_params_get_buffer_size() failed:" << snd_strerror( -err );
|
||||
alsaClose();
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ( err = snd_pcm_hw_params_get_period_size( hwparams, &alsa_period_size, 0 ) ) < 0 )
|
||||
{
|
||||
qDebug() << "snd_pcm_hw_params_get_period_size() failed:" << snd_strerror( -err );
|
||||
alsaClose();
|
||||
return false;
|
||||
}
|
||||
snd_pcm_sw_params_alloca( &swparams );
|
||||
snd_pcm_sw_params_current( alsa_pcm, swparams );
|
||||
|
||||
if ( ( err = snd_pcm_sw_params_set_start_threshold( alsa_pcm,
|
||||
swparams, alsa_buffer_size - alsa_period_size ) < 0 ) )
|
||||
qDebug() << "Setting start threshold failed:" << snd_strerror( -err );
|
||||
if ( snd_pcm_sw_params( alsa_pcm, swparams ) < 0 )
|
||||
{
|
||||
qDebug() << "Unable to install sw params";
|
||||
alsaClose();
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifndef QT_NO_DEBUG
|
||||
snd_pcm_sw_params_dump( swparams, logs );
|
||||
snd_pcm_dump( alsa_pcm, logs );
|
||||
#endif
|
||||
|
||||
hw_period_size = snd_pcm_frames_to_bytes( alsa_pcm, alsa_period_size );
|
||||
if ( inputf->bps != outputf->bps )
|
||||
{
|
||||
int align = ( inputf->sample_bits * inputf->channels ) / 8;
|
||||
hw_period_size_in = ( (quint64)hw_period_size * inputf->bps +
|
||||
outputf->bps/2 ) / outputf->bps;
|
||||
hw_period_size_in -= hw_period_size_in % align;
|
||||
}
|
||||
else
|
||||
{
|
||||
hw_period_size_in = hw_period_size;
|
||||
}
|
||||
|
||||
hw_buffer_size = snd_pcm_frames_to_bytes( alsa_pcm, alsa_buffer_size );
|
||||
thread_buffer_size = minBufferCapacity * 4;
|
||||
if ( thread_buffer_size < hw_buffer_size )
|
||||
thread_buffer_size = hw_buffer_size * 2;
|
||||
if ( thread_buffer_size < 8192 )
|
||||
thread_buffer_size = 8192;
|
||||
thread_buffer_size += hw_buffer_size;
|
||||
thread_buffer_size -= thread_buffer_size % hw_period_size;
|
||||
|
||||
thread_buffer = (char*)calloc(thread_buffer_size, sizeof(char));
|
||||
|
||||
// qDebug() << "Device setup: period size:" << hw_period_size;
|
||||
// qDebug() << "Device setup: hw_period_size_in:" << hw_period_size_in;
|
||||
// qDebug() << "Device setup: hw_buffer_size:" << hw_buffer_size;
|
||||
// qDebug() << "Device setup: thread_buffer_size:" << thread_buffer_size;
|
||||
// qDebug() << "bits per sample:" << snd_pcm_format_physical_width( outputf->format )
|
||||
// << "frame size:" << snd_pcm_frames_to_bytes( alsa_pcm, 1 )
|
||||
// << "Bps:" << outputf->bps;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
AlsaAudio::startPlayback()
|
||||
{
|
||||
int pthreadError = 0;
|
||||
|
||||
// We should double check this here. AlsaPlayback::initAudio
|
||||
// isn't having its emitted error caught.
|
||||
// So double check here to avoid a potential assert.
|
||||
if ( !alsa_pcm )
|
||||
return 1;
|
||||
|
||||
going = true;
|
||||
|
||||
// qDebug() << "Starting thread";
|
||||
AlsaAudio* aaThread = new AlsaAudio();
|
||||
pthreadError = pthread_create( &audio_thread, NULL, &alsa_loop, (void*)aaThread );
|
||||
|
||||
return pthreadError;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AlsaAudio::clearBuffer( void )
|
||||
{
|
||||
wr_index = rd_index = pcmCounter = 0;
|
||||
if ( thread_buffer )
|
||||
memset( thread_buffer, 0, thread_buffer_size );
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
Play Interface
|
||||
******************************************************************************/
|
||||
|
||||
void
|
||||
AlsaAudio::alsaWrite( const QByteArray& input )
|
||||
{
|
||||
int cnt;
|
||||
const char *src = input.data();
|
||||
int length = input.size();
|
||||
//qDebug() << "alsaWrite length:" << length;
|
||||
|
||||
while ( length > 0 )
|
||||
{
|
||||
int wr;
|
||||
cnt = qMin(length, thread_buffer_size - wr_index);
|
||||
memcpy(thread_buffer + wr_index, src, cnt);
|
||||
wr = (wr_index + cnt) % thread_buffer_size;
|
||||
wr_index = wr;
|
||||
length -= cnt;
|
||||
src += cnt;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
AlsaAudio::get_thread_buffer_filled() const
|
||||
{
|
||||
if ( wr_index >= rd_index )
|
||||
{
|
||||
return wr_index - rd_index;
|
||||
}
|
||||
return ( thread_buffer_size - ( rd_index - wr_index ) );
|
||||
}
|
||||
|
||||
|
||||
// HACK: the buffer may have data, but not enough to send to the card. In that
|
||||
// case we tell alsaplayback that we don't have any. This may chop off some
|
||||
// data, but only at the natural end of a track. On my machine, this is at
|
||||
// most 3759 bytes. That's less than 0.022 sec. It beats padding the buffer
|
||||
// with 0's if the stream fails mid track. No stutter this way.
|
||||
int
|
||||
AlsaAudio::hasData()
|
||||
{
|
||||
int tempSize = get_thread_buffer_filled();
|
||||
if ( tempSize < hw_period_size_in )
|
||||
return 0;
|
||||
else
|
||||
return tempSize;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
AlsaAudio::alsa_free() const
|
||||
{
|
||||
//qDebug() << "alsa_free:" << thread_buffer_size - get_thread_buffer_filled() - 1;
|
||||
return thread_buffer_size - get_thread_buffer_filled() - 1;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AlsaAudio::setVolume ( float v )
|
||||
{
|
||||
volume = v;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AlsaAudio::stopPlayback()
|
||||
{
|
||||
if (going)
|
||||
{
|
||||
// Q_DEBUG_BLOCK;
|
||||
|
||||
going = false;
|
||||
|
||||
pthread_join( audio_thread, NULL );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AlsaAudio::alsaClose()
|
||||
{
|
||||
// Q_DEBUG_BLOCK;
|
||||
|
||||
alsa_close_pcm();
|
||||
|
||||
xmms_convert_buffers_destroy( convertb );
|
||||
convertb = NULL;
|
||||
|
||||
if ( thread_buffer )
|
||||
{
|
||||
free(thread_buffer);
|
||||
thread_buffer = NULL;
|
||||
}
|
||||
if ( inputf )
|
||||
{
|
||||
free( inputf );
|
||||
inputf = NULL;
|
||||
}
|
||||
if (outputf )
|
||||
{
|
||||
free( outputf );
|
||||
outputf = NULL;
|
||||
}
|
||||
if ( logs )
|
||||
{
|
||||
snd_output_close( logs );
|
||||
logs = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
Play Thread
|
||||
******************************************************************************/
|
||||
|
||||
void*
|
||||
AlsaAudio::alsa_loop( void* pthis )
|
||||
{
|
||||
AlsaAudio* aaThread = (AlsaAudio*)pthis;
|
||||
aaThread->run();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AlsaAudio::run()
|
||||
{
|
||||
int npfds = snd_pcm_poll_descriptors_count( alsa_pcm );
|
||||
int wr = 0;
|
||||
int err;
|
||||
|
||||
if ( npfds <= 0 )
|
||||
goto _error;
|
||||
|
||||
err = snd_pcm_prepare( alsa_pcm );
|
||||
if ( err < 0 )
|
||||
qDebug() << "snd_pcm_prepare error:" << snd_strerror( err );
|
||||
|
||||
while ( going && alsa_pcm )
|
||||
{
|
||||
if ( !paused && get_thread_buffer_filled() >= hw_period_size_in )
|
||||
{
|
||||
wr = snd_pcm_wait( alsa_pcm, 10 );
|
||||
|
||||
if ( wr > 0 )
|
||||
{
|
||||
alsa_write_out_thread_data();
|
||||
}
|
||||
else if ( wr < 0 )
|
||||
{
|
||||
alsa_handle_error( wr );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
struct timespec req;
|
||||
req.tv_sec = 0;
|
||||
req.tv_nsec = 10000000; //0.1 seconds
|
||||
nanosleep( &req, NULL );
|
||||
}
|
||||
}
|
||||
|
||||
_error:
|
||||
err = snd_pcm_drop( alsa_pcm );
|
||||
if ( err < 0 )
|
||||
qDebug() << "snd_pcm_drop error:" << snd_strerror( err );
|
||||
wr_index = rd_index = 0;
|
||||
memset( thread_buffer, 0, thread_buffer_size );
|
||||
|
||||
// qDebug() << "Exiting thread";
|
||||
|
||||
pthread_exit( NULL );
|
||||
}
|
||||
|
||||
|
||||
/* transfer audio data from thread buffer to h/w */
|
||||
void
|
||||
AlsaAudio::alsa_write_out_thread_data( void )
|
||||
{
|
||||
ssize_t length;
|
||||
int cnt;
|
||||
length = qMin( hw_period_size_in, ssize_t(get_thread_buffer_filled()) );
|
||||
length = qMin( length, snd_pcm_frames_to_bytes( alsa_pcm, alsa_get_avail() ) );
|
||||
|
||||
while (length > 0)
|
||||
{
|
||||
int rd;
|
||||
cnt = qMin(int(length), thread_buffer_size - rd_index);
|
||||
alsa_do_write( thread_buffer + rd_index, cnt);
|
||||
rd = (rd_index + cnt) % thread_buffer_size;
|
||||
rd_index = rd;
|
||||
length -= cnt;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* update and get the available space on h/w buffer (in frames) */
|
||||
snd_pcm_sframes_t
|
||||
AlsaAudio::alsa_get_avail( void )
|
||||
{
|
||||
snd_pcm_sframes_t ret;
|
||||
|
||||
if ( alsa_pcm == NULL )
|
||||
return 0;
|
||||
|
||||
while ( ( ret = snd_pcm_avail_update( alsa_pcm ) ) < 0 )
|
||||
{
|
||||
ret = alsa_handle_error( ret );
|
||||
if ( ret < 0 )
|
||||
{
|
||||
qDebug() << "alsa_get_avail(): snd_pcm_avail_update() failed:" << snd_strerror( -ret );
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/* transfer data to audio h/w; length is given in bytes
|
||||
*
|
||||
* data can be modified via rate conversion or
|
||||
* software volume before passed to audio h/w
|
||||
*/
|
||||
void
|
||||
AlsaAudio::alsa_do_write( void* data, ssize_t length )
|
||||
{
|
||||
if ( alsa_convert_func != NULL )
|
||||
length = alsa_convert_func( convertb, &data, length );
|
||||
if ( alsa_stereo_convert_func != NULL )
|
||||
length = alsa_stereo_convert_func( convertb, &data, length );
|
||||
if ( alsa_frequency_convert_func != NULL )
|
||||
{
|
||||
length = alsa_frequency_convert_func( convertb, &data, length,
|
||||
inputf->rate,
|
||||
outputf->rate );
|
||||
}
|
||||
|
||||
volume_adjust( data, length, outputf->xmms_format );
|
||||
|
||||
alsa_write_audio( (char*)data, length );
|
||||
}
|
||||
|
||||
|
||||
#define VOLUME_ADJUST( type, endian ) \
|
||||
do { \
|
||||
type *ptr = (type*)data; \
|
||||
for ( i = 0; i < length; i += 2 ) \
|
||||
{ \
|
||||
*ptr = qTo##endian( (type)( qFrom##endian( *ptr ) * volume ) ); \
|
||||
ptr++; \
|
||||
} \
|
||||
} while ( 0 )
|
||||
|
||||
#define VOLUME_ADJUST8( type ) \
|
||||
do { \
|
||||
type *ptr = (type*)data; \
|
||||
for ( i = 0; i < length; i++ ) \
|
||||
{ \
|
||||
*ptr = (type)( *ptr * volume ); \
|
||||
ptr++; \
|
||||
} \
|
||||
} while ( 0 )
|
||||
|
||||
void
|
||||
AlsaAudio::volume_adjust( void* data, ssize_t length, AFormat fmt )
|
||||
{
|
||||
ssize_t i;
|
||||
if ( volume == 1.0 )
|
||||
return;
|
||||
|
||||
switch ( fmt )
|
||||
{
|
||||
case FMT_S16_LE:
|
||||
VOLUME_ADJUST( qint16, LittleEndian );
|
||||
break;
|
||||
case FMT_U16_LE:
|
||||
VOLUME_ADJUST( quint16, LittleEndian );
|
||||
break;
|
||||
case FMT_S16_BE:
|
||||
VOLUME_ADJUST( qint16, BigEndian );
|
||||
break;
|
||||
case FMT_U16_BE:
|
||||
VOLUME_ADJUST( quint16, BigEndian );
|
||||
break;
|
||||
case FMT_S8:
|
||||
VOLUME_ADJUST8( qint8 );
|
||||
break;
|
||||
case FMT_U8:
|
||||
VOLUME_ADJUST8( quint8 );
|
||||
break;
|
||||
default:
|
||||
qDebug() << __PRETTY_FUNCTION__ << "unhandled format:" << fmt ;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* transfer data to audio h/w via normal write */
|
||||
void
|
||||
AlsaAudio::alsa_write_audio( char *data, ssize_t length )
|
||||
{
|
||||
snd_pcm_sframes_t written_frames;
|
||||
|
||||
while ( length > 0 )
|
||||
{
|
||||
snd_pcm_sframes_t frames = snd_pcm_bytes_to_frames( alsa_pcm, length );
|
||||
written_frames = snd_pcm_writei( alsa_pcm, data, frames );
|
||||
|
||||
if ( written_frames > 0 )
|
||||
{
|
||||
ssize_t written = snd_pcm_frames_to_bytes( alsa_pcm, written_frames );
|
||||
pcmCounter += written;
|
||||
|
||||
length -= written;
|
||||
data += written;
|
||||
}
|
||||
else
|
||||
{
|
||||
int err = alsa_handle_error( (int)written_frames );
|
||||
if ( err < 0 )
|
||||
{
|
||||
qDebug() << __PRETTY_FUNCTION__ << "write error:" << snd_strerror( -err );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* handle generic errors */
|
||||
int
|
||||
AlsaAudio::alsa_handle_error( int err )
|
||||
{
|
||||
switch ( err )
|
||||
{
|
||||
case -EPIPE:
|
||||
return xrun_recover();
|
||||
case -ESTRPIPE:
|
||||
return suspend_recover();
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
/* close PCM and release associated resources */
|
||||
void
|
||||
AlsaAudio::alsa_close_pcm( void )
|
||||
{
|
||||
if ( alsa_pcm )
|
||||
{
|
||||
int err;
|
||||
snd_pcm_drop( alsa_pcm );
|
||||
if ( ( err = snd_pcm_close( alsa_pcm ) ) < 0 )
|
||||
qDebug() << "alsa_close_pcm() failed:" << snd_strerror( -err );
|
||||
alsa_pcm = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
AlsaAudio::format_from_alsa( snd_pcm_format_t fmt )
|
||||
{
|
||||
uint i;
|
||||
for ( i = 0; i < sizeof( format_table ) / sizeof( format_table[0] ); i++ )
|
||||
if ( format_table[i].alsa == fmt )
|
||||
return format_table[i].xmms;
|
||||
qDebug() << "Unsupported format:" << snd_pcm_format_name( fmt );
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
struct snd_format*
|
||||
AlsaAudio::snd_format_from_xmms( AFormat fmt, unsigned int rate, unsigned int channels )
|
||||
{
|
||||
struct snd_format *f = (struct snd_format*)malloc( sizeof( struct snd_format ) );
|
||||
uint i;
|
||||
|
||||
f->xmms_format = fmt;
|
||||
f->format = SND_PCM_FORMAT_UNKNOWN;
|
||||
|
||||
for ( i = 0; i < sizeof( format_table ) / sizeof( format_table[0] ); i++ )
|
||||
{
|
||||
if ( format_table[i].xmms == fmt )
|
||||
{
|
||||
f->format = format_table[i].alsa;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Get rid of _NE */
|
||||
for ( i = 0; i < sizeof( format_table ) / sizeof( format_table[0] ); i++ )
|
||||
{
|
||||
if ( format_table[i].alsa == f->format )
|
||||
{
|
||||
f->xmms_format = format_table[i].xmms;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
f->rate = rate;
|
||||
f->channels = channels;
|
||||
f->sample_bits = snd_pcm_format_physical_width( f->format );
|
||||
f->bps = ( rate * f->sample_bits * channels ) >> 3;
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
AlsaAudio::xrun_recover( void )
|
||||
{
|
||||
#ifndef QT_NO_DEBUG
|
||||
snd_pcm_status_t *alsa_status;
|
||||
snd_pcm_status_alloca( &alsa_status );
|
||||
if ( snd_pcm_status( alsa_pcm, alsa_status ) < 0 )
|
||||
{
|
||||
qDebug() << "AlsaAudio::xrun_recover(): snd_pcm_status() failed";
|
||||
}
|
||||
else
|
||||
{
|
||||
snd_pcm_status_dump( alsa_status, logs );
|
||||
qDebug() << "Status:\n" << logs;
|
||||
}
|
||||
#endif
|
||||
|
||||
return snd_pcm_prepare( alsa_pcm );
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
AlsaAudio::suspend_recover( void )
|
||||
{
|
||||
int err;
|
||||
|
||||
while ( ( err = snd_pcm_resume( alsa_pcm ) ) == -EAGAIN )
|
||||
/* wait until suspend flag is released */
|
||||
sleep( 1 );
|
||||
if ( err < 0 )
|
||||
{
|
||||
qDebug() << "alsa_handle_error(): snd_pcm_resume() failed." ;
|
||||
return snd_pcm_prepare( alsa_pcm );
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
unsigned int
|
||||
AlsaAudio::timeElapsed()
|
||||
{
|
||||
return pcmCounter / outputf->bps;
|
||||
}
|
136
thirdparty/alsa-playback/alsaaudio.h
vendored
136
thirdparty/alsa-playback/alsaaudio.h
vendored
@ -1,136 +0,0 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2007 by John Stamp, <jstamp@users.sourceforge.net> *
|
||||
* Copyright (C) 2007 by Max Howell, Last.fm Ltd. *
|
||||
* Copyright (C) 2010 by Christian Muehlhaeuser <muesli@gmail.com> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02110-1301, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef ALSA_AUDIO_H
|
||||
#define ALSA_AUDIO_H
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
|
||||
#include <alsa/asoundlib.h>
|
||||
#include "xconvert.h"
|
||||
|
||||
struct AlsaDeviceInfo
|
||||
{
|
||||
QString name;
|
||||
QString device;
|
||||
};
|
||||
|
||||
struct snd_format
|
||||
{
|
||||
unsigned int rate;
|
||||
unsigned int channels;
|
||||
snd_pcm_format_t format;
|
||||
AFormat xmms_format;
|
||||
int sample_bits;
|
||||
int bps;
|
||||
};
|
||||
|
||||
static const struct
|
||||
{
|
||||
AFormat xmms;
|
||||
snd_pcm_format_t alsa;
|
||||
}
|
||||
|
||||
format_table[] = { { FMT_S16_LE, SND_PCM_FORMAT_S16_LE },
|
||||
{ FMT_S16_BE, SND_PCM_FORMAT_S16_BE },
|
||||
{ FMT_S16_NE, SND_PCM_FORMAT_S16 },
|
||||
{ FMT_U16_LE, SND_PCM_FORMAT_U16_LE },
|
||||
{ FMT_U16_BE, SND_PCM_FORMAT_U16_BE },
|
||||
{ FMT_U16_NE, SND_PCM_FORMAT_U16 },
|
||||
{ FMT_U8, SND_PCM_FORMAT_U8 },
|
||||
{ FMT_S8, SND_PCM_FORMAT_S8 }, };
|
||||
|
||||
class AlsaAudio
|
||||
{
|
||||
public:
|
||||
AlsaAudio();
|
||||
~AlsaAudio();
|
||||
|
||||
int getCards();
|
||||
AlsaDeviceInfo getDeviceInfo( int device );
|
||||
|
||||
bool alsaOpen( QString device, AFormat format, unsigned int rate,
|
||||
unsigned int channels, snd_pcm_uframes_t periodSize,
|
||||
unsigned int periodCount, int minBufferCapacity );
|
||||
|
||||
int startPlayback();
|
||||
void stopPlayback();
|
||||
|
||||
void alsaWrite( const QByteArray& inputData );
|
||||
void alsaClose();
|
||||
|
||||
void setVolume( float vol );
|
||||
void setPaused( bool enabled ) { paused = enabled; }
|
||||
|
||||
unsigned int timeElapsed();
|
||||
|
||||
int hasData();
|
||||
int get_thread_buffer_filled() const;
|
||||
int alsa_free() const;
|
||||
void clearBuffer();
|
||||
|
||||
private:
|
||||
QList<AlsaDeviceInfo> m_devices;
|
||||
|
||||
// The following static variables are configured in either
|
||||
// alsaOpen or alsaSetup and used later in the audio thread
|
||||
static ssize_t hw_period_size_in;
|
||||
static snd_output_t *logs;
|
||||
static bool going;
|
||||
static snd_pcm_t *alsa_pcm;
|
||||
static snd_format* inputf;
|
||||
static snd_format* outputf;
|
||||
static float volume;
|
||||
static bool paused;
|
||||
static convert_func_t alsa_convert_func;
|
||||
static convert_channel_func_t alsa_stereo_convert_func;
|
||||
static convert_freq_func_t alsa_frequency_convert_func;
|
||||
static xmms_convert_buffers *convertb;
|
||||
static pthread_t audio_thread;
|
||||
static unsigned int pcmCounter;
|
||||
|
||||
void getDevicesForCard( int card );
|
||||
|
||||
static void* alsa_loop( void* );
|
||||
void run();
|
||||
void alsa_write_out_thread_data();
|
||||
void alsa_do_write( void* data, ssize_t length );
|
||||
void volume_adjust( void* data, ssize_t length, AFormat fmt );
|
||||
void alsa_write_audio( char *data, ssize_t length );
|
||||
//int get_thread_buffer_filled() const;
|
||||
|
||||
static char* thread_buffer;
|
||||
static int thread_buffer_size;
|
||||
static int rd_index, wr_index;
|
||||
|
||||
snd_pcm_sframes_t alsa_get_avail( void );
|
||||
int alsa_handle_error( int err );
|
||||
int xrun_recover();
|
||||
int suspend_recover();
|
||||
int format_from_alsa( snd_pcm_format_t fmt );
|
||||
snd_format* snd_format_from_xmms( AFormat fmt, unsigned int rate, unsigned int channels );
|
||||
|
||||
void alsa_close_pcm( void );
|
||||
};
|
||||
|
||||
#endif
|
217
thirdparty/alsa-playback/alsaplayback.cpp
vendored
217
thirdparty/alsa-playback/alsaplayback.cpp
vendored
@ -1,217 +0,0 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2005 - 2010 by *
|
||||
* Christian Muehlhaeuser <muesli@gmail.com> *
|
||||
* Erik Jaelevik, Last.fm Ltd <erik@last.fm> *
|
||||
* Max Howell, Last.fm Ltd <max@last.fm> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#include "alsaaudio.h"
|
||||
#include "alsaplayback.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QStringList>
|
||||
|
||||
|
||||
AlsaPlayback::AlsaPlayback()
|
||||
: m_audio( 0 )
|
||||
, m_paused( false )
|
||||
, m_playing( false )
|
||||
, m_volume( 0.75 )
|
||||
, m_deviceNum( 0 )
|
||||
{
|
||||
setBufferCapacity( 32768 * 4 ); //FIXME: const value
|
||||
}
|
||||
|
||||
|
||||
AlsaPlayback::~AlsaPlayback()
|
||||
{
|
||||
delete m_audio;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
AlsaPlayback::haveData()
|
||||
{
|
||||
return ( m_audio->hasData() > 0 );
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
AlsaPlayback::needData()
|
||||
{
|
||||
return ( m_audio->get_thread_buffer_filled() < m_bufferCapacity );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AlsaPlayback::setBufferCapacity( int size )
|
||||
{
|
||||
m_bufferCapacity = size;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
AlsaPlayback::bufferSize()
|
||||
{
|
||||
return m_audio->get_thread_buffer_filled();
|
||||
}
|
||||
|
||||
|
||||
float
|
||||
AlsaPlayback::volume()
|
||||
{
|
||||
return m_volume;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AlsaPlayback::setVolume( int volume )
|
||||
{
|
||||
m_volume = (float)volume / 100.0;
|
||||
m_audio->setVolume( m_volume );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AlsaPlayback::triggerTimers()
|
||||
{
|
||||
if ( m_audio )
|
||||
emit timeElapsed( m_audio->timeElapsed() );
|
||||
}
|
||||
|
||||
|
||||
QStringList
|
||||
AlsaPlayback::soundSystems()
|
||||
{
|
||||
return QStringList() << "Alsa";
|
||||
}
|
||||
|
||||
|
||||
QStringList
|
||||
AlsaPlayback::devices()
|
||||
{
|
||||
// Q_DEBUG_BLOCK << "Querying audio devices";
|
||||
|
||||
QStringList devices;
|
||||
for (int i = 0, n = m_audio->getCards(); i < n; i++)
|
||||
devices << m_audio->getDeviceInfo( i ).name;
|
||||
|
||||
return devices;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
AlsaPlayback::startPlayback()
|
||||
{
|
||||
if ( !m_audio )
|
||||
{
|
||||
goto _error;
|
||||
}
|
||||
|
||||
if ( m_audio->startPlayback() )
|
||||
{
|
||||
goto _error;
|
||||
}
|
||||
|
||||
m_playing = true;
|
||||
return true;
|
||||
|
||||
_error:
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AlsaPlayback::stopPlayback()
|
||||
{
|
||||
m_audio->stopPlayback();
|
||||
m_paused = false;
|
||||
m_playing = false;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AlsaPlayback::initAudio( long sampleRate, int channels )
|
||||
{
|
||||
int periodSize = 1024; // According to mplayer, these two are good defaults.
|
||||
int periodCount = 16; // They create a buffer size of 16384 frames.
|
||||
QString cardDevice;
|
||||
|
||||
delete m_audio;
|
||||
m_audio = new AlsaAudio;
|
||||
m_audio->clearBuffer();
|
||||
|
||||
cardDevice = internalSoundCardID( m_deviceNum );
|
||||
|
||||
// We assume host byte order
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
if ( !m_audio->alsaOpen( cardDevice, FMT_S16_BE, sampleRate, channels, periodSize, periodCount, m_bufferCapacity ) )
|
||||
#else
|
||||
if ( !m_audio->alsaOpen( cardDevice, FMT_S16_LE, sampleRate, channels, periodSize, periodCount, m_bufferCapacity ) )
|
||||
#endif
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AlsaPlayback::processData( const QByteArray &buffer )
|
||||
{
|
||||
m_audio->alsaWrite( buffer );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AlsaPlayback::clearBuffers()
|
||||
{
|
||||
m_audio->clearBuffer();
|
||||
}
|
||||
|
||||
|
||||
QString
|
||||
AlsaPlayback::internalSoundCardID( int settingsID )
|
||||
{
|
||||
int cards = m_audio->getCards();
|
||||
|
||||
if ( settingsID < cards )
|
||||
return m_audio->getDeviceInfo( settingsID ).device;
|
||||
else
|
||||
return "default";
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AlsaPlayback::pause()
|
||||
{
|
||||
m_paused = true;
|
||||
|
||||
if ( m_audio )
|
||||
{
|
||||
m_audio->setPaused( true );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AlsaPlayback::resume()
|
||||
{
|
||||
m_paused = false;
|
||||
|
||||
if ( m_audio )
|
||||
m_audio->setPaused( false );
|
||||
}
|
80
thirdparty/alsa-playback/alsaplayback.h
vendored
80
thirdparty/alsa-playback/alsaplayback.h
vendored
@ -1,80 +0,0 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2005 - 2010 by *
|
||||
* Christian Muehlhaeuser <muesli@gmail.com> *
|
||||
* Erik Jaelevik, Last.fm Ltd <erik@last.fm> *
|
||||
* Max Howell, Last.fm Ltd <max@last.fm> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef ALSAPLAYBACK_H
|
||||
#define ALSAPLAYBACK_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class AlsaPlayback : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
AlsaPlayback();
|
||||
~AlsaPlayback();
|
||||
|
||||
virtual void initAudio( long sampleRate, int channels );
|
||||
|
||||
virtual float volume();
|
||||
virtual bool isPaused() { return m_paused; }
|
||||
virtual bool isPlaying() { return m_playing; }
|
||||
|
||||
virtual bool haveData();
|
||||
virtual bool needData();
|
||||
virtual void processData( const QByteArray& );
|
||||
|
||||
virtual void setBufferCapacity( int size );
|
||||
virtual int bufferSize();
|
||||
|
||||
virtual QStringList soundSystems();
|
||||
virtual QStringList devices();
|
||||
|
||||
public slots:
|
||||
virtual void clearBuffers();
|
||||
|
||||
virtual bool startPlayback();
|
||||
virtual void stopPlayback();
|
||||
|
||||
virtual void pause();
|
||||
virtual void resume();
|
||||
|
||||
virtual void setVolume( int volume );
|
||||
|
||||
virtual void triggerTimers();
|
||||
|
||||
signals:
|
||||
void timeElapsed( unsigned int seconds );
|
||||
|
||||
private:
|
||||
class AlsaAudio *m_audio;
|
||||
int m_bufferCapacity;
|
||||
|
||||
bool m_paused;
|
||||
bool m_playing;
|
||||
float m_volume;
|
||||
int m_deviceNum;
|
||||
|
||||
QString internalSoundCardID( int settingsID );
|
||||
};
|
||||
|
||||
#endif
|
771
thirdparty/alsa-playback/xconvert.c
vendored
771
thirdparty/alsa-playback/xconvert.c
vendored
@ -1,771 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2001-2003 Haavard Kvaalen <havardk@xmms.org>
|
||||
*
|
||||
* Licensed under GNU LGPL version 2.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include "xconvert.h"
|
||||
|
||||
// These are adapted from defines in gtypes.h and glibconfig.h
|
||||
#ifndef FALSE
|
||||
#define FALSE ( 0 )
|
||||
#endif
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE ( !FALSE )
|
||||
#endif
|
||||
|
||||
# define GUINT16_SWAP_LE_BE( val ) \
|
||||
( ( uint16_t ) \
|
||||
( \
|
||||
( uint16_t ) ( ( uint16_t ) ( val ) >> 8 ) | \
|
||||
( uint16_t ) ( ( uint16_t ) ( val ) << 8 ) \
|
||||
) \
|
||||
)
|
||||
|
||||
# define GINT16_SWAP_LE_BE( val ) ( ( int16_t ) GUINT16_SWAP_LE_BE ( val ) )
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
|
||||
# define IS_BIG_ENDIAN TRUE
|
||||
|
||||
# define GINT16_TO_BE( val ) ( ( int16_t ) ( val ) )
|
||||
# define GINT16_FROM_BE( val ) ( ( int16_t ) ( val ) )
|
||||
# define GUINT16_TO_BE( val ) ( ( uint16_t ) ( val ) )
|
||||
# define GUINT16_FROM_BE( val ) ( ( uint16_t ) ( val ) )
|
||||
|
||||
# define GUINT16_TO_LE( val ) ( GUINT16_SWAP_LE_BE ( val ) )
|
||||
# define GUINT16_FROM_LE( val ) ( GUINT16_SWAP_LE_BE ( val ) )
|
||||
# define GINT16_TO_LE( val ) ( ( int16_t ) GUINT16_SWAP_LE_BE ( val ) )
|
||||
# define GINT16_FROM_LE( val ) ( ( int16_t ) GUINT16_SWAP_LE_BE ( val ) )
|
||||
|
||||
#else
|
||||
|
||||
# define IS_BIG_ENDIAN FALSE
|
||||
|
||||
# define GINT16_TO_LE( val ) ( ( int16_t ) ( val ) )
|
||||
# define GINT16_FROM_LE( val ) ( ( int16_t ) ( val ) )
|
||||
# define GUINT16_TO_LE( val ) ( ( uint16_t ) ( val ) )
|
||||
# define GUINT16_FROM_LE( val ) ( ( uint16_t ) ( val ) )
|
||||
|
||||
# define GUINT16_TO_BE( val ) ( GUINT16_SWAP_LE_BE ( val ) )
|
||||
# define GUINT16_FROM_BE( val ) ( GUINT16_SWAP_LE_BE ( val ) )
|
||||
# define GINT16_TO_BE( val ) ( ( int16_t ) GUINT16_SWAP_LE_BE ( val ) )
|
||||
# define GINT16_FROM_BE( val ) ( ( int16_t ) GUINT16_SWAP_LE_BE ( val ) )
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
struct buffer {
|
||||
void *buffer;
|
||||
uint size;
|
||||
};
|
||||
|
||||
struct xmms_convert_buffers {
|
||||
struct buffer format_buffer, stereo_buffer, freq_buffer;
|
||||
};
|
||||
|
||||
struct xmms_convert_buffers* xmms_convert_buffers_new( void )
|
||||
{
|
||||
return calloc( 1, sizeof( struct xmms_convert_buffers ) );
|
||||
}
|
||||
|
||||
static void* convert_get_buffer( struct buffer *buffer, size_t size )
|
||||
{
|
||||
if ( size > 0 && size <= buffer->size )
|
||||
return buffer->buffer;
|
||||
|
||||
buffer->size = size;
|
||||
buffer->buffer = realloc( buffer->buffer, size );
|
||||
return buffer->buffer;
|
||||
}
|
||||
|
||||
void xmms_convert_buffers_free( struct xmms_convert_buffers* buf )
|
||||
{
|
||||
convert_get_buffer( &buf->format_buffer, 0 );
|
||||
convert_get_buffer( &buf->stereo_buffer, 0 );
|
||||
convert_get_buffer( &buf->freq_buffer, 0 );
|
||||
}
|
||||
|
||||
void xmms_convert_buffers_destroy( struct xmms_convert_buffers* buf )
|
||||
{
|
||||
if ( !buf )
|
||||
return;
|
||||
xmms_convert_buffers_free( buf );
|
||||
free( buf );
|
||||
}
|
||||
|
||||
static int convert_swap_endian( struct xmms_convert_buffers* buf, void **data, int length )
|
||||
{
|
||||
uint16_t *ptr = *data;
|
||||
int i;
|
||||
for ( i = 0; i < length; i += 2, ptr++ )
|
||||
*ptr = GUINT16_SWAP_LE_BE( *ptr );
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
static int convert_swap_sign_and_endian_to_native( struct xmms_convert_buffers* buf, void **data, int length )
|
||||
{
|
||||
uint16_t *ptr = *data;
|
||||
int i;
|
||||
for ( i = 0; i < length; i += 2, ptr++ )
|
||||
*ptr = GUINT16_SWAP_LE_BE( *ptr ) ^ 1 << 15;
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
static int convert_swap_sign_and_endian_to_alien( struct xmms_convert_buffers* buf, void **data, int length )
|
||||
{
|
||||
uint16_t *ptr = *data;
|
||||
int i;
|
||||
for ( i = 0; i < length; i += 2, ptr++ )
|
||||
*ptr = GUINT16_SWAP_LE_BE( *ptr ^ 1 << 15 );
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
static int convert_swap_sign16( struct xmms_convert_buffers* buf, void **data, int length )
|
||||
{
|
||||
int16_t *ptr = *data;
|
||||
int i;
|
||||
for ( i = 0; i < length; i += 2, ptr++ )
|
||||
*ptr ^= 1 << 15;
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
static int convert_swap_sign8( struct xmms_convert_buffers* buf, void **data, int length )
|
||||
{
|
||||
int8_t *ptr = *data;
|
||||
int i;
|
||||
for ( i = 0; i < length; i++ )
|
||||
*ptr++ ^= 1 << 7;
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
static int convert_to_8_native_endian( struct xmms_convert_buffers* buf, void **data, int length )
|
||||
{
|
||||
int8_t *output = *data;
|
||||
int16_t *input = *data;
|
||||
int i;
|
||||
for ( i = 0; i < length / 2; i++ )
|
||||
*output++ = *input++ >> 8;
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
static int convert_to_8_native_endian_swap_sign( struct xmms_convert_buffers* buf, void **data, int length )
|
||||
{
|
||||
int8_t *output = *data;
|
||||
int16_t *input = *data;
|
||||
int i;
|
||||
for ( i = 0; i < length / 2; i++ )
|
||||
*output++ = ( *input++ >> 8 ) ^ ( 1 << 7 );
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
static int convert_to_8_alien_endian( struct xmms_convert_buffers* buf, void **data, int length )
|
||||
{
|
||||
int8_t *output = *data;
|
||||
int16_t *input = *data;
|
||||
int i;
|
||||
for ( i = 0; i < length / 2; i++ )
|
||||
*output++ = *input++ & 0xff;
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
static int convert_to_8_alien_endian_swap_sign( struct xmms_convert_buffers* buf, void **data, int length )
|
||||
{
|
||||
int8_t *output = *data;
|
||||
int16_t *input = *data;
|
||||
int i;
|
||||
for ( i = 0; i < length / 2; i++ )
|
||||
*output++ = ( *input++ & 0xff ) ^ ( 1 << 7 );
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
static int convert_to_16_native_endian( struct xmms_convert_buffers* buf, void **data, int length )
|
||||
{
|
||||
uint8_t *input = *data;
|
||||
uint16_t *output;
|
||||
int i;
|
||||
*data = convert_get_buffer( &buf->format_buffer, length * 2 );
|
||||
output = *data;
|
||||
for ( i = 0; i < length; i++ )
|
||||
*output++ = *input++ << 8;
|
||||
|
||||
return i * 2;
|
||||
}
|
||||
|
||||
static int convert_to_16_native_endian_swap_sign( struct xmms_convert_buffers* buf, void **data, int length )
|
||||
{
|
||||
uint8_t *input = *data;
|
||||
uint16_t *output;
|
||||
int i;
|
||||
*data = convert_get_buffer( &buf->format_buffer, length * 2 );
|
||||
output = *data;
|
||||
for ( i = 0; i < length; i++ )
|
||||
*output++ = ( *input++ << 8 ) ^ ( 1 << 15 );
|
||||
|
||||
return i * 2;
|
||||
}
|
||||
|
||||
|
||||
static int convert_to_16_alien_endian( struct xmms_convert_buffers* buf, void **data, int length )
|
||||
{
|
||||
uint8_t *input = *data;
|
||||
uint16_t *output;
|
||||
int i;
|
||||
*data = convert_get_buffer( &buf->format_buffer, length * 2 );
|
||||
output = *data;
|
||||
for ( i = 0; i < length; i++ )
|
||||
*output++ = *input++;
|
||||
|
||||
return i * 2;
|
||||
}
|
||||
|
||||
static int convert_to_16_alien_endian_swap_sign( struct xmms_convert_buffers* buf, void **data, int length )
|
||||
{
|
||||
uint8_t *input = *data;
|
||||
uint16_t *output;
|
||||
int i;
|
||||
*data = convert_get_buffer( &buf->format_buffer, length * 2 );
|
||||
output = *data;
|
||||
for ( i = 0; i < length; i++ )
|
||||
*output++ = *input++ ^ ( 1 << 7 );
|
||||
|
||||
return i * 2;
|
||||
}
|
||||
|
||||
static AFormat unnativize( AFormat fmt )
|
||||
{
|
||||
if ( fmt == FMT_S16_NE )
|
||||
{
|
||||
if ( IS_BIG_ENDIAN )
|
||||
return FMT_S16_BE;
|
||||
else
|
||||
return FMT_S16_LE;
|
||||
}
|
||||
if ( fmt == FMT_U16_NE )
|
||||
{
|
||||
if ( IS_BIG_ENDIAN )
|
||||
return FMT_U16_BE;
|
||||
else
|
||||
return FMT_U16_LE;
|
||||
}
|
||||
return fmt;
|
||||
}
|
||||
|
||||
convert_func_t xmms_convert_get_func( AFormat output, AFormat input )
|
||||
{
|
||||
output = unnativize( output );
|
||||
input = unnativize( input );
|
||||
|
||||
if ( output == input )
|
||||
return NULL;
|
||||
|
||||
if ( ( output == FMT_U16_BE && input == FMT_U16_LE ) ||
|
||||
( output == FMT_U16_LE && input == FMT_U16_BE ) ||
|
||||
( output == FMT_S16_BE && input == FMT_S16_LE ) ||
|
||||
( output == FMT_S16_LE && input == FMT_S16_BE ) )
|
||||
return convert_swap_endian;
|
||||
|
||||
if ( ( output == FMT_U16_BE && input == FMT_S16_BE ) ||
|
||||
( output == FMT_U16_LE && input == FMT_S16_LE ) ||
|
||||
( output == FMT_S16_BE && input == FMT_U16_BE ) ||
|
||||
( output == FMT_S16_LE && input == FMT_U16_LE ) )
|
||||
return convert_swap_sign16;
|
||||
|
||||
if ( ( IS_BIG_ENDIAN &&
|
||||
( ( output == FMT_U16_BE && input == FMT_S16_LE ) ||
|
||||
( output == FMT_S16_BE && input == FMT_U16_LE ) ) ) ||
|
||||
( !IS_BIG_ENDIAN &&
|
||||
( ( output == FMT_U16_LE && input == FMT_S16_BE ) ||
|
||||
( output == FMT_S16_LE && input == FMT_U16_BE ) ) ) )
|
||||
return convert_swap_sign_and_endian_to_native;
|
||||
|
||||
if ( ( !IS_BIG_ENDIAN &&
|
||||
( ( output == FMT_U16_BE && input == FMT_S16_LE ) ||
|
||||
( output == FMT_S16_BE && input == FMT_U16_LE ) ) ) ||
|
||||
( IS_BIG_ENDIAN &&
|
||||
( ( output == FMT_U16_LE && input == FMT_S16_BE ) ||
|
||||
( output == FMT_S16_LE && input == FMT_U16_BE ) ) ) )
|
||||
return convert_swap_sign_and_endian_to_alien;
|
||||
|
||||
if ( ( IS_BIG_ENDIAN &&
|
||||
( ( output == FMT_U8 && input == FMT_U16_BE ) ||
|
||||
( output == FMT_S8 && input == FMT_S16_BE ) ) ) ||
|
||||
( !IS_BIG_ENDIAN &&
|
||||
( ( output == FMT_U8 && input == FMT_U16_LE ) ||
|
||||
( output == FMT_S8 && input == FMT_S16_LE ) ) ) )
|
||||
return convert_to_8_native_endian;
|
||||
|
||||
if ( ( IS_BIG_ENDIAN &&
|
||||
( ( output == FMT_U8 && input == FMT_S16_BE ) ||
|
||||
( output == FMT_S8 && input == FMT_U16_BE ) ) ) ||
|
||||
( !IS_BIG_ENDIAN &&
|
||||
( ( output == FMT_U8 && input == FMT_S16_LE ) ||
|
||||
( output == FMT_S8 && input == FMT_U16_LE ) ) ) )
|
||||
return convert_to_8_native_endian_swap_sign;
|
||||
|
||||
if ( ( !IS_BIG_ENDIAN &&
|
||||
( ( output == FMT_U8 && input == FMT_U16_BE ) ||
|
||||
( output == FMT_S8 && input == FMT_S16_BE ) ) ) ||
|
||||
( IS_BIG_ENDIAN &&
|
||||
( ( output == FMT_U8 && input == FMT_U16_LE ) ||
|
||||
( output == FMT_S8 && input == FMT_S16_LE ) ) ) )
|
||||
return convert_to_8_alien_endian;
|
||||
|
||||
if ( ( !IS_BIG_ENDIAN &&
|
||||
( ( output == FMT_U8 && input == FMT_S16_BE ) ||
|
||||
( output == FMT_S8 && input == FMT_U16_BE ) ) ) ||
|
||||
( IS_BIG_ENDIAN &&
|
||||
( ( output == FMT_U8 && input == FMT_S16_LE ) ||
|
||||
( output == FMT_S8 && input == FMT_U16_LE ) ) ) )
|
||||
return convert_to_8_alien_endian_swap_sign;
|
||||
|
||||
if ( ( output == FMT_U8 && input == FMT_S8 ) ||
|
||||
( output == FMT_S8 && input == FMT_U8 ) )
|
||||
return convert_swap_sign8;
|
||||
|
||||
if ( ( IS_BIG_ENDIAN &&
|
||||
( ( output == FMT_U16_BE && input == FMT_U8 ) ||
|
||||
( output == FMT_S16_BE && input == FMT_S8 ) ) ) ||
|
||||
( !IS_BIG_ENDIAN &&
|
||||
( ( output == FMT_U16_LE && input == FMT_U8 ) ||
|
||||
( output == FMT_S16_LE && input == FMT_S8 ) ) ) )
|
||||
return convert_to_16_native_endian;
|
||||
|
||||
if ( ( IS_BIG_ENDIAN &&
|
||||
( ( output == FMT_U16_BE && input == FMT_S8 ) ||
|
||||
( output == FMT_S16_BE && input == FMT_U8 ) ) ) ||
|
||||
( !IS_BIG_ENDIAN &&
|
||||
( ( output == FMT_U16_LE && input == FMT_S8 ) ||
|
||||
( output == FMT_S16_LE && input == FMT_U8 ) ) ) )
|
||||
return convert_to_16_native_endian_swap_sign;
|
||||
|
||||
if ( ( !IS_BIG_ENDIAN &&
|
||||
( ( output == FMT_U16_BE && input == FMT_U8 ) ||
|
||||
( output == FMT_S16_BE && input == FMT_S8 ) ) ) ||
|
||||
( IS_BIG_ENDIAN &&
|
||||
( ( output == FMT_U16_LE && input == FMT_U8 ) ||
|
||||
( output == FMT_S16_LE && input == FMT_S8 ) ) ) )
|
||||
return convert_to_16_alien_endian;
|
||||
|
||||
if ( ( !IS_BIG_ENDIAN &&
|
||||
( ( output == FMT_U16_BE && input == FMT_S8 ) ||
|
||||
( output == FMT_S16_BE && input == FMT_U8 ) ) ) ||
|
||||
( IS_BIG_ENDIAN &&
|
||||
( ( output == FMT_U16_LE && input == FMT_S8 ) ||
|
||||
( output == FMT_S16_LE && input == FMT_U8 ) ) ) )
|
||||
return convert_to_16_alien_endian_swap_sign;
|
||||
|
||||
//g_warning( "Translation needed, but not available.\n"
|
||||
// "Input: %d; Output %d.", input, output );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int convert_mono_to_stereo( struct xmms_convert_buffers* buf, void **data, int length, int b16 )
|
||||
{
|
||||
int i;
|
||||
void *outbuf = convert_get_buffer( &buf->stereo_buffer, length * 2 );
|
||||
|
||||
if ( b16 )
|
||||
{
|
||||
uint16_t *output = outbuf, *input = *data;
|
||||
for ( i = 0; i < length / 2; i++ )
|
||||
{
|
||||
*output++ = *input;
|
||||
*output++ = *input;
|
||||
input++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
uint8_t *output = outbuf, *input = *data;
|
||||
for ( i = 0; i < length; i++ )
|
||||
{
|
||||
*output++ = *input;
|
||||
*output++ = *input;
|
||||
input++;
|
||||
}
|
||||
}
|
||||
*data = outbuf;
|
||||
|
||||
return length * 2;
|
||||
}
|
||||
|
||||
static int convert_mono_to_stereo_8( struct xmms_convert_buffers* buf, void **data, int length )
|
||||
{
|
||||
return convert_mono_to_stereo( buf, data, length, FALSE );
|
||||
}
|
||||
|
||||
static int convert_mono_to_stereo_16( struct xmms_convert_buffers* buf, void **data, int length )
|
||||
{
|
||||
return convert_mono_to_stereo( buf, data, length, TRUE );
|
||||
}
|
||||
|
||||
static int convert_stereo_to_mono_u8( struct xmms_convert_buffers* buf, void **data, int length )
|
||||
{
|
||||
uint8_t *output = *data, *input = *data;
|
||||
int i;
|
||||
for ( i = 0; i < length / 2; i++ )
|
||||
{
|
||||
uint16_t tmp;
|
||||
tmp = *input++;
|
||||
tmp += *input++;
|
||||
*output++ = tmp / 2;
|
||||
}
|
||||
return length / 2;
|
||||
}
|
||||
static int convert_stereo_to_mono_s8( struct xmms_convert_buffers* buf, void **data, int length )
|
||||
{
|
||||
int8_t *output = *data, *input = *data;
|
||||
int i;
|
||||
for ( i = 0; i < length / 2; i++ )
|
||||
{
|
||||
int16_t tmp;
|
||||
tmp = *input++;
|
||||
tmp += *input++;
|
||||
*output++ = tmp / 2;
|
||||
}
|
||||
return length / 2;
|
||||
}
|
||||
static int convert_stereo_to_mono_u16le( struct xmms_convert_buffers* buf, void **data, int length )
|
||||
{
|
||||
uint16_t *output = *data, *input = *data;
|
||||
int i;
|
||||
for ( i = 0; i < length / 4; i++ )
|
||||
{
|
||||
uint32_t tmp;
|
||||
uint16_t stmp;
|
||||
tmp = GUINT16_FROM_LE( *input );
|
||||
input++;
|
||||
tmp += GUINT16_FROM_LE( *input );
|
||||
input++;
|
||||
stmp = tmp / 2;
|
||||
*output++ = GUINT16_TO_LE( stmp );
|
||||
}
|
||||
return length / 2;
|
||||
}
|
||||
|
||||
static int convert_stereo_to_mono_u16be( struct xmms_convert_buffers* buf, void **data, int length )
|
||||
{
|
||||
uint16_t *output = *data, *input = *data;
|
||||
int i;
|
||||
for ( i = 0; i < length / 4; i++ )
|
||||
{
|
||||
uint32_t tmp;
|
||||
uint16_t stmp;
|
||||
tmp = GUINT16_FROM_BE( *input );
|
||||
input++;
|
||||
tmp += GUINT16_FROM_BE( *input );
|
||||
input++;
|
||||
stmp = tmp / 2;
|
||||
*output++ = GUINT16_TO_BE( stmp );
|
||||
}
|
||||
return length / 2;
|
||||
}
|
||||
|
||||
static int convert_stereo_to_mono_s16le( struct xmms_convert_buffers* buf, void **data, int length )
|
||||
{
|
||||
int16_t *output = *data, *input = *data;
|
||||
int i;
|
||||
for ( i = 0; i < length / 4; i++ )
|
||||
{
|
||||
int32_t tmp;
|
||||
int16_t stmp;
|
||||
tmp = GINT16_FROM_LE( *input );
|
||||
input++;
|
||||
tmp += GINT16_FROM_LE( *input );
|
||||
input++;
|
||||
stmp = tmp / 2;
|
||||
*output++ = GINT16_TO_LE( stmp );
|
||||
}
|
||||
return length / 2;
|
||||
}
|
||||
|
||||
static int convert_stereo_to_mono_s16be( struct xmms_convert_buffers* buf, void **data, int length )
|
||||
{
|
||||
int16_t *output = *data, *input = *data;
|
||||
int i;
|
||||
for ( i = 0; i < length / 4; i++ )
|
||||
{
|
||||
int32_t tmp;
|
||||
int16_t stmp;
|
||||
tmp = GINT16_FROM_BE( *input );
|
||||
input++;
|
||||
tmp += GINT16_FROM_BE( *input );
|
||||
input++;
|
||||
stmp = tmp / 2;
|
||||
*output++ = GINT16_TO_BE( stmp );
|
||||
}
|
||||
return length / 2;
|
||||
}
|
||||
|
||||
convert_channel_func_t xmms_convert_get_channel_func( AFormat fmt, int output, int input )
|
||||
{
|
||||
fmt = unnativize( fmt );
|
||||
|
||||
if ( output == input )
|
||||
return NULL;
|
||||
|
||||
if ( input == 1 && output == 2 )
|
||||
switch ( fmt )
|
||||
{
|
||||
case FMT_U8:
|
||||
case FMT_S8:
|
||||
return convert_mono_to_stereo_8;
|
||||
case FMT_U16_LE:
|
||||
case FMT_U16_BE:
|
||||
case FMT_S16_LE:
|
||||
case FMT_S16_BE:
|
||||
return convert_mono_to_stereo_16;
|
||||
default:
|
||||
//g_warning( "Unknown format: %d"
|
||||
// "No conversion available.", fmt );
|
||||
return NULL;
|
||||
}
|
||||
if ( input == 2 && output == 1 )
|
||||
switch ( fmt )
|
||||
{
|
||||
case FMT_U8:
|
||||
return convert_stereo_to_mono_u8;
|
||||
case FMT_S8:
|
||||
return convert_stereo_to_mono_s8;
|
||||
case FMT_U16_LE:
|
||||
return convert_stereo_to_mono_u16le;
|
||||
case FMT_U16_BE:
|
||||
return convert_stereo_to_mono_u16be;
|
||||
case FMT_S16_LE:
|
||||
return convert_stereo_to_mono_s16le;
|
||||
case FMT_S16_BE:
|
||||
return convert_stereo_to_mono_s16be;
|
||||
default:
|
||||
//g_warning( "Unknown format: %d. "
|
||||
// "No conversion available.", fmt );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//g_warning( "Input has %d channels, soundcard uses %d channels\n"
|
||||
// "No conversion is available", input, output );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
#define RESAMPLE_STEREO( sample_type, bswap ) \
|
||||
do { \
|
||||
const int shift = sizeof ( sample_type ); \
|
||||
int i, in_samples, out_samples, x, delta; \
|
||||
sample_type *inptr = *data, *outptr; \
|
||||
uint nlen = ( ( ( length >> shift ) * ofreq ) / ifreq ); \
|
||||
void *nbuf; \
|
||||
if ( nlen == 0 ) \
|
||||
break; \
|
||||
nlen <<= shift; \
|
||||
if ( bswap ) \
|
||||
convert_swap_endian( NULL, data, length ); \
|
||||
nbuf = convert_get_buffer( &buf->freq_buffer, nlen ); \
|
||||
outptr = nbuf; \
|
||||
in_samples = length >> shift; \
|
||||
out_samples = nlen >> shift; \
|
||||
delta = ( in_samples << 12 ) / out_samples; \
|
||||
for ( x = 0, i = 0; i < out_samples; i++ ) \
|
||||
{ \
|
||||
int x1, frac; \
|
||||
x1 = ( x >> 12 ) << 12; \
|
||||
frac = x - x1; \
|
||||
*outptr++ = \
|
||||
( ( inptr[( x1 >> 12 ) << 1] * \
|
||||
( ( 1<<12 ) - frac ) + \
|
||||
inptr[( ( x1 >> 12 ) + 1 ) << 1] * \
|
||||
frac ) >> 12 ); \
|
||||
*outptr++ = \
|
||||
( ( inptr[( ( x1 >> 12 ) << 1 ) + 1] * \
|
||||
( ( 1<<12 ) - frac ) + \
|
||||
inptr[( ( ( x1 >> 12 ) + 1 ) << 1 ) + 1] * \
|
||||
frac ) >> 12 ); \
|
||||
x += delta; \
|
||||
} \
|
||||
if ( bswap ) \
|
||||
convert_swap_endian( NULL, &nbuf, nlen ); \
|
||||
*data = nbuf; \
|
||||
return nlen; \
|
||||
} while ( 0 )
|
||||
|
||||
|
||||
#define RESAMPLE_MONO( sample_type, bswap ) \
|
||||
do { \
|
||||
const int shift = sizeof ( sample_type ) - 1; \
|
||||
int i, x, delta, in_samples, out_samples; \
|
||||
sample_type *inptr = *data, *outptr; \
|
||||
uint nlen = ( ( ( length >> shift ) * ofreq ) / ifreq ); \
|
||||
void *nbuf; \
|
||||
if ( nlen == 0 ) \
|
||||
break; \
|
||||
nlen <<= shift; \
|
||||
if ( bswap ) \
|
||||
convert_swap_endian( NULL, data, length ); \
|
||||
nbuf = convert_get_buffer( &buf->freq_buffer, nlen ); \
|
||||
outptr = nbuf; \
|
||||
in_samples = length >> shift; \
|
||||
out_samples = nlen >> shift; \
|
||||
delta = ( ( length >> shift ) << 12 ) / out_samples; \
|
||||
for ( x = 0, i = 0; i < out_samples; i++ ) \
|
||||
{ \
|
||||
int x1, frac; \
|
||||
x1 = ( x >> 12 ) << 12; \
|
||||
frac = x - x1; \
|
||||
*outptr++ = \
|
||||
( ( inptr[x1 >> 12] * ( ( 1<<12 ) - frac ) + \
|
||||
inptr[( x1 >> 12 ) + 1] * frac ) >> 12 ); \
|
||||
x += delta; \
|
||||
} \
|
||||
if ( bswap ) \
|
||||
convert_swap_endian( NULL, &nbuf, nlen ); \
|
||||
*data = nbuf; \
|
||||
return nlen; \
|
||||
} while ( 0 )
|
||||
|
||||
static int convert_resample_stereo_s16ne( struct xmms_convert_buffers* buf, void **data, int length, int ifreq, int ofreq )
|
||||
{
|
||||
RESAMPLE_STEREO( int16_t, FALSE );
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int convert_resample_stereo_s16ae( struct xmms_convert_buffers* buf, void **data, int length, int ifreq, int ofreq )
|
||||
{
|
||||
RESAMPLE_STEREO( int16_t, TRUE );
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int convert_resample_stereo_u16ne( struct xmms_convert_buffers* buf, void **data, int length, int ifreq, int ofreq )
|
||||
{
|
||||
RESAMPLE_STEREO( uint16_t, FALSE );
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int convert_resample_stereo_u16ae( struct xmms_convert_buffers* buf, void **data, int length, int ifreq, int ofreq )
|
||||
{
|
||||
RESAMPLE_STEREO( uint16_t, TRUE );
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int convert_resample_mono_s16ne( struct xmms_convert_buffers* buf, void **data, int length, int ifreq, int ofreq )
|
||||
{
|
||||
RESAMPLE_MONO( int16_t, FALSE );
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int convert_resample_mono_s16ae( struct xmms_convert_buffers* buf, void **data, int length, int ifreq, int ofreq )
|
||||
{
|
||||
RESAMPLE_MONO( int16_t, TRUE );
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int convert_resample_mono_u16ne( struct xmms_convert_buffers* buf, void **data, int length, int ifreq, int ofreq )
|
||||
{
|
||||
RESAMPLE_MONO( uint16_t, FALSE );
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int convert_resample_mono_u16ae( struct xmms_convert_buffers* buf, void **data, int length, int ifreq, int ofreq )
|
||||
{
|
||||
RESAMPLE_MONO( uint16_t, TRUE );
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int convert_resample_stereo_u8( struct xmms_convert_buffers* buf, void **data, int length, int ifreq, int ofreq )
|
||||
{
|
||||
RESAMPLE_STEREO( uint8_t, FALSE );
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int convert_resample_mono_u8( struct xmms_convert_buffers* buf, void **data, int length, int ifreq, int ofreq )
|
||||
{
|
||||
RESAMPLE_MONO( uint8_t, FALSE );
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int convert_resample_stereo_s8( struct xmms_convert_buffers* buf, void **data, int length, int ifreq, int ofreq )
|
||||
{
|
||||
RESAMPLE_STEREO( int8_t, FALSE );
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int convert_resample_mono_s8( struct xmms_convert_buffers* buf, void **data, int length, int ifreq, int ofreq )
|
||||
{
|
||||
RESAMPLE_MONO( int8_t, FALSE );
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
convert_freq_func_t xmms_convert_get_frequency_func( AFormat fmt, int channels )
|
||||
{
|
||||
fmt = unnativize( fmt );
|
||||
//g_message( "fmt %d, channels: %d", fmt, channels );
|
||||
|
||||
if ( channels < 1 || channels > 2 )
|
||||
{
|
||||
//g_warning( "Unsupported number of channels: %d. "
|
||||
// "Resample function not available", channels );
|
||||
return NULL;
|
||||
}
|
||||
if ( ( IS_BIG_ENDIAN && fmt == FMT_U16_BE ) ||
|
||||
( !IS_BIG_ENDIAN && fmt == FMT_U16_LE ) )
|
||||
{
|
||||
if ( channels == 1 )
|
||||
return convert_resample_mono_u16ne;
|
||||
else
|
||||
return convert_resample_stereo_u16ne;
|
||||
}
|
||||
if ( ( IS_BIG_ENDIAN && fmt == FMT_S16_BE ) ||
|
||||
( !IS_BIG_ENDIAN && fmt == FMT_S16_LE ) )
|
||||
{
|
||||
if ( channels == 1 )
|
||||
return convert_resample_mono_s16ne;
|
||||
else
|
||||
return convert_resample_stereo_s16ne;
|
||||
}
|
||||
if ( ( !IS_BIG_ENDIAN && fmt == FMT_U16_BE ) ||
|
||||
( IS_BIG_ENDIAN && fmt == FMT_U16_LE ) )
|
||||
{
|
||||
if ( channels == 1 )
|
||||
return convert_resample_mono_u16ae;
|
||||
else
|
||||
return convert_resample_stereo_u16ae;
|
||||
}
|
||||
if ( ( !IS_BIG_ENDIAN && fmt == FMT_S16_BE ) ||
|
||||
( IS_BIG_ENDIAN && fmt == FMT_S16_LE ) )
|
||||
{
|
||||
if ( channels == 1 )
|
||||
return convert_resample_mono_s16ae;
|
||||
else
|
||||
return convert_resample_stereo_s16ae;
|
||||
}
|
||||
if ( fmt == FMT_U8 )
|
||||
{
|
||||
if ( channels == 1 )
|
||||
return convert_resample_mono_u8;
|
||||
else
|
||||
return convert_resample_stereo_u8;
|
||||
}
|
||||
if ( fmt == FMT_S8 )
|
||||
{
|
||||
if ( channels == 1 )
|
||||
return convert_resample_mono_s8;
|
||||
else
|
||||
return convert_resample_stereo_s8;
|
||||
}
|
||||
//g_warning( "Resample function not available"
|
||||
// "Format %d.", fmt );
|
||||
return NULL;
|
||||
}
|
43
thirdparty/alsa-playback/xconvert.h
vendored
43
thirdparty/alsa-playback/xconvert.h
vendored
@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2003 Haavard Kvaalen <havardk@xmms.org>
|
||||
*
|
||||
* Licensed under GNU LGPL version 2.
|
||||
*/
|
||||
|
||||
#if BYTE_ORDER == BIG_ENDIAN
|
||||
#define WORDS_BIGENDIAN 1
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum
|
||||
{
|
||||
FMT_U8, FMT_S8, FMT_U16_LE, FMT_U16_BE, FMT_U16_NE, FMT_S16_LE, FMT_S16_BE, FMT_S16_NE
|
||||
}
|
||||
AFormat;
|
||||
|
||||
struct xmms_convert_buffers;
|
||||
|
||||
struct xmms_convert_buffers* xmms_convert_buffers_new(void);
|
||||
/*
|
||||
* Free the data assosiated with the buffers, without destroying the
|
||||
* context. The context can be reused.
|
||||
*/
|
||||
void xmms_convert_buffers_free(struct xmms_convert_buffers* buf);
|
||||
void xmms_convert_buffers_destroy(struct xmms_convert_buffers* buf);
|
||||
|
||||
|
||||
typedef int (*convert_func_t)(struct xmms_convert_buffers* buf, void **data, int length);
|
||||
typedef int (*convert_channel_func_t)(struct xmms_convert_buffers* buf, void **data, int length);
|
||||
typedef int (*convert_freq_func_t)(struct xmms_convert_buffers* buf, void **data, int length, int ifreq, int ofreq);
|
||||
|
||||
|
||||
convert_func_t xmms_convert_get_func(AFormat output, AFormat input);
|
||||
convert_channel_func_t xmms_convert_get_channel_func(AFormat fmt, int output, int input);
|
||||
convert_freq_func_t xmms_convert_get_frequency_func(AFormat fmt, int channels);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
43
thirdparty/rtaudio/CMakeLists.txt
vendored
43
thirdparty/rtaudio/CMakeLists.txt
vendored
@ -1,43 +0,0 @@
|
||||
PROJECT(rtaudio)
|
||||
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 2.6 FATAL_ERROR)
|
||||
SET(CMAKE_VERBOSE_MAKEFILE ON)
|
||||
SET(CMAKE_INSTALL_PREFIX ".")
|
||||
|
||||
#ADD_DEFINITIONS(-Wall -O2 -DNDEBUG)
|
||||
#ADD_DEFINITIONS(-fPIC)
|
||||
|
||||
SET(AUDIO_LIBS "")
|
||||
|
||||
if(APPLE)
|
||||
ADD_DEFINITIONS(-DHAVE_GETTIMEOFDAY -D__MACOSX_CORE__)
|
||||
endif(APPLE)
|
||||
|
||||
if(WIN32)
|
||||
ADD_DEFINITIONS(-D__WINDOWS_DS__)
|
||||
INCLUDE_DIRECTORIES(
|
||||
../../dx2010/include
|
||||
# Just copy sal.h from VS\include to directx/include instead of this:
|
||||
# "c:\\Program Files\\Microsoft Visual Studio 10.0\\VC\\include"
|
||||
)
|
||||
SET(AUDIO_LIBS "dsound.dll" "winmm.dll" )
|
||||
endif(WIN32)
|
||||
|
||||
if(UNIX AND NOT APPLE)
|
||||
ADD_DEFINITIONS(-DHAVE_GETTIMEOFDAY -D__LINUX_ALSA__)
|
||||
SET(AUDIO_LIBS "asound")
|
||||
endif(UNIX AND NOT APPLE)
|
||||
|
||||
if(WIN32)
|
||||
ADD_LIBRARY(rtaudio SHARED RtAudio.cpp)
|
||||
else()
|
||||
ADD_LIBRARY(rtaudio STATIC RtAudio.cpp)
|
||||
endif()
|
||||
|
||||
target_link_libraries( rtaudio
|
||||
${AUDIO_LIBS}
|
||||
)
|
||||
|
||||
IF(WIN32)
|
||||
INSTALL( TARGETS rtaudio DESTINATION lib${LIB_SUFFIX} )
|
||||
ENDIF()
|
7918
thirdparty/rtaudio/RtAudio.cpp
vendored
7918
thirdparty/rtaudio/RtAudio.cpp
vendored
File diff suppressed because it is too large
Load Diff
967
thirdparty/rtaudio/RtAudio.h
vendored
967
thirdparty/rtaudio/RtAudio.h
vendored
@ -1,967 +0,0 @@
|
||||
/************************************************************************/
|
||||
/*! \class RtAudio
|
||||
\brief Realtime audio i/o C++ classes.
|
||||
|
||||
RtAudio provides a common API (Application Programming Interface)
|
||||
for realtime audio input/output across Linux (native ALSA, Jack,
|
||||
and OSS), Macintosh OS X (CoreAudio and Jack), and Windows
|
||||
(DirectSound and ASIO) operating systems.
|
||||
|
||||
RtAudio WWW site: http://www.music.mcgill.ca/~gary/rtaudio/
|
||||
|
||||
RtAudio: realtime audio i/o C++ classes
|
||||
Copyright (c) 2001-2010 Gary P. Scavone
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation files
|
||||
(the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge,
|
||||
publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
Any person wishing to distribute modifications to the Software is
|
||||
asked to send the modifications to the original developer so that
|
||||
they can be incorporated into the canonical version. This is,
|
||||
however, not a binding provision of this license.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
|
||||
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
||||
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
/************************************************************************/
|
||||
|
||||
/*!
|
||||
\file RtAudio.h
|
||||
*/
|
||||
|
||||
// RtAudio: Version 4.0.7
|
||||
|
||||
#ifndef __RTAUDIO_H
|
||||
#define __RTAUDIO_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "RtError.h"
|
||||
|
||||
/*! \typedef typedef unsigned long RtAudioFormat;
|
||||
\brief RtAudio data format type.
|
||||
|
||||
Support for signed integers and floats. Audio data fed to/from an
|
||||
RtAudio stream is assumed to ALWAYS be in host byte order. The
|
||||
internal routines will automatically take care of any necessary
|
||||
byte-swapping between the host format and the soundcard. Thus,
|
||||
endian-ness is not a concern in the following format definitions.
|
||||
|
||||
- \e RTAUDIO_SINT8: 8-bit signed integer.
|
||||
- \e RTAUDIO_SINT16: 16-bit signed integer.
|
||||
- \e RTAUDIO_SINT24: Upper 3 bytes of 32-bit signed integer.
|
||||
- \e RTAUDIO_SINT32: 32-bit signed integer.
|
||||
- \e RTAUDIO_FLOAT32: Normalized between plus/minus 1.0.
|
||||
- \e RTAUDIO_FLOAT64: Normalized between plus/minus 1.0.
|
||||
*/
|
||||
typedef unsigned long RtAudioFormat;
|
||||
static const RtAudioFormat RTAUDIO_SINT8 = 0x1; // 8-bit signed integer.
|
||||
static const RtAudioFormat RTAUDIO_SINT16 = 0x2; // 16-bit signed integer.
|
||||
static const RtAudioFormat RTAUDIO_SINT24 = 0x4; // Lower 3 bytes of 32-bit signed integer.
|
||||
static const RtAudioFormat RTAUDIO_SINT32 = 0x8; // 32-bit signed integer.
|
||||
static const RtAudioFormat RTAUDIO_FLOAT32 = 0x10; // Normalized between plus/minus 1.0.
|
||||
static const RtAudioFormat RTAUDIO_FLOAT64 = 0x20; // Normalized between plus/minus 1.0.
|
||||
|
||||
/*! \typedef typedef unsigned long RtAudioStreamFlags;
|
||||
\brief RtAudio stream option flags.
|
||||
|
||||
The following flags can be OR'ed together to allow a client to
|
||||
make changes to the default stream behavior:
|
||||
|
||||
- \e RTAUDIO_NONINTERLEAVED: Use non-interleaved buffers (default = interleaved).
|
||||
- \e RTAUDIO_MINIMIZE_LATENCY: Attempt to set stream parameters for lowest possible latency.
|
||||
- \e RTAUDIO_HOG_DEVICE: Attempt grab device for exclusive use.
|
||||
|
||||
By default, RtAudio streams pass and receive audio data from the
|
||||
client in an interleaved format. By passing the
|
||||
RTAUDIO_NONINTERLEAVED flag to the openStream() function, audio
|
||||
data will instead be presented in non-interleaved buffers. In
|
||||
this case, each buffer argument in the RtAudioCallback function
|
||||
will point to a single array of data, with \c nFrames samples for
|
||||
each channel concatenated back-to-back. For example, the first
|
||||
sample of data for the second channel would be located at index \c
|
||||
nFrames (assuming the \c buffer pointer was recast to the correct
|
||||
data type for the stream).
|
||||
|
||||
Certain audio APIs offer a number of parameters that influence the
|
||||
I/O latency of a stream. By default, RtAudio will attempt to set
|
||||
these parameters internally for robust (glitch-free) performance
|
||||
(though some APIs, like Windows Direct Sound, make this difficult).
|
||||
By passing the RTAUDIO_MINIMIZE_LATENCY flag to the openStream()
|
||||
function, internal stream settings will be influenced in an attempt
|
||||
to minimize stream latency, though possibly at the expense of stream
|
||||
performance.
|
||||
|
||||
If the RTAUDIO_HOG_DEVICE flag is set, RtAudio will attempt to
|
||||
open the input and/or output stream device(s) for exclusive use.
|
||||
Note that this is not possible with all supported audio APIs.
|
||||
|
||||
If the RTAUDIO_SCHEDULE_REALTIME flag is set, RtAudio will attempt
|
||||
to select realtime scheduling (round-robin) for the callback thread.
|
||||
*/
|
||||
typedef unsigned int RtAudioStreamFlags;
|
||||
static const RtAudioStreamFlags RTAUDIO_NONINTERLEAVED = 0x1; // Use non-interleaved buffers (default = interleaved).
|
||||
static const RtAudioStreamFlags RTAUDIO_MINIMIZE_LATENCY = 0x2; // Attempt to set stream parameters for lowest possible latency.
|
||||
static const RtAudioStreamFlags RTAUDIO_HOG_DEVICE = 0x4; // Attempt grab device and prevent use by others.
|
||||
static const RtAudioStreamFlags RTAUDIO_SCHEDULE_REALTIME = 0x8; // Try to select realtime scheduling for callback thread.
|
||||
|
||||
/*! \typedef typedef unsigned long RtAudioStreamStatus;
|
||||
\brief RtAudio stream status (over- or underflow) flags.
|
||||
|
||||
Notification of a stream over- or underflow is indicated by a
|
||||
non-zero stream \c status argument in the RtAudioCallback function.
|
||||
The stream status can be one of the following two options,
|
||||
depending on whether the stream is open for output and/or input:
|
||||
|
||||
- \e RTAUDIO_INPUT_OVERFLOW: Input data was discarded because of an overflow condition at the driver.
|
||||
- \e RTAUDIO_OUTPUT_UNDERFLOW: The output buffer ran low, likely producing a break in the output sound.
|
||||
*/
|
||||
typedef unsigned int RtAudioStreamStatus;
|
||||
static const RtAudioStreamStatus RTAUDIO_INPUT_OVERFLOW = 0x1; // Input data was discarded because of an overflow condition at the driver.
|
||||
static const RtAudioStreamStatus RTAUDIO_OUTPUT_UNDERFLOW = 0x2; // The output buffer ran low, likely causing a gap in the output sound.
|
||||
|
||||
//! RtAudio callback function prototype.
|
||||
/*!
|
||||
All RtAudio clients must create a function of type RtAudioCallback
|
||||
to read and/or write data from/to the audio stream. When the
|
||||
underlying audio system is ready for new input or output data, this
|
||||
function will be invoked.
|
||||
|
||||
\param outputBuffer For output (or duplex) streams, the client
|
||||
should write \c nFrames of audio sample frames into this
|
||||
buffer. This argument should be recast to the datatype
|
||||
specified when the stream was opened. For input-only
|
||||
streams, this argument will be NULL.
|
||||
|
||||
\param inputBuffer For input (or duplex) streams, this buffer will
|
||||
hold \c nFrames of input audio sample frames. This
|
||||
argument should be recast to the datatype specified when the
|
||||
stream was opened. For output-only streams, this argument
|
||||
will be NULL.
|
||||
|
||||
\param nFrames The number of sample frames of input or output
|
||||
data in the buffers. The actual buffer size in bytes is
|
||||
dependent on the data type and number of channels in use.
|
||||
|
||||
\param streamTime The number of seconds that have elapsed since the
|
||||
stream was started.
|
||||
|
||||
\param status If non-zero, this argument indicates a data overflow
|
||||
or underflow condition for the stream. The particular
|
||||
condition can be determined by comparison with the
|
||||
RtAudioStreamStatus flags.
|
||||
|
||||
\param userData A pointer to optional data provided by the client
|
||||
when opening the stream (default = NULL).
|
||||
|
||||
To continue normal stream operation, the RtAudioCallback function
|
||||
should return a value of zero. To stop the stream and drain the
|
||||
output buffer, the function should return a value of one. To abort
|
||||
the stream immediately, the client should return a value of two.
|
||||
*/
|
||||
typedef int (*RtAudioCallback)( void *outputBuffer, void *inputBuffer,
|
||||
unsigned int nFrames,
|
||||
double streamTime,
|
||||
RtAudioStreamStatus status,
|
||||
void *userData );
|
||||
|
||||
|
||||
// **************************************************************** //
|
||||
//
|
||||
// RtAudio class declaration.
|
||||
//
|
||||
// RtAudio is a "controller" used to select an available audio i/o
|
||||
// interface. It presents a common API for the user to call but all
|
||||
// functionality is implemented by the class RtApi and its
|
||||
// subclasses. RtAudio creates an instance of an RtApi subclass
|
||||
// based on the user's API choice. If no choice is made, RtAudio
|
||||
// attempts to make a "logical" API selection.
|
||||
//
|
||||
// **************************************************************** //
|
||||
|
||||
class RtApi;
|
||||
|
||||
class RtAudio
|
||||
{
|
||||
public:
|
||||
|
||||
//! Audio API specifier arguments.
|
||||
enum Api {
|
||||
UNSPECIFIED, /*!< Search for a working compiled API. */
|
||||
LINUX_ALSA, /*!< The Advanced Linux Sound Architecture API. */
|
||||
LINUX_OSS, /*!< The Linux Open Sound System API. */
|
||||
UNIX_JACK, /*!< The Jack Low-Latency Audio Server API. */
|
||||
MACOSX_CORE, /*!< Macintosh OS-X Core Audio API. */
|
||||
WINDOWS_ASIO, /*!< The Steinberg Audio Stream I/O API. */
|
||||
WINDOWS_DS, /*!< The Microsoft Direct Sound API. */
|
||||
RTAUDIO_DUMMY /*!< A compilable but non-functional API. */
|
||||
};
|
||||
|
||||
//! The public device information structure for returning queried values.
|
||||
struct DeviceInfo {
|
||||
bool probed; /*!< true if the device capabilities were successfully probed. */
|
||||
std::string name; /*!< Character string device identifier. */
|
||||
unsigned int outputChannels; /*!< Maximum output channels supported by device. */
|
||||
unsigned int inputChannels; /*!< Maximum input channels supported by device. */
|
||||
unsigned int duplexChannels; /*!< Maximum simultaneous input/output channels supported by device. */
|
||||
bool isDefaultOutput; /*!< true if this is the default output device. */
|
||||
bool isDefaultInput; /*!< true if this is the default input device. */
|
||||
std::vector<unsigned int> sampleRates; /*!< Supported sample rates (queried from list of standard rates). */
|
||||
RtAudioFormat nativeFormats; /*!< Bit mask of supported data formats. */
|
||||
|
||||
// Default constructor.
|
||||
DeviceInfo()
|
||||
:probed(false), outputChannels(0), inputChannels(0), duplexChannels(0),
|
||||
isDefaultOutput(false), isDefaultInput(false), nativeFormats(0) {}
|
||||
};
|
||||
|
||||
//! The structure for specifying input or ouput stream parameters.
|
||||
struct StreamParameters {
|
||||
unsigned int deviceId; /*!< Device index (0 to getDeviceCount() - 1). */
|
||||
unsigned int nChannels; /*!< Number of channels. */
|
||||
unsigned int firstChannel; /*!< First channel index on device (default = 0). */
|
||||
|
||||
// Default constructor.
|
||||
StreamParameters()
|
||||
: deviceId(0), nChannels(0), firstChannel(0) {}
|
||||
};
|
||||
|
||||
//! The structure for specifying stream options.
|
||||
/*!
|
||||
The following flags can be OR'ed together to allow a client to
|
||||
make changes to the default stream behavior:
|
||||
|
||||
- \e RTAUDIO_NONINTERLEAVED: Use non-interleaved buffers (default = interleaved).
|
||||
- \e RTAUDIO_MINIMIZE_LATENCY: Attempt to set stream parameters for lowest possible latency.
|
||||
- \e RTAUDIO_HOG_DEVICE: Attempt grab device for exclusive use.
|
||||
- \e RTAUDIO_SCHEDULE_REALTIME: Attempt to select realtime scheduling for callback thread.
|
||||
|
||||
By default, RtAudio streams pass and receive audio data from the
|
||||
client in an interleaved format. By passing the
|
||||
RTAUDIO_NONINTERLEAVED flag to the openStream() function, audio
|
||||
data will instead be presented in non-interleaved buffers. In
|
||||
this case, each buffer argument in the RtAudioCallback function
|
||||
will point to a single array of data, with \c nFrames samples for
|
||||
each channel concatenated back-to-back. For example, the first
|
||||
sample of data for the second channel would be located at index \c
|
||||
nFrames (assuming the \c buffer pointer was recast to the correct
|
||||
data type for the stream).
|
||||
|
||||
Certain audio APIs offer a number of parameters that influence the
|
||||
I/O latency of a stream. By default, RtAudio will attempt to set
|
||||
these parameters internally for robust (glitch-free) performance
|
||||
(though some APIs, like Windows Direct Sound, make this difficult).
|
||||
By passing the RTAUDIO_MINIMIZE_LATENCY flag to the openStream()
|
||||
function, internal stream settings will be influenced in an attempt
|
||||
to minimize stream latency, though possibly at the expense of stream
|
||||
performance.
|
||||
|
||||
If the RTAUDIO_HOG_DEVICE flag is set, RtAudio will attempt to
|
||||
open the input and/or output stream device(s) for exclusive use.
|
||||
Note that this is not possible with all supported audio APIs.
|
||||
|
||||
If the RTAUDIO_SCHEDULE_REALTIME flag is set, RtAudio will attempt
|
||||
to select realtime scheduling (round-robin) for the callback thread.
|
||||
The \c priority parameter will only be used if the RTAUDIO_SCHEDULE_REALTIME
|
||||
flag is set. It defines the thread's realtime priority.
|
||||
|
||||
The \c numberOfBuffers parameter can be used to control stream
|
||||
latency in the Windows DirectSound, Linux OSS, and Linux Alsa APIs
|
||||
only. A value of two is usually the smallest allowed. Larger
|
||||
numbers can potentially result in more robust stream performance,
|
||||
though likely at the cost of stream latency. The value set by the
|
||||
user is replaced during execution of the RtAudio::openStream()
|
||||
function by the value actually used by the system.
|
||||
|
||||
The \c streamName parameter can be used to set the client name
|
||||
when using the Jack API. By default, the client name is set to
|
||||
RtApiJack. However, if you wish to create multiple instances of
|
||||
RtAudio with Jack, each instance must have a unique client name.
|
||||
*/
|
||||
struct StreamOptions {
|
||||
RtAudioStreamFlags flags; /*!< A bit-mask of stream flags (RTAUDIO_NONINTERLEAVED, RTAUDIO_MINIMIZE_LATENCY, RTAUDIO_HOG_DEVICE). */
|
||||
unsigned int numberOfBuffers; /*!< Number of stream buffers. */
|
||||
std::string streamName; /*!< A stream name (currently used only in Jack). */
|
||||
int priority; /*!< Scheduling priority of callback thread (only used with flag RTAUDIO_SCHEDULE_REALTIME). */
|
||||
|
||||
// Default constructor.
|
||||
StreamOptions()
|
||||
: flags(0), numberOfBuffers(0), priority(0) {}
|
||||
};
|
||||
|
||||
//! A static function to determine the available compiled audio APIs.
|
||||
/*!
|
||||
The values returned in the std::vector can be compared against
|
||||
the enumerated list values. Note that there can be more than one
|
||||
API compiled for certain operating systems.
|
||||
*/
|
||||
static void getCompiledApi( std::vector<RtAudio::Api> &apis ) throw();
|
||||
|
||||
//! The class constructor.
|
||||
/*!
|
||||
The constructor performs minor initialization tasks. No exceptions
|
||||
can be thrown.
|
||||
|
||||
If no API argument is specified and multiple API support has been
|
||||
compiled, the default order of use is JACK, ALSA, OSS (Linux
|
||||
systems) and ASIO, DS (Windows systems).
|
||||
*/
|
||||
RtAudio( RtAudio::Api api=UNSPECIFIED ) throw();
|
||||
|
||||
//! The destructor.
|
||||
/*!
|
||||
If a stream is running or open, it will be stopped and closed
|
||||
automatically.
|
||||
*/
|
||||
~RtAudio() throw();
|
||||
|
||||
//! Returns the audio API specifier for the current instance of RtAudio.
|
||||
RtAudio::Api getCurrentApi( void ) throw();
|
||||
|
||||
//! A public function that queries for the number of audio devices available.
|
||||
/*!
|
||||
This function performs a system query of available devices each time it
|
||||
is called, thus supporting devices connected \e after instantiation. If
|
||||
a system error occurs during processing, a warning will be issued.
|
||||
*/
|
||||
unsigned int getDeviceCount( void ) throw();
|
||||
|
||||
//! Return an RtAudio::DeviceInfo structure for a specified device number.
|
||||
/*!
|
||||
|
||||
Any device integer between 0 and getDeviceCount() - 1 is valid.
|
||||
If an invalid argument is provided, an RtError (type = INVALID_USE)
|
||||
will be thrown. If a device is busy or otherwise unavailable, the
|
||||
structure member "probed" will have a value of "false" and all
|
||||
other members are undefined. If the specified device is the
|
||||
current default input or output device, the corresponding
|
||||
"isDefault" member will have a value of "true".
|
||||
*/
|
||||
RtAudio::DeviceInfo getDeviceInfo( unsigned int device );
|
||||
|
||||
//! A function that returns the index of the default output device.
|
||||
/*!
|
||||
If the underlying audio API does not provide a "default
|
||||
device", or if no devices are available, the return value will be
|
||||
0. Note that this is a valid device identifier and it is the
|
||||
client's responsibility to verify that a device is available
|
||||
before attempting to open a stream.
|
||||
*/
|
||||
unsigned int getDefaultOutputDevice( void ) throw();
|
||||
|
||||
//! A function that returns the index of the default input device.
|
||||
/*!
|
||||
If the underlying audio API does not provide a "default
|
||||
device", or if no devices are available, the return value will be
|
||||
0. Note that this is a valid device identifier and it is the
|
||||
client's responsibility to verify that a device is available
|
||||
before attempting to open a stream.
|
||||
*/
|
||||
unsigned int getDefaultInputDevice( void ) throw();
|
||||
|
||||
//! A public function for opening a stream with the specified parameters.
|
||||
/*!
|
||||
An RtError (type = SYSTEM_ERROR) is thrown if a stream cannot be
|
||||
opened with the specified parameters or an error occurs during
|
||||
processing. An RtError (type = INVALID_USE) is thrown if any
|
||||
invalid device ID or channel number parameters are specified.
|
||||
|
||||
\param outputParameters Specifies output stream parameters to use
|
||||
when opening a stream, including a device ID, number of channels,
|
||||
and starting channel number. For input-only streams, this
|
||||
argument should be NULL. The device ID is an index value between
|
||||
0 and getDeviceCount() - 1.
|
||||
\param inputParameters Specifies input stream parameters to use
|
||||
when opening a stream, including a device ID, number of channels,
|
||||
and starting channel number. For output-only streams, this
|
||||
argument should be NULL. The device ID is an index value between
|
||||
0 and getDeviceCount() - 1.
|
||||
\param format An RtAudioFormat specifying the desired sample data format.
|
||||
\param sampleRate The desired sample rate (sample frames per second).
|
||||
\param *bufferFrames A pointer to a value indicating the desired
|
||||
internal buffer size in sample frames. The actual value
|
||||
used by the device is returned via the same pointer. A
|
||||
value of zero can be specified, in which case the lowest
|
||||
allowable value is determined.
|
||||
\param callback A client-defined function that will be invoked
|
||||
when input data is available and/or output data is needed.
|
||||
\param userData An optional pointer to data that can be accessed
|
||||
from within the callback function.
|
||||
\param options An optional pointer to a structure containing various
|
||||
global stream options, including a list of OR'ed RtAudioStreamFlags
|
||||
and a suggested number of stream buffers that can be used to
|
||||
control stream latency. More buffers typically result in more
|
||||
robust performance, though at a cost of greater latency. If a
|
||||
value of zero is specified, a system-specific median value is
|
||||
chosen. If the RTAUDIO_MINIMIZE_LATENCY flag bit is set, the
|
||||
lowest allowable value is used. The actual value used is
|
||||
returned via the structure argument. The parameter is API dependent.
|
||||
*/
|
||||
void openStream( RtAudio::StreamParameters *outputParameters,
|
||||
RtAudio::StreamParameters *inputParameters,
|
||||
RtAudioFormat format, unsigned int sampleRate,
|
||||
unsigned int *bufferFrames, RtAudioCallback callback,
|
||||
void *userData = NULL, RtAudio::StreamOptions *options = NULL );
|
||||
|
||||
//! A function that closes a stream and frees any associated stream memory.
|
||||
/*!
|
||||
If a stream is not open, this function issues a warning and
|
||||
returns (no exception is thrown).
|
||||
*/
|
||||
void closeStream( void ) throw();
|
||||
|
||||
//! A function that starts a stream.
|
||||
/*!
|
||||
An RtError (type = SYSTEM_ERROR) is thrown if an error occurs
|
||||
during processing. An RtError (type = INVALID_USE) is thrown if a
|
||||
stream is not open. A warning is issued if the stream is already
|
||||
running.
|
||||
*/
|
||||
void startStream( void );
|
||||
|
||||
//! Stop a stream, allowing any samples remaining in the output queue to be played.
|
||||
/*!
|
||||
An RtError (type = SYSTEM_ERROR) is thrown if an error occurs
|
||||
during processing. An RtError (type = INVALID_USE) is thrown if a
|
||||
stream is not open. A warning is issued if the stream is already
|
||||
stopped.
|
||||
*/
|
||||
void stopStream( void );
|
||||
|
||||
//! Stop a stream, discarding any samples remaining in the input/output queue.
|
||||
/*!
|
||||
An RtError (type = SYSTEM_ERROR) is thrown if an error occurs
|
||||
during processing. An RtError (type = INVALID_USE) is thrown if a
|
||||
stream is not open. A warning is issued if the stream is already
|
||||
stopped.
|
||||
*/
|
||||
void abortStream( void );
|
||||
|
||||
//! Returns true if a stream is open and false if not.
|
||||
bool isStreamOpen( void ) const throw();
|
||||
|
||||
//! Returns true if the stream is running and false if it is stopped or not open.
|
||||
bool isStreamRunning( void ) const throw();
|
||||
|
||||
//! Returns the number of elapsed seconds since the stream was started.
|
||||
/*!
|
||||
If a stream is not open, an RtError (type = INVALID_USE) will be thrown.
|
||||
*/
|
||||
double getStreamTime( void );
|
||||
|
||||
//! Returns the internal stream latency in sample frames.
|
||||
/*!
|
||||
The stream latency refers to delay in audio input and/or output
|
||||
caused by internal buffering by the audio system and/or hardware.
|
||||
For duplex streams, the returned value will represent the sum of
|
||||
the input and output latencies. If a stream is not open, an
|
||||
RtError (type = INVALID_USE) will be thrown. If the API does not
|
||||
report latency, the return value will be zero.
|
||||
*/
|
||||
long getStreamLatency( void );
|
||||
|
||||
//! Returns actual sample rate in use by the stream.
|
||||
/*!
|
||||
On some systems, the sample rate used may be slightly different
|
||||
than that specified in the stream parameters. If a stream is not
|
||||
open, an RtError (type = INVALID_USE) will be thrown.
|
||||
*/
|
||||
unsigned int getStreamSampleRate( void );
|
||||
|
||||
//! Specify whether warning messages should be printed to stderr.
|
||||
void showWarnings( bool value = true ) throw();
|
||||
|
||||
protected:
|
||||
|
||||
void openRtApi( RtAudio::Api api );
|
||||
RtApi *rtapi_;
|
||||
};
|
||||
|
||||
// Operating system dependent thread functionality.
|
||||
#if defined(__WINDOWS_DS__) || defined(__WINDOWS_ASIO__)
|
||||
#include <windows.h>
|
||||
#include <process.h>
|
||||
|
||||
typedef unsigned long ThreadHandle;
|
||||
typedef CRITICAL_SECTION StreamMutex;
|
||||
|
||||
#elif defined(__LINUX_ALSA__) || defined(__UNIX_JACK__) || defined(__LINUX_OSS__) || defined(__MACOSX_CORE__)
|
||||
// Using pthread library for various flavors of unix.
|
||||
#include <pthread.h>
|
||||
|
||||
typedef pthread_t ThreadHandle;
|
||||
typedef pthread_mutex_t StreamMutex;
|
||||
|
||||
#else // Setup for "dummy" behavior
|
||||
|
||||
#define __RTAUDIO_DUMMY__
|
||||
typedef int ThreadHandle;
|
||||
typedef int StreamMutex;
|
||||
|
||||
#endif
|
||||
|
||||
// This global structure type is used to pass callback information
|
||||
// between the private RtAudio stream structure and global callback
|
||||
// handling functions.
|
||||
struct CallbackInfo {
|
||||
void *object; // Used as a "this" pointer.
|
||||
ThreadHandle thread;
|
||||
void *callback;
|
||||
void *userData;
|
||||
void *apiInfo; // void pointer for API specific callback information
|
||||
bool isRunning;
|
||||
|
||||
// Default constructor.
|
||||
CallbackInfo()
|
||||
:object(0), callback(0), userData(0), apiInfo(0), isRunning(false) {}
|
||||
};
|
||||
|
||||
// **************************************************************** //
|
||||
//
|
||||
// RtApi class declaration.
|
||||
//
|
||||
// Subclasses of RtApi contain all API- and OS-specific code necessary
|
||||
// to fully implement the RtAudio API.
|
||||
//
|
||||
// Note that RtApi is an abstract base class and cannot be
|
||||
// explicitly instantiated. The class RtAudio will create an
|
||||
// instance of an RtApi subclass (RtApiOss, RtApiAlsa,
|
||||
// RtApiJack, RtApiCore, RtApiAl, RtApiDs, or RtApiAsio).
|
||||
//
|
||||
// **************************************************************** //
|
||||
|
||||
#if defined( HAVE_GETTIMEOFDAY )
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#include <sstream>
|
||||
|
||||
class RtApi
|
||||
{
|
||||
public:
|
||||
|
||||
RtApi();
|
||||
virtual ~RtApi();
|
||||
virtual RtAudio::Api getCurrentApi( void ) = 0;
|
||||
virtual unsigned int getDeviceCount( void ) = 0;
|
||||
virtual RtAudio::DeviceInfo getDeviceInfo( unsigned int device ) = 0;
|
||||
virtual unsigned int getDefaultInputDevice( void );
|
||||
virtual unsigned int getDefaultOutputDevice( void );
|
||||
void openStream( RtAudio::StreamParameters *outputParameters,
|
||||
RtAudio::StreamParameters *inputParameters,
|
||||
RtAudioFormat format, unsigned int sampleRate,
|
||||
unsigned int *bufferFrames, RtAudioCallback callback,
|
||||
void *userData, RtAudio::StreamOptions *options );
|
||||
virtual void closeStream( void );
|
||||
virtual void startStream( void ) = 0;
|
||||
virtual void stopStream( void ) = 0;
|
||||
virtual void abortStream( void ) = 0;
|
||||
long getStreamLatency( void );
|
||||
unsigned int getStreamSampleRate( void );
|
||||
virtual double getStreamTime( void );
|
||||
bool isStreamOpen( void ) const { return stream_.state != STREAM_CLOSED; };
|
||||
bool isStreamRunning( void ) const { return stream_.state == STREAM_RUNNING; };
|
||||
void showWarnings( bool value ) { showWarnings_ = value; };
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
static const unsigned int MAX_SAMPLE_RATES;
|
||||
static const unsigned int SAMPLE_RATES[];
|
||||
|
||||
enum { FAILURE, SUCCESS };
|
||||
|
||||
enum StreamState {
|
||||
STREAM_STOPPED,
|
||||
STREAM_RUNNING,
|
||||
STREAM_CLOSED = -50
|
||||
};
|
||||
|
||||
enum StreamMode {
|
||||
OUTPUT,
|
||||
INPUT,
|
||||
DUPLEX,
|
||||
UNINITIALIZED = -75
|
||||
};
|
||||
|
||||
// A protected structure used for buffer conversion.
|
||||
struct ConvertInfo {
|
||||
int channels;
|
||||
int inJump, outJump;
|
||||
RtAudioFormat inFormat, outFormat;
|
||||
std::vector<int> inOffset;
|
||||
std::vector<int> outOffset;
|
||||
};
|
||||
|
||||
// A protected structure for audio streams.
|
||||
struct RtApiStream {
|
||||
unsigned int device[2]; // Playback and record, respectively.
|
||||
void *apiHandle; // void pointer for API specific stream handle information
|
||||
StreamMode mode; // OUTPUT, INPUT, or DUPLEX.
|
||||
StreamState state; // STOPPED, RUNNING, or CLOSED
|
||||
char *userBuffer[2]; // Playback and record, respectively.
|
||||
char *deviceBuffer;
|
||||
bool doConvertBuffer[2]; // Playback and record, respectively.
|
||||
bool userInterleaved;
|
||||
bool deviceInterleaved[2]; // Playback and record, respectively.
|
||||
bool doByteSwap[2]; // Playback and record, respectively.
|
||||
unsigned int sampleRate;
|
||||
unsigned int bufferSize;
|
||||
unsigned int nBuffers;
|
||||
unsigned int nUserChannels[2]; // Playback and record, respectively.
|
||||
unsigned int nDeviceChannels[2]; // Playback and record channels, respectively.
|
||||
unsigned int channelOffset[2]; // Playback and record, respectively.
|
||||
unsigned long latency[2]; // Playback and record, respectively.
|
||||
RtAudioFormat userFormat;
|
||||
RtAudioFormat deviceFormat[2]; // Playback and record, respectively.
|
||||
StreamMutex mutex;
|
||||
CallbackInfo callbackInfo;
|
||||
ConvertInfo convertInfo[2];
|
||||
double streamTime; // Number of elapsed seconds since the stream started.
|
||||
|
||||
#if defined(HAVE_GETTIMEOFDAY)
|
||||
struct timeval lastTickTimestamp;
|
||||
#endif
|
||||
|
||||
RtApiStream()
|
||||
:apiHandle(0), deviceBuffer(0) { device[0] = 11111; device[1] = 11111; }
|
||||
};
|
||||
|
||||
typedef signed short Int16;
|
||||
typedef signed int Int32;
|
||||
typedef float Float32;
|
||||
typedef double Float64;
|
||||
|
||||
std::ostringstream errorStream_;
|
||||
std::string errorText_;
|
||||
bool showWarnings_;
|
||||
RtApiStream stream_;
|
||||
|
||||
/*!
|
||||
Protected, api-specific method that attempts to open a device
|
||||
with the given parameters. This function MUST be implemented by
|
||||
all subclasses. If an error is encountered during the probe, a
|
||||
"warning" message is reported and FAILURE is returned. A
|
||||
successful probe is indicated by a return value of SUCCESS.
|
||||
*/
|
||||
virtual bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
|
||||
unsigned int firstChannel, unsigned int sampleRate,
|
||||
RtAudioFormat format, unsigned int *bufferSize,
|
||||
RtAudio::StreamOptions *options );
|
||||
|
||||
//! A protected function used to increment the stream time.
|
||||
void tickStreamTime( void );
|
||||
|
||||
//! Protected common method to clear an RtApiStream structure.
|
||||
void clearStreamInfo();
|
||||
|
||||
/*!
|
||||
Protected common method that throws an RtError (type =
|
||||
INVALID_USE) if a stream is not open.
|
||||
*/
|
||||
void verifyStream( void );
|
||||
|
||||
//! Protected common error method to allow global control over error handling.
|
||||
void error( RtError::Type type );
|
||||
|
||||
/*!
|
||||
Protected method used to perform format, channel number, and/or interleaving
|
||||
conversions between the user and device buffers.
|
||||
*/
|
||||
void convertBuffer( char *outBuffer, char *inBuffer, ConvertInfo &info );
|
||||
|
||||
//! Protected common method used to perform byte-swapping on buffers.
|
||||
void byteSwapBuffer( char *buffer, unsigned int samples, RtAudioFormat format );
|
||||
|
||||
//! Protected common method that returns the number of bytes for a given format.
|
||||
unsigned int formatBytes( RtAudioFormat format );
|
||||
|
||||
//! Protected common method that sets up the parameters for buffer conversion.
|
||||
void setConvertInfo( StreamMode mode, unsigned int firstChannel );
|
||||
};
|
||||
|
||||
// **************************************************************** //
|
||||
//
|
||||
// Inline RtAudio definitions.
|
||||
//
|
||||
// **************************************************************** //
|
||||
|
||||
inline RtAudio::Api RtAudio :: getCurrentApi( void ) throw() { return rtapi_->getCurrentApi(); }
|
||||
inline unsigned int RtAudio :: getDeviceCount( void ) throw() { return rtapi_->getDeviceCount(); }
|
||||
inline RtAudio::DeviceInfo RtAudio :: getDeviceInfo( unsigned int device ) { return rtapi_->getDeviceInfo( device ); }
|
||||
inline unsigned int RtAudio :: getDefaultInputDevice( void ) throw() { return rtapi_->getDefaultInputDevice(); }
|
||||
inline unsigned int RtAudio :: getDefaultOutputDevice( void ) throw() { return rtapi_->getDefaultOutputDevice(); }
|
||||
inline void RtAudio :: closeStream( void ) throw() { return rtapi_->closeStream(); }
|
||||
inline void RtAudio :: startStream( void ) { return rtapi_->startStream(); }
|
||||
inline void RtAudio :: stopStream( void ) { return rtapi_->stopStream(); }
|
||||
inline void RtAudio :: abortStream( void ) { return rtapi_->abortStream(); }
|
||||
inline bool RtAudio :: isStreamOpen( void ) const throw() { return rtapi_->isStreamOpen(); }
|
||||
inline bool RtAudio :: isStreamRunning( void ) const throw() { return rtapi_->isStreamRunning(); }
|
||||
inline long RtAudio :: getStreamLatency( void ) { return rtapi_->getStreamLatency(); }
|
||||
inline unsigned int RtAudio :: getStreamSampleRate( void ) { return rtapi_->getStreamSampleRate(); };
|
||||
inline double RtAudio :: getStreamTime( void ) { return rtapi_->getStreamTime(); }
|
||||
inline void RtAudio :: showWarnings( bool value ) throw() { rtapi_->showWarnings( value ); }
|
||||
|
||||
// RtApi Subclass prototypes.
|
||||
|
||||
#if defined(__MACOSX_CORE__)
|
||||
|
||||
#include <CoreAudio/AudioHardware.h>
|
||||
|
||||
class RtApiCore: public RtApi
|
||||
{
|
||||
public:
|
||||
|
||||
RtApiCore();
|
||||
~RtApiCore();
|
||||
RtAudio::Api getCurrentApi( void ) { return RtAudio::MACOSX_CORE; };
|
||||
unsigned int getDeviceCount( void );
|
||||
RtAudio::DeviceInfo getDeviceInfo( unsigned int device );
|
||||
unsigned int getDefaultOutputDevice( void );
|
||||
unsigned int getDefaultInputDevice( void );
|
||||
void closeStream( void );
|
||||
void startStream( void );
|
||||
void stopStream( void );
|
||||
void abortStream( void );
|
||||
long getStreamLatency( void );
|
||||
|
||||
// This function is intended for internal use only. It must be
|
||||
// public because it is called by the internal callback handler,
|
||||
// which is not a member of RtAudio. External use of this function
|
||||
// will most likely produce highly undesireable results!
|
||||
bool callbackEvent( AudioDeviceID deviceId,
|
||||
const AudioBufferList *inBufferList,
|
||||
const AudioBufferList *outBufferList );
|
||||
|
||||
private:
|
||||
|
||||
bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
|
||||
unsigned int firstChannel, unsigned int sampleRate,
|
||||
RtAudioFormat format, unsigned int *bufferSize,
|
||||
RtAudio::StreamOptions *options );
|
||||
static const char* getErrorCode( OSStatus code );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(__UNIX_JACK__)
|
||||
|
||||
class RtApiJack: public RtApi
|
||||
{
|
||||
public:
|
||||
|
||||
RtApiJack();
|
||||
~RtApiJack();
|
||||
RtAudio::Api getCurrentApi( void ) { return RtAudio::UNIX_JACK; };
|
||||
unsigned int getDeviceCount( void );
|
||||
RtAudio::DeviceInfo getDeviceInfo( unsigned int device );
|
||||
void closeStream( void );
|
||||
void startStream( void );
|
||||
void stopStream( void );
|
||||
void abortStream( void );
|
||||
long getStreamLatency( void );
|
||||
|
||||
// This function is intended for internal use only. It must be
|
||||
// public because it is called by the internal callback handler,
|
||||
// which is not a member of RtAudio. External use of this function
|
||||
// will most likely produce highly undesireable results!
|
||||
bool callbackEvent( unsigned long nframes );
|
||||
|
||||
private:
|
||||
|
||||
bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
|
||||
unsigned int firstChannel, unsigned int sampleRate,
|
||||
RtAudioFormat format, unsigned int *bufferSize,
|
||||
RtAudio::StreamOptions *options );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(__WINDOWS_ASIO__)
|
||||
|
||||
class RtApiAsio: public RtApi
|
||||
{
|
||||
public:
|
||||
|
||||
RtApiAsio();
|
||||
~RtApiAsio();
|
||||
RtAudio::Api getCurrentApi( void ) { return RtAudio::WINDOWS_ASIO; };
|
||||
unsigned int getDeviceCount( void );
|
||||
RtAudio::DeviceInfo getDeviceInfo( unsigned int device );
|
||||
void closeStream( void );
|
||||
void startStream( void );
|
||||
void stopStream( void );
|
||||
void abortStream( void );
|
||||
long getStreamLatency( void );
|
||||
|
||||
// This function is intended for internal use only. It must be
|
||||
// public because it is called by the internal callback handler,
|
||||
// which is not a member of RtAudio. External use of this function
|
||||
// will most likely produce highly undesireable results!
|
||||
bool callbackEvent( long bufferIndex );
|
||||
|
||||
private:
|
||||
|
||||
std::vector<RtAudio::DeviceInfo> devices_;
|
||||
void saveDeviceInfo( void );
|
||||
bool coInitialized_;
|
||||
bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
|
||||
unsigned int firstChannel, unsigned int sampleRate,
|
||||
RtAudioFormat format, unsigned int *bufferSize,
|
||||
RtAudio::StreamOptions *options );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(__WINDOWS_DS__)
|
||||
|
||||
class RtApiDs: public RtApi
|
||||
{
|
||||
public:
|
||||
|
||||
RtApiDs();
|
||||
~RtApiDs();
|
||||
RtAudio::Api getCurrentApi( void ) { return RtAudio::WINDOWS_DS; };
|
||||
unsigned int getDeviceCount( void );
|
||||
unsigned int getDefaultOutputDevice( void );
|
||||
unsigned int getDefaultInputDevice( void );
|
||||
RtAudio::DeviceInfo getDeviceInfo( unsigned int device );
|
||||
void closeStream( void );
|
||||
void startStream( void );
|
||||
void stopStream( void );
|
||||
void abortStream( void );
|
||||
long getStreamLatency( void );
|
||||
|
||||
// This function is intended for internal use only. It must be
|
||||
// public because it is called by the internal callback handler,
|
||||
// which is not a member of RtAudio. External use of this function
|
||||
// will most likely produce highly undesireable results!
|
||||
void callbackEvent( void );
|
||||
|
||||
private:
|
||||
|
||||
bool coInitialized_;
|
||||
bool buffersRolling;
|
||||
long duplexPrerollBytes;
|
||||
bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
|
||||
unsigned int firstChannel, unsigned int sampleRate,
|
||||
RtAudioFormat format, unsigned int *bufferSize,
|
||||
RtAudio::StreamOptions *options );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(__LINUX_ALSA__)
|
||||
|
||||
class RtApiAlsa: public RtApi
|
||||
{
|
||||
public:
|
||||
|
||||
RtApiAlsa();
|
||||
~RtApiAlsa();
|
||||
RtAudio::Api getCurrentApi() { return RtAudio::LINUX_ALSA; };
|
||||
unsigned int getDeviceCount( void );
|
||||
RtAudio::DeviceInfo getDeviceInfo( unsigned int device );
|
||||
void closeStream( void );
|
||||
void startStream( void );
|
||||
void stopStream( void );
|
||||
void abortStream( void );
|
||||
|
||||
// This function is intended for internal use only. It must be
|
||||
// public because it is called by the internal callback handler,
|
||||
// which is not a member of RtAudio. External use of this function
|
||||
// will most likely produce highly undesireable results!
|
||||
void callbackEvent( void );
|
||||
|
||||
private:
|
||||
|
||||
std::vector<RtAudio::DeviceInfo> devices_;
|
||||
void saveDeviceInfo( void );
|
||||
bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
|
||||
unsigned int firstChannel, unsigned int sampleRate,
|
||||
RtAudioFormat format, unsigned int *bufferSize,
|
||||
RtAudio::StreamOptions *options );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(__LINUX_OSS__)
|
||||
|
||||
class RtApiOss: public RtApi
|
||||
{
|
||||
public:
|
||||
|
||||
RtApiOss();
|
||||
~RtApiOss();
|
||||
RtAudio::Api getCurrentApi() { return RtAudio::LINUX_OSS; };
|
||||
unsigned int getDeviceCount( void );
|
||||
RtAudio::DeviceInfo getDeviceInfo( unsigned int device );
|
||||
void closeStream( void );
|
||||
void startStream( void );
|
||||
void stopStream( void );
|
||||
void abortStream( void );
|
||||
|
||||
// This function is intended for internal use only. It must be
|
||||
// public because it is called by the internal callback handler,
|
||||
// which is not a member of RtAudio. External use of this function
|
||||
// will most likely produce highly undesireable results!
|
||||
void callbackEvent( void );
|
||||
|
||||
private:
|
||||
|
||||
bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
|
||||
unsigned int firstChannel, unsigned int sampleRate,
|
||||
RtAudioFormat format, unsigned int *bufferSize,
|
||||
RtAudio::StreamOptions *options );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(__RTAUDIO_DUMMY__)
|
||||
|
||||
class RtApiDummy: public RtApi
|
||||
{
|
||||
public:
|
||||
|
||||
RtApiDummy() { errorText_ = "RtApiDummy: This class provides no functionality."; error( RtError::WARNING ); };
|
||||
RtAudio::Api getCurrentApi( void ) { return RtAudio::RTAUDIO_DUMMY; };
|
||||
unsigned int getDeviceCount( void ) { return 0; };
|
||||
RtAudio::DeviceInfo getDeviceInfo( unsigned int device ) { RtAudio::DeviceInfo info; return info; };
|
||||
void closeStream( void ) {};
|
||||
void startStream( void ) {};
|
||||
void stopStream( void ) {};
|
||||
void abortStream( void ) {};
|
||||
|
||||
private:
|
||||
|
||||
bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
|
||||
unsigned int firstChannel, unsigned int sampleRate,
|
||||
RtAudioFormat format, unsigned int *bufferSize,
|
||||
RtAudio::StreamOptions *options ) { return false; };
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
// Indentation settings for Vim and Emacs
|
||||
//
|
||||
// Local Variables:
|
||||
// c-basic-offset: 2
|
||||
// indent-tabs-mode: nil
|
||||
// End:
|
||||
//
|
||||
// vim: et sts=2 sw=2
|
60
thirdparty/rtaudio/RtError.h
vendored
60
thirdparty/rtaudio/RtError.h
vendored
@ -1,60 +0,0 @@
|
||||
/************************************************************************/
|
||||
/*! \class RtError
|
||||
\brief Exception handling class for RtAudio & RtMidi.
|
||||
|
||||
The RtError class is quite simple but it does allow errors to be
|
||||
"caught" by RtError::Type. See the RtAudio and RtMidi
|
||||
documentation to know which methods can throw an RtError.
|
||||
|
||||
*/
|
||||
/************************************************************************/
|
||||
|
||||
#ifndef RTERROR_H
|
||||
#define RTERROR_H
|
||||
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
class RtError : public std::exception
|
||||
{
|
||||
public:
|
||||
//! Defined RtError types.
|
||||
enum Type {
|
||||
WARNING, /*!< A non-critical error. */
|
||||
DEBUG_WARNING, /*!< A non-critical error which might be useful for debugging. */
|
||||
UNSPECIFIED, /*!< The default, unspecified error type. */
|
||||
NO_DEVICES_FOUND, /*!< No devices found on system. */
|
||||
INVALID_DEVICE, /*!< An invalid device ID was specified. */
|
||||
MEMORY_ERROR, /*!< An error occured during memory allocation. */
|
||||
INVALID_PARAMETER, /*!< An invalid parameter was specified to a function. */
|
||||
INVALID_USE, /*!< The function was called incorrectly. */
|
||||
DRIVER_ERROR, /*!< A system driver error occured. */
|
||||
SYSTEM_ERROR, /*!< A system error occured. */
|
||||
THREAD_ERROR /*!< A thread error occured. */
|
||||
};
|
||||
|
||||
//! The constructor.
|
||||
RtError( const std::string& message, Type type = RtError::UNSPECIFIED ) throw() : message_(message), type_(type) {}
|
||||
|
||||
//! The destructor.
|
||||
virtual ~RtError( void ) throw() {}
|
||||
|
||||
//! Prints thrown error message to stderr.
|
||||
virtual void printMessage( void ) throw() { std::cerr << '\n' << message_ << "\n\n"; }
|
||||
|
||||
//! Returns the thrown error message type.
|
||||
virtual const Type& getType(void) throw() { return type_; }
|
||||
|
||||
//! Returns the thrown error message string.
|
||||
virtual const std::string& getMessage(void) throw() { return message_; }
|
||||
|
||||
//! Returns the thrown error message as a c-style string.
|
||||
virtual const char* what( void ) const throw() { return message_.c_str(); }
|
||||
|
||||
protected:
|
||||
std::string message_;
|
||||
Type type_;
|
||||
};
|
||||
|
||||
#endif
|
61
thirdparty/rtaudio/readme
vendored
61
thirdparty/rtaudio/readme
vendored
@ -1,61 +0,0 @@
|
||||
RtAudio - a set of C++ classes that provide a common API for realtime audio input/output across Linux (native ALSA, JACK, and OSS), Macintosh OS X (CoreAudio and JACK), and Windows (DirectSound and ASIO) operating systems.
|
||||
|
||||
By Gary P. Scavone, 2001-2010.
|
||||
|
||||
This distribution of RtAudio contains the following:
|
||||
|
||||
doc: RtAudio documentation (see doc/html/index.html)
|
||||
tests: example RtAudio programs
|
||||
asio: header and source files necessary for ASIO compilation
|
||||
tests/Windows: Visual C++ .net test program workspace and projects
|
||||
|
||||
OVERVIEW:
|
||||
|
||||
RtAudio is a set of C++ classes that provides a common API (Application Programming Interface) for realtime audio input/output across Linux (native ALSA, JACK, and OSS), Macintosh OS X, SGI, and Windows (DirectSound and ASIO) operating systems. RtAudio significantly simplifies the process of interacting with computer audio hardware. It was designed with the following objectives:
|
||||
|
||||
- object-oriented C++ design
|
||||
- simple, common API across all supported platforms
|
||||
- only one source and two header files for easy inclusion in programming projects
|
||||
- allow simultaneous multi-api support
|
||||
- support dynamic connection of devices
|
||||
- provide extensive audio device parameter control
|
||||
- allow audio device capability probing
|
||||
- automatic internal conversion for data format, channel number compensation, (de)interleaving, and byte-swapping
|
||||
|
||||
RtAudio incorporates the concept of audio streams, which represent audio output (playback) and/or input (recording). Available audio devices and their capabilities can be enumerated and then specified when opening a stream. Where applicable, multiple API support can be compiled and a particular API specified when creating an RtAudio instance. See the \ref apinotes section for information specific to each of the supported audio APIs.
|
||||
|
||||
FURTHER READING:
|
||||
|
||||
For complete documentation on RtAudio, see the doc directory of the distribution or surf to http://www.music.mcgill.ca/~gary/rtaudio/.
|
||||
|
||||
|
||||
LEGAL AND ETHICAL:
|
||||
|
||||
The RtAudio license is similar to the MIT License.
|
||||
|
||||
RtAudio: a set of realtime audio i/o C++ classes
|
||||
Copyright (c) 2001-2010 Gary P. Scavone
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation files
|
||||
(the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge,
|
||||
publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
Any person wishing to distribute modifications to the Software is
|
||||
asked to send the modifications to the original developer so that
|
||||
they can be incorporated into the canonical version. This is,
|
||||
however, not a binding provision of this license.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
|
||||
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
||||
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
Loading…
x
Reference in New Issue
Block a user