irmc/src/beep.h

63 lines
1.2 KiB
C
Raw Normal View History

2015-07-08 21:24:41 +00:00
#include <math.h>
2016-10-04 14:37:06 +00:00
#ifdef __MACH__
#define PORTAUDIO
#endif
2016-10-04 14:40:57 +00:00
#ifdef __arm__
2016-10-04 14:38:51 +00:00
#define ALSA
#endif
2016-10-04 14:37:06 +00:00
#ifdef PORTAUDIO
2016-10-04 14:33:14 +00:00
#include <portaudio.h>
2016-10-04 14:37:06 +00:00
#endif
2015-07-08 21:24:41 +00:00
#define NUM_SECONDS (5)
2016-10-03 15:59:43 +00:00
#define SAMPLE_RATE (48000)
2015-07-08 21:24:41 +00:00
#define FRAMES_PER_BUFFER (64)
#ifndef M_PI
#define M_PI (3.14159265)
#endif
2016-10-04 14:37:06 +00:00
#ifdef PORTAUDIO
2015-07-08 21:24:41 +00:00
typedef struct
{
2016-10-03 14:13:59 +00:00
uint32_t total_count;
uint32_t up_count;
2016-09-23 20:32:24 +00:00
2016-10-03 14:13:59 +00:00
uint32_t counter;
uint32_t prev_freq;
uint32_t freq;
} paTestData;
2015-07-08 21:24:41 +00:00
2016-10-03 14:54:54 +00:00
static int patestCallback( const void *inputBuffer, void *outputBuffer,
unsigned long framesPerBuffer,
const PaStreamCallbackTimeInfo* timeInfo,
PaStreamCallbackFlags statusFlags,
void *userData );
2016-10-03 14:13:59 +00:00
void buzzer_set_freq(int frequency);
void buzzer_beep(int frequency, int msecs);
int buzzer_start(void);
int buzzer_stop();
void msleep(int d);
int beep_test(void);
2016-10-04 14:37:06 +00:00
#endif
2016-10-03 14:13:59 +00:00
2016-10-04 14:41:45 +00:00
#ifdef ALSA
#include <stdint.h>
#include <alsa/asoundlib.h>
#include <math.h>
2016-10-04 15:02:16 +00:00
#define FRAMES (SAMPLE_RATE*2L) //16384L
2016-10-04 14:41:45 +00:00
int16_t buffer[FRAMES*2]; /* 16bit stereo sound samples */
#endif
2016-10-03 14:13:59 +00:00
// compatibility to old interface
int beep(double freq_hz, double duration_sec);
int beep_init();
2016-10-03 19:05:44 +00:00
int beep_close();