kopia lustrzana https://github.com/open-ham/OpenGD77
210 wiersze
67 KiB
C
210 wiersze
67 KiB
C
![]() |
/*
|
||
|
* Copyright (C)2019 Kai Ludwig, DG4KLU
|
||
|
*
|
||
|
* This program is free software; you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU General Public License as published by
|
||
|
* the Free Software Foundation; either version 2 of the License, or
|
||
|
* (at your option) any later version.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU General Public License
|
||
|
* along with this program; if not, write to the Free Software
|
||
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||
|
*/
|
||
|
|
||
|
#include "dmr_codec/codec.h"
|
||
|
#include "functions/voicePrompts.h"
|
||
|
|
||
|
const uint8_t ambebuffer_decode_init[] = { 0xb0, 0x18, 0x00, 0x00, 0x7a, 0x15, 0x00, 0x00, 0x7a, 0x15, 0x00, 0x00, 0x60, 0x11, 0x00, 0x00, 0x53, 0x28, 0x00, 0x00, 0xa4, 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x
|
||
|
const uint8_t ambebuffer_encode_init[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x
|
||
|
const uint8_t ambebuffer_encode_ecc_init[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x00, 0x31, 0x00, 0x17, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x40, 0x18, 0x40, 0x18, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x80, 0x00, 0xec, 0xff, 0xea, 0xff, 0x14, 0x00, 0xf6, 0xff, 0xd8, 0xff, 0x00, 0x40, 0xcc, 0x0c, 0xcc, 0x0c, 0x1e, 0x05, 0x0a, 0x00, 0x14, 0x00, 0xf5, 0xff, 0xf1, 0xff, 0xf1, 0xff, 0x04, 0x00, 0x01, 0x00, 0xfa, 0xff, 0xfc, 0xff, 0xec, 0xff, 0xf1, 0xff, 0xf2, 0xff, 0xf2, 0xff, 0xfe, 0xff, 0xf9, 0xff, 0xf3, 0xff, 0xea, 0xff, 0xf2, 0xff, 0xf5, 0xff, 0xed, 0xff, 0xf4, 0xff, 0xef, 0xff, 0x06, 0x00, 0xfe, 0xff, 0xf9, 0xff, 0x0a, 0x00, 0xf3, 0xff, 0x0b, 0x00, 0x0b, 0x00, 0x06, 0x00, 0x0c, 0x00, 0x06, 0x00, 0x11, 0x00, 0x03, 0x00, 0x02, 0x00, 0x05, 0x00, 0x0b, 0x00, 0x10, 0x00, 0x11, 0x00, 0x0f, 0x00, 0x12, 0x00, 0x15, 0x00, 0x13, 0x00, 0x1d, 0x00, 0x1a, 0x00, 0x10, 0x00, 0x09, 0x00, 0x06, 0x00, 0x0b, 0x00, 0x10, 0x00, 0xfb, 0xff, 0xf2, 0xff, 0xfe, 0xff, 0xf3, 0xff, 0xfa, 0xff, 0xfb, 0xff, 0xfb, 0xff, 0x0a, 0x00, 0xfc, 0xff, 0xfd, 0xff, 0x01, 0x00, 0x07, 0x00, 0x0a, 0x00, 0x05, 0x00, 0x0b, 0x00, 0xfc, 0xff, 0xfb, 0xff, 0xff, 0xff, 0x03, 0x00, 0x02, 0x00, 0x06, 0x00, 0x0d, 0x00, 0x0b, 0x00 };
|
||
|
|
||
|
short bitbuffer_decode[49];
|
||
|
char ambe_d[49];
|
||
|
short bitbuffer_encode[72];
|
||
|
|
||
|
uint8_t ambebuffer_decode[0x7ec];
|
||
|
uint8_t ambebuffer_encode[0x2000];
|
||
|
uint8_t ambebuffer_encode_ecc[0x100];
|
||
|
|
||
|
|
||
|
void codecInitInternalBuffers(void)
|
||
|
{
|
||
|
memcpy(ambebuffer_decode, ambebuffer_decode_init, 0x7ec);
|
||
|
memcpy(ambebuffer_encode, ambebuffer_encode_init, 0x2000);
|
||
|
memcpy(ambebuffer_encode_ecc, ambebuffer_encode_ecc_init, 0x100);
|
||
|
}
|
||
|
|
||
|
void codecInit(void)
|
||
|
{
|
||
|
// Need to prevent the DMR side of the code initialising the codec and sound buffers when the voice prompts are playing
|
||
|
// This could be done in every location this function is called, but it saves space if the check is done inside the function.
|
||
|
if (voicePromptsIsPlaying())
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
codecInitInternalBuffers();
|
||
|
soundInit();
|
||
|
}
|
||
|
|
||
|
void codecDecode(uint8_t *indata_ptr, int numbBlocks)
|
||
|
{
|
||
|
int errs1;
|
||
|
int errs2;
|
||
|
|
||
|
register int r0 asm ("r0") __attribute__((unused));
|
||
|
register int r1 asm ("r1") __attribute__((unused));
|
||
|
register int r2 asm ("r2") __attribute__((unused));
|
||
|
|
||
|
for (int idx = 0; idx < numbBlocks; idx++)
|
||
|
{
|
||
|
prepare_framedata(indata_ptr, ambe_d, &errs1, &errs2);
|
||
|
indata_ptr = indata_ptr + 9;
|
||
|
|
||
|
for (int i = 0; i < 49; i++)
|
||
|
{
|
||
|
bitbuffer_decode[i] = (short)ambe_d[i];
|
||
|
}
|
||
|
soundSetupBuffer();// this just sets currentWaveBuffer but the compiler seems to optimise out the code if I try to do it in this file
|
||
|
r2 = (int)bitbuffer_decode;
|
||
|
r0 = (int)currentWaveBuffer;
|
||
|
r1 = (int)ambebuffer_decode;
|
||
|
|
||
|
asm volatile (
|
||
|
"PUSH {R4-R11}\n"
|
||
|
"SUB SP, SP, #0x10\n"
|
||
|
"STR R1, [SP, #0x08]\n"
|
||
|
"LDR R1, =0\n"
|
||
|
"STR R1, [SP, #0x04]\n"
|
||
|
"LDR R1, =0\n"
|
||
|
"STR R1, [SP, #0x00]\n"
|
||
|
"LDR R3, =0\n"
|
||
|
"LDR R1, =80\n"
|
||
|
"BL " QU(AMBE_DECODE)
|
||
|
"ADD SP, SP, #0x10\n"
|
||
|
"POP {R4-R11}"
|
||
|
);
|
||
|
|
||
|
soundStoreBuffer();
|
||
|
|
||
|
soundSetupBuffer();// this just sets currentWaveBuffer but the compiler seems to optimise out the code if I try to do it in this file
|
||
|
r2 = (int)bitbuffer_decode;
|
||
|
r0 = (int)currentWaveBuffer;
|
||
|
r1 = (int)ambebuffer_decode;
|
||
|
|
||
|
asm volatile (
|
||
|
"PUSH {R4-R11}\n"
|
||
|
"SUB SP, SP, #0x10\n"
|
||
|
"STR R1, [SP, #0x08]\n"
|
||
|
"LDR R1, =1\n"
|
||
|
"STR R1, [SP, #0x04]\n"
|
||
|
"LDR R1, =0\n"
|
||
|
"STR R1, [SP, #0x00]\n"
|
||
|
"LDR R3, =0\n"
|
||
|
"LDR R1, =80\n"
|
||
|
"BL " QU(AMBE_DECODE)
|
||
|
"ADD SP, SP, #0x10\n"
|
||
|
"POP {R4-R11}"
|
||
|
);
|
||
|
|
||
|
soundStoreBuffer();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void codecEncodeInit(uint8_t *outdata_ptr)
|
||
|
{
|
||
|
memset((uint8_t *)outdata_ptr, 0, 27);// fills with zeros
|
||
|
}
|
||
|
|
||
|
void codecEncodeBlock(uint8_t *outdata_ptr)
|
||
|
{
|
||
|
register int r0 asm ("r0") __attribute__((unused));
|
||
|
register int r1 asm ("r1") __attribute__((unused));
|
||
|
register int r2 asm ("r2") __attribute__((unused));
|
||
|
|
||
|
memset((uint8_t *)outdata_ptr, 0, 9);// fills with zeros
|
||
|
memset(bitbuffer_encode, 0, 72);// faster to call memset as it will be compiled as optimised code
|
||
|
|
||
|
|
||
|
soundRetrieveBuffer();// gets currentWaveBuffer pointer used as input r2 to the encoder
|
||
|
|
||
|
r0 = (int)bitbuffer_encode;
|
||
|
r2 = (int)currentWaveBuffer;//tmp_wavbuffer;
|
||
|
r1 = (int)ambebuffer_encode;// seems to be a hard coded (defined) memory address of 0x1FFF6B60. I'm not sure why it has to be hard coded, since its passed as a paramater (register)
|
||
|
|
||
|
asm volatile (
|
||
|
"PUSH {R4-R11}\n"
|
||
|
"SUB SP, SP, #0x14\n"
|
||
|
"STR R1, [SP, #0x0C]\n"
|
||
|
"LDR R1, =0x00002000\n"
|
||
|
"STR R1, [SP, #0x08]\n"
|
||
|
"LDR R1, =0\n"
|
||
|
"STR R1, [SP, #0x04]\n"
|
||
|
"LDR R1, =0x00001840\n"
|
||
|
"STR R1, [SP, #0x00]\n"
|
||
|
"LDR R3, =80\n"
|
||
|
"LDR R1, =0\n"
|
||
|
"BL " QU(AMBE_ENCODE)
|
||
|
"ADD SP, SP, #0x14\n"
|
||
|
"POP {R4-R11}"
|
||
|
);
|
||
|
|
||
|
soundRetrieveBuffer();// gets currentWaveBuffer pointer used as input r2 to the encoder
|
||
|
|
||
|
r0 = (int)bitbuffer_encode;
|
||
|
r2 = (int)currentWaveBuffer;//tmp_wavbuffer;
|
||
|
r1 = (int)ambebuffer_encode;
|
||
|
|
||
|
asm volatile (
|
||
|
"PUSH {R4-R11}\n"
|
||
|
"SUB SP, SP, #0x14\n"
|
||
|
"STR R1, [SP, #0x0C]\n"
|
||
|
"LDR R1, =0x00002000\n"
|
||
|
"STR R1, [SP, #0x08]\n"
|
||
|
"LDR R1, =1\n"
|
||
|
"STR R1, [SP, #0x04]\n"
|
||
|
"LDR R1, =0x00000800\n"
|
||
|
"STR R1, [SP, #0x00]\n"
|
||
|
"LDR R3, =80\n"
|
||
|
"LDR R1, =0\n"
|
||
|
"BL " QU(AMBE_ENCODE)
|
||
|
"ADD SP, SP, #0x14\n"
|
||
|
"POP {R4-R11}"
|
||
|
);
|
||
|
|
||
|
r0 = (int)bitbuffer_encode;
|
||
|
r1 = (int)ambebuffer_encode_ecc;
|
||
|
|
||
|
asm volatile (
|
||
|
"PUSH {R4-R11}\n"
|
||
|
"SUB SP, SP, #0x14\n"
|
||
|
"MOV R3, R1\n"
|
||
|
"LDR R2, =0\n"
|
||
|
"MOV R1, R0\n"
|
||
|
"BL " QU(AMBE_ENCODE_ECC)
|
||
|
"ADD SP, SP, #0x14\n"
|
||
|
"POP {R4-R11}"
|
||
|
);
|
||
|
|
||
|
for (int i = 0; i < 72; i++)
|
||
|
{
|
||
|
if (bitbuffer_encode[i] & 1)
|
||
|
{
|
||
|
outdata_ptr[i >> 3] |= 128 >> (i & 7);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void codecEncode(uint8_t *outdata_ptr, int numbBlocks)
|
||
|
{
|
||
|
for (int i = 0; i < numbBlocks; i++)
|
||
|
{
|
||
|
codecEncodeBlock(outdata_ptr);
|
||
|
outdata_ptr+=9;
|
||
|
}
|
||
|
}
|