2003-10-21 22:51:25 +00:00
|
|
|
#ifndef ALSA9_HELPERS_H
|
|
|
|
|
#define ALSA9_HELPERS_H
|
|
|
|
|
|
|
|
|
|
#define ALSA_PCM_NEW_HW_PARAMS_API
|
2003-11-03 21:52:31 +00:00
|
|
|
#define ALSA_PCM_NEW_SW_PARAMS_API
|
2003-10-21 22:51:25 +00:00
|
|
|
#include <alsa/asoundlib.h>
|
|
|
|
|
|
|
|
|
|
#include "SDL_types.h"
|
|
|
|
|
|
|
|
|
|
class Alsa9Buf
|
|
|
|
|
{
|
|
|
|
|
private:
|
2003-10-22 02:34:44 +00:00
|
|
|
int channels, samplerate, samplebits;
|
2004-01-20 01:00:01 +00:00
|
|
|
int buffersize;
|
|
|
|
|
int64_t last_cursor_pos;
|
2004-01-03 02:49:19 +00:00
|
|
|
bool samplerate_set_explicitly;
|
2003-10-21 22:51:25 +00:00
|
|
|
|
2004-05-08 03:02:25 +00:00
|
|
|
snd_pcm_uframes_t writeahead, chunksize;
|
2003-10-21 22:51:25 +00:00
|
|
|
|
|
|
|
|
snd_pcm_t *pcm;
|
|
|
|
|
|
|
|
|
|
bool Recover( int r );
|
2003-10-22 03:41:29 +00:00
|
|
|
bool SetHWParams();
|
2004-01-03 08:40:43 +00:00
|
|
|
bool SetSWParams();
|
2003-10-21 22:51:25 +00:00
|
|
|
|
2003-10-22 06:50:08 +00:00
|
|
|
static void ErrorHandler(const char *file, int line, const char *function, int err, const char *fmt, ...);
|
|
|
|
|
|
2003-10-21 22:51:25 +00:00
|
|
|
public:
|
2004-04-03 20:55:50 +00:00
|
|
|
static void InitializeErrorHandler();
|
2003-10-22 03:41:29 +00:00
|
|
|
static void GetSoundCardDebugInfo();
|
2004-02-18 00:40:22 +00:00
|
|
|
static CString GetHardwareID( CString name="" );
|
2003-10-22 03:41:29 +00:00
|
|
|
|
2003-10-21 22:51:25 +00:00
|
|
|
enum hw { HW_HARDWARE, HW_SOFTWARE, HW_DONT_CARE };
|
|
|
|
|
|
2004-01-03 02:35:47 +00:00
|
|
|
/* Call SetSampleRate before you use the sample. */
|
|
|
|
|
Alsa9Buf( hw hardware, int channels );
|
2003-10-21 22:51:25 +00:00
|
|
|
~Alsa9Buf();
|
|
|
|
|
|
2004-05-08 03:02:25 +00:00
|
|
|
int GetNumFramesToFill();
|
|
|
|
|
bool WaitUntilFramesCanBeFilled( int timeout_ms );
|
2003-10-21 22:51:25 +00:00
|
|
|
void Write( const Sint16 *buffer, int frames );
|
2004-01-03 02:35:47 +00:00
|
|
|
unsigned FindSampleRate( unsigned rate );
|
|
|
|
|
|
2003-10-21 22:51:25 +00:00
|
|
|
void Play();
|
|
|
|
|
void Stop();
|
|
|
|
|
void SetVolume(float vol);
|
|
|
|
|
void SetSampleRate(int hz);
|
2004-01-12 03:53:16 +00:00
|
|
|
int GetSampleRate() const { return samplerate; }
|
2003-10-21 22:51:25 +00:00
|
|
|
|
2004-05-08 03:02:25 +00:00
|
|
|
void SetWriteahead( snd_pcm_sframes_t frames );
|
|
|
|
|
void SetChunksize( snd_pcm_sframes_t frames );
|
|
|
|
|
|
2004-01-20 01:00:01 +00:00
|
|
|
int64_t GetPosition() const;
|
|
|
|
|
int64_t GetPlayPos() const { return last_cursor_pos; }
|
2003-10-21 22:51:25 +00:00
|
|
|
};
|
|
|
|
|
#endif
|