Commit 447efe75 authored by Geoffroy Lacarriere's avatar Geoffroy Lacarriere
Browse files

Refactor of the Audio graph architecture

parent a2b76bf0
......@@ -4,6 +4,7 @@
* Copyright (C) 2008-2009 the VLMC team
*
* Authors: Hugo Beauzee-Luyssen <hugo@vlmc.org>
* 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
......@@ -28,6 +29,7 @@
#include <QtDebug>
#include "Media.h"
#include <QPainter>
QPixmap* Media::defaultSnapshot = NULL;
const QString Media::VideoExtensions = "*.mov *.avi *.mkv *.mpg *.mpeg *.wmv *.mp4";
......@@ -46,6 +48,8 @@ Media::Media( const QFileInfo* fileInfo)
else
m_mrl = "fake:///" + fileInfo->absoluteFilePath();
m_vlcMedia = new LibVLCpp::Media( m_mrl );
connect(this, SIGNAL(audioFramePointList(QVector<uint>*)), this, SLOT(addAudioFramePointList(QVector<uint>*)));
}
Media::~Media()
......@@ -173,10 +177,10 @@ Media::FileType Media::getFileType() const
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.freq = *freq;
m_audioData.nbChannels = *nbChannels;
m_audioData.frameSize = *frameSize;
m_audioData.fourCCFormat = *fourCCFormat;
m_audioData.datas = datas;
}
......@@ -184,19 +188,47 @@ void Media::addAudioFrame( void* datas, unsigned char* buffer, si
{
m_audioData.nbSample = nbSample;
m_audioData.buffSize = buffSize;
unsigned int bytePerSample = buffSize / nbSample;
unsigned int bytePerChannelPerSample = bytePerSample / m_audioData.nbChannels;
int average = 0;
for (unsigned int i = 0; i < nbSample; i++)
{
unsigned int left = 0;
unsigned int right = 0;
for ( unsigned int u = 0; u < bytePerChannelPerSample ; u++ )
{
int increment = 0;
if ( m_audioData.nbChannels == 2 )
increment = 2;
left <<= 8;
left += buffer[ u ];
right <<= 8;
right += buffer[ u + increment ];
}
average += left;
//qDebug() << "Left: " << left << " Right: " << right;
}
static int i = 0;
average /= nbSample;
int* frame = new int[ m_audioData.buffSize ];
for (unsigned int i = 0, u = 0; u < m_audioData.nbSample; i += 4, u++)
if ( i < 64 )
{
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;
//qDebug() << i;
m_pointList.append( average );
i++;
}
m_audioData.frameList.append( frame );
// qDebug() << m_audioData.frameList.size();
else
{
emit audioFramePointList( &m_pointList );
i = 0;
}
}
void Media::addAudioFramePointList( QVector<uint>* pointList )
{
QPainter painter;
QPixmap pixmap;
qDebug("new frame");
}
......@@ -41,10 +41,10 @@
struct audioData
{
void* datas;
unsigned int* freq;
unsigned int* nbChannels;
unsigned int* fourCCFormat;
unsigned int* frameSize;
unsigned int freq;
unsigned int nbChannels;
unsigned int fourCCFormat;
unsigned int frameSize;
unsigned int nbSample;
unsigned char* buffer;
size_t buffSize;
......@@ -129,6 +129,9 @@ public:
private:
void setFileType();
private slots:
void addAudioFramePointList( QVector<uint>* );
protected:
static QPixmap* defaultSnapshot;
......@@ -146,8 +149,11 @@ protected:
audioData m_audioData;
FileType m_fileType;
QVector<uint> m_pointList;
signals:
void snapshotChanged();
void audioFramePointList( QVector<uint>* );
};
#endif // CLIP_H__
......@@ -55,11 +55,8 @@ void GraphicsMovieItem::paint( QPainter* painter, const QStyleOptionGraphicsItem
painter->setPen( QPen( Qt::NoPen ) );
painter->setBrush( QBrush( gradient ) );
painter->drawRect( boundingRect() );
paintAudioSpectrum( painter );
}
void GraphicsMovieItem::setWidth( int width )
{
m_width = width;
......
......@@ -34,22 +34,21 @@ class GraphicsMovieItem : public AbstractGraphicsMediaItem
public:
enum { Type = UserType + 1 };
GraphicsMovieItem( Clip* clip );
virtual ~GraphicsMovieItem();
virtual ~GraphicsMovieItem();
Clip* clip() const;
virtual int type() const { return Type; }
virtual bool expandable() const { return false; }
virtual bool moveable() const { return true; }
virtual const QUuid& uuid() const { return m_media->getUuid(); }
virtual QRectF boundingRect() const;
virtual void paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0 );
void setWidth( int width );
void setHeight( int height );
virtual int type() const { return Type; }
virtual bool expandable() const { return false; }
virtual bool moveable() const { return true; }
virtual const QUuid& uuid() const { return m_clip->getUuid(); }
virtual QRectF boundingRect() const;
virtual void paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0 );
void setWidth( int width );
void setHeight( int height );
Clip* clip() const;
//void setAudioSpectrum( QVector<float*> spectrum );
void paintAudioSpectrum( QPainter* painter );
private:
Media* m_media;
Clip* m_clip;
int m_width;
int m_height;
......
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