Commit a7f907ef authored by Geoffroy Lacarriere's avatar Geoffroy Lacarriere

Add of the sound graph on the timeline. It's unstable for the moment so it's...

Add of the sound graph on the timeline. It's unstable for the moment so it's not activated by default.
To activate the sound graph rendering, uncomment the startAudioDataParsing() line on the MetaDataManager.cpp
parent 6f1cc172
......@@ -139,3 +139,32 @@ void Media::setHeight( int height )
m_height = height;
}
void Media::initAudioData( void* datas, unsigned int* freq, unsigned int* nbChannels, unsigned int* fourCCFormat, unsigned int* frameSize )
{
m_audioData.freq = freq;
m_audioData.nbChannels = nbChannels;
m_audioData.frameSize = frameSize;
m_audioData.fourCCFormat = fourCCFormat;
m_audioData.datas = datas;
}
void Media::addAudioFrame( void* datas, unsigned char* buffer, size_t buffSize, unsigned int nbSample )
{
m_audioData.nbSample = nbSample;
m_audioData.buffSize = buffSize;
int* frame = new int[ m_audioData.buffSize ];
for (int i = 0, u = 0; u < m_audioData.nbSample; i += 4, u++)
{
int value = buffer[i];
value << 8;
value += buffer[i + 1];
value << 8;
value += buffer[i + 2];
value << 8;
value += buffer[i + 3];
frame[u] = value;
}
m_audioData.frameList.append( frame );
// qDebug() << m_audioData.frameList.size();
}
......@@ -38,6 +38,19 @@
#include "VLCMedia.h"
struct audioData
{
void* datas;
unsigned int* freq;
unsigned int* nbChannels;
unsigned int* fourCCFormat;
unsigned int* frameSize;
unsigned int nbSample;
unsigned char* buffer;
size_t buffSize;
QVector<int*> frameList;
};
/**
* Represents a basic container for media informations.
*/
......@@ -71,6 +84,13 @@ public:
const QUuid& getUuid() const;
void initAudioData( void* datas, unsigned int* freq, unsigned int* nbChannels, unsigned int* fourCCFormat, unsigned int* frameSize );
void addAudioFrame( void* datas, unsigned char* buffer, size_t buffSize, unsigned int nbSample );
audioData* getAudioData() { return &m_audioData; }
QVector<int*> getAudioFrameList() { return m_audioData.frameList; }
unsigned int getAudioNbSample() { return m_audioData.nbSample; }
protected:
static QPixmap* defaultSnapshot;
......@@ -83,6 +103,8 @@ protected:
qint64 m_length;
unsigned int m_width;
unsigned int m_height;
int* m_audioSpectrum;
audioData m_audioData;
signals:
void snapshotChanged();
......
......@@ -29,7 +29,6 @@
#include "MetaDataManager.h"
#include "Library.h"
MetaDataManager::MetaDataManager() : m_renderWidget( NULL )
{
m_mediaPlayer = new LibVLCpp::MediaPlayer();
......@@ -132,7 +131,7 @@ void MetaDataManager::setSnapshot()
qDebug() << "Stopping playback";
m_mediaPlayer->stop();
// startAudioDataParsing();
//startAudioDataParsing();
}
void MetaDataManager::startAudioDataParsing()
......@@ -140,7 +139,7 @@ void MetaDataManager::startAudioDataParsing()
qDebug() << "Starting audio parsing";
char osb[64], psb[64], csb[64], iph[64], data[64];
disconnect( m_mediaPlayer, SIGNAL( stopped() ), this, SLOT( startAudioDataParsing() ) );
// disconnect( m_mediaPlayer, SIGNAL( stopped() ), this, SLOT( startAudioDataParsing() ) );
//Deactivating video, so that real time doesn't matter
sprintf( osb, ":amem-opensb=%lld", (long long int)(intptr_t) &MetaDataManager::openSoundBuffer);
......@@ -148,8 +147,8 @@ void MetaDataManager::startAudioDataParsing()
sprintf( csb, ":amem-closesb=%lld", (long long int)(intptr_t) &MetaDataManager::closeSoundBuffer);
sprintf( iph, ":amem-iph=%lld", (long long int)(intptr_t) &MetaDataManager::instanceParameterHandler);
sprintf( data, ":amem-data=%lld", (long long int)(intptr_t) this);
// m_currentClip->addParam( ":no-video" );
// m_currentClip->addParam( ":audio" );
m_currentClip->addParam( ":no-video" );
m_currentClip->addParam( ":audio" );
m_currentClip->addParam( ":aout=amem" );
m_currentClip->addParam( osb );
m_currentClip->addParam( psb );
......@@ -159,27 +158,40 @@ void MetaDataManager::startAudioDataParsing()
m_currentClip->flushParameters();
m_mediaPlayer->setMedia( m_currentClip->getVLCMedia() );
connect( m_mediaPlayer, SIGNAL( endReached() ), this, SLOT( stopAudioDataParsing() ) );
qDebug() << "Starting playback again";
m_mediaPlayer->play();
//Restoring the clip at a correct value.
// m_currentClip->addParam( ":video" );
m_currentClip->addParam( ":video" );
}
void MetaDataManager::openSoundBuffer( void* datas, unsigned int* freq, unsigned int* nbChannels, unsigned int* fourCCFormat, unsigned int* frameSize )
void MetaDataManager::stopAudioDataParsing()
{
qDebug() << "Opening sound buffer with freq =" << *freq << "nbChannels =" << *nbChannels << "frameSize =" << *frameSize;
qDebug() << "Stopping AudioDataParsing";
m_mediaPlayer->stop();
}
void MetaDataManager::openSoundBuffer( void* datas, unsigned int* freq, unsigned int* nbChannels, unsigned int* fourCCFormat, unsigned int* frameSize )
{
//qDebug() << "Opening sound buffer with freq =" << *freq << "nbChannels =" << *nbChannels << "frameSize =" << *frameSize;
MetaDataManager::getInstance()->getCurrentMedia()->initAudioData( datas, freq, nbChannels, fourCCFormat, frameSize );
}
void MetaDataManager::playSoundBuffer( void* datas, unsigned char* buffer, size_t buffSize, unsigned int nbSample )
{
// qDebug() << "Playing sound buffer with nbSample =" << nbSample << "buffSize =" << buffSize;
//qDebug() << "Playing sound buffer with nbSample =" << nbSample << "buffSize =" << buffSize;
// qDebug() << "Buff[0] = " << (unsigned int)buffer[0];
//if (MetaDataManager::getInstance()->getCurrentMedia()->getAudioData()->frameList.size() < 500 )
MetaDataManager::getInstance()->getCurrentMedia()->addAudioFrame( datas, buffer, buffSize, nbSample );
//else
// MetaDataManager::getInstance()->getMediaPlayer()->stop();
}
void MetaDataManager::closeSoundBuffer( void* datas )
{
qDebug() << "Closing sound buffer";
MetaDataManager::getInstance()->getMediaPlayer()->stop();
}
void MetaDataManager::instanceParameterHandler( void*, char*, char* )
......
......@@ -4,6 +4,7 @@
* Copyright (C) 2008-2009 the VLMC team
*
* Authors: Hugo Beauzee-Luyssen <hugo@vlmc.org>
* Authors: Geoffroy Lacarriere <geoffroylaca@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
......@@ -19,6 +20,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
/** \file
* This file contains the MetaDataManager class declaration/definition.
* It used by the library in Library.[hc]pp.
......@@ -34,17 +36,23 @@
#include <QWidget>
#include "Media.h"
#include "VLCMediaPlayer.h"
#include "Singleton.hpp"
class MetaDataManager : public QThread
class MetaDataManager : public QThread, public Singleton<MetaDataManager>
{
Q_OBJECT
Q_DISABLE_COPY( MetaDataManager )
friend class Singleton<MetaDataManager>;
public:
Media* getCurrentMedia() { return m_currentClip; }
LibVLCpp::MediaPlayer* getMediaPlayer() { return m_mediaPlayer; }
private:
MetaDataManager();
~MetaDataManager();
private:
virtual void run();
//AMEM part :
static void openSoundBuffer( void* datas, unsigned int* freq,
......@@ -74,6 +82,7 @@ class MetaDataManager : public QThread
void newMediaLoaded( Media* );
void setSnapshot();
void startAudioDataParsing();
void stopAudioDataParsing();
};
#endif // METADATAMANAGER_H
......@@ -22,6 +22,8 @@
#include "GraphicsMovieItem.h"
#include "TracksView.h"
#include <QPainter>
#include <QDebug>
GraphicsMovieItem::GraphicsMovieItem( Media* media ) : m_media ( media ), m_width( 0 ), m_height( 0 )
{
......@@ -41,6 +43,8 @@ void GraphicsMovieItem::paint( QPainter* painter, const QStyleOptionGraphicsItem
{
painter->setBrush( Qt::red );
painter->drawRect( boundingRect() );
paintAudioSpectrum( painter );
}
......@@ -53,3 +57,47 @@ void GraphicsMovieItem::setHeight( int height )
{
m_height = height;
}
void GraphicsMovieItem::paintAudioSpectrum( QPainter* painter )
{
qreal x1, x2, y1, y2;
QRectF tmp = boundingRect();
tmp.getCoords( &x1, &y1, &x2, &y2 );
painter->setPen( Qt::black );
painter->setBrush( Qt::black );
QLineF line;
for (int i = 0; i < m_media->getAudioFrameList().size(); i++)
{
//qDebug() << "Frame: " << i << "/" << m_media->getAudioFrameList().size();
for (int u = 0; u < m_media->getAudioNbSample(); u += 400)
{
int value = m_media->getAudioFrameList()[i][u];
value /= 30;
if( value > 48 ) value = 48;
if( value < 0 ) value = 0;
//qDebug() << "frame nb:" << i << " buff value: " << value;
static QPointF point = QPointF( x1, ( y2 - y1 ) / 2 );
qreal y = ( ( y2 - y1 ) / 2 ) - value / 2;
x1 += 2;
QPointF point2( x1, y );
line.setPoints( point, point2);
//line.setLine( x1 , y, x1 + 2, y);
painter->drawLine(line);
//painter->drawRect(tmp);
point.setX( point2.x() );
point.setY( point2.y() );
}
}
}
......@@ -44,11 +44,14 @@ public:
void setWidth( int width );
void setHeight( int height );
//void setAudioSpectrum( QVector<float*> spectrum );
void paintAudioSpectrum( QPainter* painter );
private:
Media* m_media;
int m_width;
int m_height;
Media* m_media;
int m_width;
int m_height;
QVector<float*> m_audioSpectrum;
};
#endif // GRAPHICSMOVIEITEM_H
......@@ -58,8 +58,6 @@ MainWindow::MainWindow( QWidget *parent ) :
MainWindow::~MainWindow()
{
if (m_metaDataManager)
delete m_metaDataManager;
}
void MainWindow::changeEvent( QEvent *e )
......@@ -148,7 +146,7 @@ void MainWindow::m_initializeDockWidgets( void )
QDockWidget::AllDockWidgetFeatures,
Qt::TopDockWidgetArea );
m_metaDataManager = new MetaDataManager();
m_metaDataManager = MetaDataManager::getInstance();
}
//Private slots definition
......
......@@ -193,6 +193,7 @@ void TracksView::addClip( Media* clip, const QPoint& point )
item->setPos( mappedXPos, track * tracksHeight() );
item->setWidth( ( (double)clip->getLength() / 1000 ) * m_fps );
item->setHeight( tracksHeight() );
//item->setAudioSpectrum( clip->getAudioSpectrum() );
m_scene->addItem( item );
int duration = mappedXPos + ( (double)clip->getLength() / 1000 ) * m_fps;
if ( duration > m_projectDuration )
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment