-
Notifications
You must be signed in to change notification settings - Fork 4
/
audio_filer.cpp
47 lines (43 loc) · 887 Bytes
/
audio_filer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
* audio_filer.cpp -- novelty tape output device
*/
#include <Arduino.h>
#include <stdint.h>
#include <memory.h>
#include <serialio.h>
#include <filer.h>
#include <acia.h>
#include <hardware.h>
#include "config.h"
#include "audio_filer.h"
void audio_filer::reset() {
speed(BAUD_RATE);
#if defined(PWM_SOUND)
noTone(PWM_SOUND);
#endif
}
void audio_filer::framing(unsigned data_bits, unsigned stop_bits, parity parity) {
_data_bits = data_bits;
_stop_bits = stop_bits;
_parity = parity;
}
void audio_filer::write_bit(bool bit) {
#if defined(PWM_SOUND)
tone(PWM_SOUND, bit? 2400: 1200);
#endif
delayMicroseconds(_bit_delay);
}
// FIXME: parity
void audio_filer::write(uint8_t b) {
write_bit(0);
for (int i = 0; i < _data_bits; i++) {
write_bit(b & 1);
b >>= 1;
}
write_bit(1);
if (_stop_bits == 2)
write_bit(1);
#if defined(PWM_SOUND)
noTone(PWM_SOUND);
#endif
}