summaryrefslogtreecommitdiffstats
path: root/noatun/modules/winskin/winSkinVis.cpp
blob: 8ec025d24e76da3f971aaf9c239307bcd7381a04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
  noatun visualisation interface for winskin
  Copyright (C) 2001  Martin Vogt

  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.

  For more information look at the file COPYRIGHT in this package

 */



#include "winSkinVis.h"

#define __BANDS     75
#define __SPAHEIGHT 15

WinSkinVis::WinSkinVis(TQObject *parent, const char *name):
    TQObject(parent,name),Visualization(50) {

    m_currentPeaks=new float[__BANDS];

    for(unsigned int i=0;i<__BANDS;i++) 
        m_currentPeaks[i]=0.0;

    // If we can create our server-side object, visualize away
    if (initServerObject())
    {
        start();
    }
}


WinSkinVis::~WinSkinVis()
{
    if (m_winSkinFFT != NULL) {
        if (connected())
        {
            visualizationStack().remove(m_id);
            m_winSkinFFT->stop();
            delete m_winSkinFFT;
        }
    }

    delete[] m_currentPeaks;
}


bool WinSkinVis::initServerObject()
{
    // Create FFT on server
    m_winSkinFFT = new Noatun::WinSkinFFT();
    *m_winSkinFFT = Arts::DynamicCast(server()->createObject("Noatun::WinSkinFFT"));
  
    if ( (*m_winSkinFFT).isNull() ) {
        delete m_winSkinFFT;
        m_winSkinFFT=NULL;
    } 
    else
    {
       m_winSkinFFT->bandResolution(__BANDS);
       m_winSkinFFT->start();
       m_id=visualizationStack().insertBottom(*m_winSkinFFT, "WinSkin FFT");
    }

    return (m_winSkinFFT != NULL);
}

void WinSkinVis::timeout()
{
    std::vector<float> *data(m_winSkinFFT->scope());
    
    float *f=&data->front();
    if (data->size())
        scopeEvent(f, data->size());

    delete data;
}

float* WinSkinVis::currentPeaks()
{
    return m_currentPeaks;
}

void WinSkinVis::scopeEvent(float* bandPtr, unsigned int bands)
{
    for (unsigned int i = 0;i < bands;i++) {
        float value=bandPtr[i];
        // if the peak is less we prefer the higher one
        if (m_currentPeaks[i] < value)
            m_currentPeaks[i] = value;
        else
            m_currentPeaks[i] = m_currentPeaks[i]-1.3;

        if (m_currentPeaks[i] < 0.0)
            m_currentPeaks[i] = 0.0;

        if (m_currentPeaks[i] > __SPAHEIGHT)
            m_currentPeaks[i]=__SPAHEIGHT;
    }
    emit(doRepaint());
}


#include "winSkinVis.moc"