< prev index next >

modules/javafx.media/src/main/native/jfxmedia/platform/osx/avf/AVFAudioSpectrumUnit.h

Print this page

 32 #include <memory>
 33 
 34 #include "PipelineManagement/AudioSpectrum.h"
 35 
 36 #include <gst/gst.h>
 37 #include <gstspectrum.h>
 38 
 39 // Defaults, these match the current defaults in JavaFX which get set anyways
 40 // but we can optimize things a bit here...
 41 #define kDefaultAudioSpectrumUpdateInterval 0.1 // every 1/10 second
 42 #define kDefaultAudioSpectrumThreshold -60.0    // -60 dB
 43 
 44 /*
 45  * Callback proc invoked by the audio spectrum unit. This call is made periodically
 46  * depending on the requested update interval. The band data is updated out-of-line.
 47  *
 48  * callbackContext: user specified context pointer
 49  * timeStamp: the beginning time in seconds of the sample period (from beginning of stream)
 50  * duration: the length of time in seconds of the sample period
 51  */
 52 typedef void (*AVFSpectrumUnitCallbackProc)(void *callbackContext, double duration);

 53 
 54 class AVFAudioSpectrumUnit : public CAudioSpectrum {
 55 public:
 56     AVFAudioSpectrumUnit();
 57     virtual ~AVFAudioSpectrumUnit();
 58 
 59     // We'll use ProcessBufferLists as it sends all channels at once instead
 60     // of individual channels
 61     bool ProcessBufferLists(const AudioBufferList& inBuffer,
 62                             UInt32 inFramesToProcess);
 63 
 64     // Parameter accessors
 65     virtual bool IsEnabled();
 66     virtual void SetEnabled(bool isEnabled);
 67 
 68     virtual void SetBands(int bands, CBandsHolder* holder);
 69     virtual size_t GetBands();
 70 
 71     virtual double GetInterval();
 72     virtual void SetInterval(double interval);
 73 
 74     virtual int GetThreshold();
 75     virtual void SetThreshold(int threshold);
 76 
 77     virtual void UpdateBands(int size, const float* magnitudes, const float* phases);
 78 
 79     void SetSampleRate(UInt32 rate);
 80     void SetChannels(UInt32 count);
 81     void SetMaxFrames(UInt32 maxFrames);
 82     void SetSpectrumCallbackProc(AVFSpectrumUnitCallbackProc proc, void *context);

 83 
 84 private:
 85     AVFSpectrumUnitCallbackProc mSpectrumCallbackProc;
 86     void *mSpectrumCallbackContext;
 87     bool mEnabled;
 88 
 89     pthread_mutex_t mBandLock;      // prevent bands from disappearing while we're processing
 90     int mBandCount;
 91     CBandsHolder *mBands;
 92     double mUpdateInterval;
 93     Float32 mThreshold;
 94 
 95     AudioBufferList mMixBuffer;
 96     int mMixBufferFrameCapacity;    // number of frames that can currently be stored in mix buffer
 97 
 98     // Audio parameters
 99     UInt32 mSampleRate;
100     UInt32 mChannels;
101     UInt32 mMaxFrames;
102     UInt32 mSamplesPerInterval;
103 
104     bool mRebuildCrunch;

105 
106     // GStreamer
107     GstElement *mSpectrumElement;
108     GstSpectrum *mSpectrum;
109 
110     void lockBands() {
111         pthread_mutex_lock(&mBandLock);
112     }
113 
114     void unlockBands() {
115         pthread_mutex_unlock(&mBandLock);
116     }
117 
118     void SetupSpectralProcessor();
119     void ReleaseSpectralProcessor();
120 };
121 
122 typedef std::shared_ptr<AVFAudioSpectrumUnit> AVFAudioSpectrumUnitPtr;
123 
124 #endif /* defined(__JFXMedia__AVFAudioSpectrumUnit__) */

 32 #include <memory>
 33 
 34 #include "PipelineManagement/AudioSpectrum.h"
 35 
 36 #include <gst/gst.h>
 37 #include <gstspectrum.h>
 38 
 39 // Defaults, these match the current defaults in JavaFX which get set anyways
 40 // but we can optimize things a bit here...
 41 #define kDefaultAudioSpectrumUpdateInterval 0.1 // every 1/10 second
 42 #define kDefaultAudioSpectrumThreshold -60.0    // -60 dB
 43 
 44 /*
 45  * Callback proc invoked by the audio spectrum unit. This call is made periodically
 46  * depending on the requested update interval. The band data is updated out-of-line.
 47  *
 48  * callbackContext: user specified context pointer
 49  * timeStamp: the beginning time in seconds of the sample period (from beginning of stream)
 50  * duration: the length of time in seconds of the sample period
 51  */
 52 typedef void (*AVFSpectrumUnitCallbackProc)(void *callbackContext, double duration,
 53                                             double timestamp);
 54 
 55 class AVFAudioSpectrumUnit : public CAudioSpectrum {
 56 public:
 57     AVFAudioSpectrumUnit();
 58     virtual ~AVFAudioSpectrumUnit();
 59 
 60     // We'll use ProcessBufferLists as it sends all channels at once instead
 61     // of individual channels
 62     bool ProcessBufferLists(const AudioBufferList& inBuffer,
 63                             UInt32 inFramesToProcess);
 64 
 65     // Parameter accessors
 66     virtual bool IsEnabled();
 67     virtual void SetEnabled(bool isEnabled);
 68 
 69     virtual void SetBands(int bands, CBandsHolder* holder);
 70     virtual size_t GetBands();
 71 
 72     virtual double GetInterval();
 73     virtual void SetInterval(double interval);
 74 
 75     virtual int GetThreshold();
 76     virtual void SetThreshold(int threshold);
 77 
 78     virtual void UpdateBands(int size, const float* magnitudes, const float* phases);
 79 
 80     void SetSampleRate(UInt32 rate);
 81     void SetChannels(UInt32 count);
 82     void SetMaxFrames(UInt32 maxFrames);
 83     void SetSpectrumCallbackProc(AVFSpectrumUnitCallbackProc proc, void *context);
 84     void SetFirstBufferDelivered(bool isFirstBufferDelivered);
 85 
 86 private:
 87     AVFSpectrumUnitCallbackProc mSpectrumCallbackProc;
 88     void *mSpectrumCallbackContext;
 89     bool mEnabled;
 90 
 91     pthread_mutex_t mBandLock;      // prevent bands from disappearing while we're processing
 92     int mBandCount;
 93     CBandsHolder *mBands;
 94     double mUpdateInterval;
 95     Float32 mThreshold;
 96 
 97     AudioBufferList mMixBuffer;
 98     int mMixBufferFrameCapacity;    // number of frames that can currently be stored in mix buffer
 99 
100     // Audio parameters
101     UInt32 mSampleRate;
102     UInt32 mChannels;
103     UInt32 mMaxFrames;
104     UInt32 mSamplesPerInterval;
105 
106     bool mRebuildCrunch;
107     bool mFirstBufferDelivered;
108 
109     // GStreamer
110     GstElement *mSpectrumElement;
111     GstSpectrum *mSpectrum;
112 
113     void lockBands() {
114         pthread_mutex_lock(&mBandLock);
115     }
116 
117     void unlockBands() {
118         pthread_mutex_unlock(&mBandLock);
119     }
120 
121     void SetupSpectralProcessor();
122     void ReleaseSpectralProcessor();
123 };
124 
125 typedef std::shared_ptr<AVFAudioSpectrumUnit> AVFAudioSpectrumUnitPtr;
126 
127 #endif /* defined(__JFXMedia__AVFAudioSpectrumUnit__) */
< prev index next >