~ubuntu-branches/ubuntu/natty/ultrastar-ng/natty

« back to all changes in this revision

Viewing changes to include/record.h

  • Committer: Bazaar Package Importer
  • Author(s): Miriam Ruiz, Miriam Ruiz, Mario Bonino, Jon Dowland, Ansgar Burchardt
  • Date: 2008-06-07 16:43:18 UTC
  • mfrom: (4.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080607164318-4cnzizck1tp8mrwp
Tags: 0.2.1-1
[ Miriam Ruiz ]
* New Upstream Release (Closes: #453132)
* Removed unneeded patches
* Added packages to build deps:
  + libtool
  + portaudio19-dev | portaudio-dev
  + libboost-dev, libboost-thread-dev, libboost-serialization-dev
  + libboost-program-options-dev, libboost-regex-dev
* Moved shared objects to private directory: /usr/lib/ultraster-ng
* Added rpath to binaries to search for shared objects in the private dir
* Uses ultrastar-ng-gstreamer as default, instead of ultrastar-ng-xine,
  since there are significantly less issues with GStreamer.
* Added patch to fix upstream desktop file
* Added -Wl,-as-needed to LDFLAGS
* Replaced fftw3-dev by libfftw3-dev in build dependencies.
* Standards-Version upgraded to 3.7.3

[ Mario Bonino ]
* Fixed data/Makefile.am to install .desktop file and icon

[ Jon Dowland ]
* add Homepage: control field to source stanza
* fix a bashism in debian/rules (Closes: #478634)

[ Ansgar Burchardt ]
* debian/control: Change XS-Vcs-* to Vcs-*
* Remove Homepage semi-field from description

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#ifndef __RECORD_H_
2
2
#define __RECORD_H_
3
3
 
4
 
#include "../config.h"
5
 
 
6
 
class CFft {
7
 
        public:
8
 
        CFft(int size=10);
9
 
        ~CFft();
10
 
        void compute(int nframes, signed short int *indata);
11
 
        float getFreq( void ) { return m_freq; }
12
 
        private:
13
 
        void measure (int nframes, int overlap, float *indata);
14
 
        float *fftSampleBuffer;
15
 
        float *fftSample;
16
 
        float *fftLastPhase;
17
 
        int fftSize;
18
 
        int fftFrameCount;
19
 
        float *fftIn;
20
 
        fftwf_complex *fftOut;
21
 
        fftwf_plan fftPlan;
22
 
        float m_freq;
23
 
 
24
 
};
25
 
 
26
 
class CRecord {
27
 
        public:
28
 
        CRecord(char * captureDevice = "default");
29
 
        ~CRecord();
30
 
        void compute();
31
 
        float getFreq( void ) { return fft->getFreq(); }
32
 
        char * getNoteStr( int id);
33
 
        int getNoteId(void);
34
 
        float getNoteFreq(int id);
35
 
        private:
36
 
        CFft * fft;
37
 
        snd_pcm_t *alsaHandle;
38
 
        signed short int buf[4096];
 
4
#include <boost/thread/mutex.hpp>
 
5
#include <audio.hpp>
 
6
#include <cstddef>
 
7
#include <deque>
 
8
#include <iostream>
 
9
#include <limits>
 
10
#include <vector>
 
11
 
 
12
struct Peak {
 
13
        double m_freq;
 
14
        double m_db;
 
15
  public:
 
16
        Peak(double _freq = 0.0, double _db = -std::numeric_limits<double>::infinity()): m_freq(_freq), m_db(_db) {}
 
17
        double db() const {return m_db;};
 
18
        double freq() const {return m_freq;};
 
19
        void db(double _db) {m_db = _db;};
 
20
        void freq(double _freq) {m_freq = _freq;};
 
21
};
 
22
 
 
23
class Tone {
 
24
        double m_freqSum; // Sum of the fundamental frequencies of all harmonics
 
25
        unsigned int m_harmonics;
 
26
        unsigned int m_hEven;
 
27
        unsigned int m_hHighest;
 
28
        double m_dbHighest;
 
29
        unsigned int m_dbHighestH;
 
30
  public:
 
31
        Tone();
 
32
        void print() const;
 
33
        void combine(Peak& p, unsigned int h);
 
34
        bool isWeak() const;
 
35
        double db() const { return m_dbHighest; }
 
36
        double freq() const { return m_freqSum / m_harmonics; }
 
37
        bool operator==(double f) const;
 
38
        Tone& operator+=(Tone const& t);
 
39
};
 
40
 
 
41
static inline bool operator==(Tone const& lhs, Tone const& rhs) { return lhs == rhs.freq(); }
 
42
static inline bool operator!=(Tone const& lhs, Tone const& rhs) { return !(lhs == rhs); }
 
43
static inline bool operator<=(Tone const& lhs, Tone const& rhs) { return lhs.freq() < rhs.freq() || lhs == rhs; }
 
44
static inline bool operator>=(Tone const& lhs, Tone const& rhs) { return lhs.freq() > rhs.freq() || lhs == rhs; }
 
45
static inline bool operator<(Tone const& lhs, Tone const& rhs) { return lhs.freq() < rhs.freq() && lhs != rhs; }
 
46
static inline bool operator>(Tone const& lhs, Tone const& rhs) { return lhs.freq() > rhs.freq() && lhs != rhs; }
 
47
 
 
48
class Analyzer {
 
49
        static const unsigned FFT_P = 12;
 
50
        static const std::size_t FFT_N = 1 << FFT_P;
 
51
  public:
 
52
        Analyzer(std::size_t step = 1500);
 
53
        void operator()(da::pcm_data& data, da::settings const& s);
 
54
        /** Get the peak level in dB (negative value, 0.0 = clipping). **/
 
55
        double getPeak() const { return m_peak; }
 
56
        /** Get the primary (singing) frequency. **/
 
57
        double getFreq() const { return m_freq; }
 
58
        /** Get a list of all tones detected. **/
 
59
        std::vector<Tone> getTones() const {
 
60
                boost::mutex::scoped_lock l(m_mutex);
 
61
                return m_tones;
 
62
        }
 
63
  private:
 
64
        mutable boost::mutex m_mutex;
 
65
        std::size_t m_step;
 
66
        std::vector<float> m_fftLastPhase;
 
67
        std::vector<float> m_window;
 
68
        volatile double m_peak;
 
69
        volatile double m_freq;
 
70
        std::deque<float> m_buf; // Sample buffer
 
71
        std::vector<Tone> m_tones; // Synchronized access only!
 
72
        std::vector<Tone> m_oldTones;
 
73
};
 
74
 
 
75
class Capture {
 
76
        static const std::size_t DEFAULT_RATE = 48000;
 
77
        Analyzer m_analyzer;
 
78
        da::settings m_rs;
 
79
        da::record m_record;
 
80
  public:
 
81
        Capture(std::string const& device = "", std::size_t rate = DEFAULT_RATE):
 
82
          m_rs(da::settings(device)
 
83
          .set_callback(boost::ref(m_analyzer))
 
84
          .set_channels(1)
 
85
          .set_rate(rate)
 
86
          .set_debug(std::cerr)),
 
87
          m_record(m_rs)
 
88
        {}
 
89
        ~Capture() {}
 
90
        Analyzer const& analyzer() const { return m_analyzer; }
39
91
};
40
92
 
41
93
#endif