1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-04 15:24:12 +01:00
Arduino/hardware/arduino/sam/libraries/Audio/Audio.h

58 lines
1.7 KiB
C
Raw Normal View History

/*
* Copyright (c) 2012 by Cristian Maglie <c.maglie@bug.st>
* Audio library for Arduino Due.
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of either the GNU General Public License version 2
* or the GNU Lesser General Public License version 2.1, both as
* published by the Free Software Foundation.
*/
2012-06-17 18:20:01 +02:00
#ifndef AUDIO_H
#define AUDIO_H
#include "Arduino.h"
#include "Print.h"
#include "DAC.h"
2012-06-17 18:20:01 +02:00
class AudioClass : public Print {
public:
AudioClass(DACClass &_dac) : dac(&_dac) { };
void prepare(int16_t *buffer, int S, int volume);
void begin(uint32_t sampleRate, uint32_t msPreBuffer);
2012-06-17 18:20:01 +02:00
void end();
virtual size_t write(uint8_t c) { /* not implemented */ };
virtual size_t write(const uint8_t *data, size_t size) { return write(reinterpret_cast<const uint32_t*>(data), size/4) * 4; };
virtual size_t write(const uint16_t *data, size_t size) { return write(reinterpret_cast<const uint32_t*>(data), size/2) * 2; };
virtual size_t write(const int16_t *data, size_t size) { return write(reinterpret_cast<const uint32_t*>(data), size/2) * 2; };
virtual size_t write(const uint32_t *data, size_t size);
void debug() {
// Serial1.print(running-buffer, DEC);
// Serial1.print(" ");
// Serial1.print(current-buffer, DEC);
// Serial1.print(" ");
// Serial1.print(next-buffer, DEC);
// Serial1.print(" ");
// Serial1.println(last-buffer, DEC);
}
2012-06-17 18:20:01 +02:00
private:
void enqueue();
static void onTransmitEnd(void *me);
uint32_t bufferSize;
uint32_t *buffer;
uint32_t *half;
uint32_t *last;
uint32_t *volatile running;
uint32_t *volatile next;
uint32_t *cook(const uint32_t *buffer, size_t size);
DACClass *dac;
2012-06-17 18:20:01 +02:00
};
extern AudioClass Audio;
#endif