More changes for the recording... It's still not working. -_-
This commit is contained in:
parent
15f6d78128
commit
6e05900b5a
@ -48,8 +48,8 @@ private:
|
||||
void _reset();
|
||||
void _init();
|
||||
void _wait();
|
||||
uint16_t _read_control_register(uint8_t address);
|
||||
void _write_control_register(uint8_t address, uint16_t value);
|
||||
uint16_t _read_control_register(uint8_t address, bool do_wait=true);
|
||||
void _write_control_register(uint8_t address, uint16_t value, bool do_wait=true);
|
||||
void _write_direct(uint8_t address, uint16_t value);
|
||||
void _write_data(uint8_t* data);
|
||||
uint16_t _read_wram(uint16_t address);
|
||||
|
@ -134,17 +134,18 @@ void Player::_record() {
|
||||
|
||||
_patch_adpcm();
|
||||
|
||||
_write_control_register(SCI_MODE, _read_control_register(SCI_MODE) | SM_ADPCM | SM_LAYER12);
|
||||
_write_control_register(SCI_MODE, SM_ADPCM);
|
||||
|
||||
_write_control_register(SCI_AICTRL0, 0x8000); // Mono VU meter
|
||||
_write_control_register(SCI_AICTRL1, 1024); // Manual gain, 1x
|
||||
_write_control_register(SCI_AICTRL2, 0); // Maximum gain for autogain - ignored
|
||||
_write_control_register(SCI_AICTRL3, 0); // status: record
|
||||
|
||||
_write_control_register(SCI_AIADDR, 0x0034);
|
||||
_write_control_register(SCI_AIADDR, 0x0034, false);
|
||||
delay(1);
|
||||
_wait();
|
||||
|
||||
DEBUG("Recording.\n");
|
||||
delay(10);
|
||||
_state = recording;
|
||||
}
|
||||
|
||||
@ -161,8 +162,8 @@ inline void Player::_wait() {
|
||||
while(!PIN_VS1053_DREQ());
|
||||
}
|
||||
|
||||
uint16_t Player::_read_control_register(uint8_t address) {
|
||||
_wait();
|
||||
uint16_t Player::_read_control_register(uint8_t address, bool do_wait) {
|
||||
if (do_wait) _wait();
|
||||
_spi->select_vs1053_xcs();
|
||||
SPI.beginTransaction(*_spi_settings);
|
||||
SPI.transfer(CMD_READ);
|
||||
@ -177,7 +178,7 @@ uint16_t Player::_read_control_register(uint8_t address) {
|
||||
return (b1 << 8) | b2;
|
||||
}
|
||||
|
||||
void Player::_write_control_register(uint8_t address, uint16_t value) {
|
||||
void Player::_write_control_register(uint8_t address, uint16_t value, bool do_wait) {
|
||||
_wait();
|
||||
_spi->select_vs1053_xcs();
|
||||
SPI.beginTransaction(*_spi_settings);
|
||||
@ -187,7 +188,7 @@ void Player::_write_control_register(uint8_t address, uint16_t value) {
|
||||
SPI.transfer(value & 0xFF);
|
||||
SPI.endTransaction();
|
||||
_spi->select_vs1053_xcs(false);
|
||||
_wait();
|
||||
if (do_wait) _wait();
|
||||
}
|
||||
|
||||
void Player::_patch_adpcm() {
|
||||
@ -892,13 +893,14 @@ bool Player::loop() {
|
||||
}
|
||||
|
||||
if (_state == recording) {
|
||||
uint16_t samples_available = _read_control_register(SCI_HDAT1);
|
||||
uint16_t vu_value = _read_control_register(SCI_AICTRL0);
|
||||
DEBUG("r");
|
||||
uint16_t samples_available = _read_control_register(SCI_HDAT1, false);
|
||||
uint16_t vu_value = _read_control_register(SCI_AICTRL0, false);
|
||||
DEBUG("Samples available: %4d, VU meter: 0x%04X\n", samples_available, vu_value);
|
||||
if (samples_available >= 500) {
|
||||
unsigned long sum = 0;
|
||||
for (int i=0; i<500; i++) {
|
||||
uint16_t sample = _read_control_register(SCI_HDAT0);
|
||||
uint16_t sample = _read_control_register(SCI_HDAT0, false);
|
||||
sum += sample * sample;
|
||||
}
|
||||
double result = sqrt(sum / 500);
|
||||
@ -907,8 +909,8 @@ bool Player::loop() {
|
||||
}
|
||||
|
||||
if (_state == idle && _stopped_at < millis() - VS1053_SLEEP_DELAY) {
|
||||
//_sleep();
|
||||
_record();
|
||||
_sleep();
|
||||
//_record();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user