reference

This documentation is automatically generated from the openFrameworks source code using doxygen and refers to the most recent release, version 0.12.0.

ofOpenALSoundPlayer.h
Go to the documentation of this file.
1#pragma once
2
3#include "ofConstants.h"
4
5#ifdef OF_SOUND_PLAYER_OPENAL
6#include "ofSoundBaseTypes.h"
7#include "ofThread.h"
8
9typedef unsigned int ALuint;
10
11#include "kiss_fft.h"
12#include "kiss_fftr.h"
13#include <sndfile.h>
14
15#ifdef OF_USING_MPG123
16 typedef struct mpg123_handle_struct mpg123_handle;
17#endif
18
19class ofEventArgs;
20
21// TO DO :
22// ---------------------------
23// -fft via fmod, as in the last time...
24// -close fmod if it's up
25// -loadSoundForStreaming(char * fileName);
26// ---------------------------
27
28// interesting:
29// http://www.compuphase.com/mp3/mp3loops.htm
30
31
32// ---------------------------------------------------------------------------- SOUND SYSTEM FMOD
33
34// --------------------- global functions:
35void ofFmodSoundStopAll();
36void ofFmodSoundSetVolume(float vol);
37void ofOpenALSoundUpdate(); // calls FMOD update.
38float * ofFmodSoundGetSpectrum(int nBands); // max 512...
39
40
41// --------------------- player functions:
42class ofOpenALSoundPlayer : public ofBaseSoundPlayer, public ofThread {
43
44 public:
45
46 ofOpenALSoundPlayer();
47 virtual ~ofOpenALSoundPlayer();
48
49 bool load(const of::filesystem::path& fileName, bool stream = false);
50 void unload();
51 void play();
52 void stop();
53
54 void setVolume(float vol);
55 void setPan(float vol); // -1 to 1
56 void setSpeed(float spd);
57 void setPaused(bool bP);
58 void setLoop(bool bLp);
59 void setMultiPlay(bool bMp);
60 void setPosition(float pct); // 0 = start, 1 = end;
61 void setPositionMS(int ms);
62
63
64 float getPosition() const;
65 int getPositionMS() const;
66 bool isPlaying() const;
67 float getSpeed() const;
68 float getPan() const;
69 float getVolume() const;
70 bool isPaused() const;
71 bool isLoaded() const;
72
73 static void initialize();
74 static void close();
75
76 float * getSpectrum(int bands);
77
78 static float * getSystemSpectrum(int bands);
79
80 protected:
81 void threadedFunction();
82
83 private:
84 friend void ofOpenALSoundUpdate();
85 void update(ofEventArgs & args);
86 void initFFT(int bands);
87 float * getCurrentBufferSum(int size);
88
89 static void createWindow(int size);
90 static void runWindow(std::vector<float> & signal);
91 static void initSystemFFT(int bands);
92
93 bool sfReadFile(const of::filesystem::path& path,std::vector<short> & buffer,std::vector<float> & fftAuxBuffer);
94 bool sfStream(const of::filesystem::path& path,std::vector<short> & buffer,std::vector<float> & fftAuxBuffer);
95#ifdef OF_USING_MPG123
96 bool mpg123ReadFile(const of::filesystem::path& path,std::vector<short> & buffer,std::vector<float> & fftAuxBuffer);
97 bool mpg123Stream(const of::filesystem::path& path,std::vector<short> & buffer,std::vector<float> & fftAuxBuffer);
98#endif
99
100 bool readFile(const of::filesystem::path& fileName,std::vector<short> & buffer);
101 bool stream(const of::filesystem::path& fileName, std::vector<short> & buffer);
102
103 bool isStreaming;
104 bool bMultiPlay;
105 bool bLoop;
106 bool bLoadedOk;
107 bool bPaused;
108 float pan; // 0 - 1
109 float volume; // 0 - 1
110 float internalFreq; // 44100 ?
111 float speed; // -n to n, 1 = normal, -1 backwards
112 unsigned int length; // in samples;
113
114 static std::vector<float> window;
115 static float windowSum;
116
117 int channels;
118 float duration; //in secs
119 int samplerate;
120 std::vector<ALuint> buffers;
121 std::vector<ALuint> sources;
122
123 // fft structures
124 std::vector<std::vector<float> > fftBuffers;
125 kiss_fftr_cfg fftCfg;
126 std::vector<float> windowedSignal;
127 std::vector<float> bins;
128 std::vector<kiss_fft_cpx> cx_out;
129
130
131 static kiss_fftr_cfg systemFftCfg;
132 static std::vector<float> systemWindowedSignal;
133 static std::vector<float> systemBins;
134 static std::vector<kiss_fft_cpx> systemCx_out;
135
136 SNDFILE* streamf;
137 size_t stream_samples_read;
138#ifdef OF_USING_MPG123
139 mpg123_handle * mp3streamf;
140 int stream_encoding;
141#endif
142 int mp3_buffer_size;
143 int stream_subformat;
144 double stream_scale;
145 std::vector<short> buffer;
146 std::vector<float> fftAuxBuffer;
147
148 bool stream_end;
149};
150
151#endif
Definition ofSoundBaseTypes.h:161
virtual void setSpeed(float spd)=0
virtual bool load(const of::filesystem::path &fileName, bool stream=false)=0
virtual void setPositionMS(int ms)=0
virtual bool isLoaded() const =0
virtual bool isPlaying() const =0
virtual void setMultiPlay(bool bMp)=0
virtual float getPosition() const =0
virtual void play()=0
virtual void stop()=0
virtual void setPan(float vol)=0
virtual void setVolume(float vol)=0
virtual float getVolume() const =0
virtual void setPaused(bool bP)=0
virtual float getPan() const =0
virtual int getPositionMS() const =0
virtual float getSpeed() const =0
virtual void setPosition(float pct)=0
virtual void unload()=0
virtual void setLoop(bool bLp)=0
Definition ofEvents.h:119
A threaded base class with a built in mutex for convenience.
Definition ofThread.h:70
virtual void threadedFunction()
The thread's run function.
Definition ofThread.cpp:148
float * ofFmodSoundGetSpectrum(int nBands)