[2717] | 1 | //rdtcs.c: |
---|
| 2 | |
---|
| 3 | /* |
---|
| 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009 |
---|
| 5 | * |
---|
| 6 | * This file is part of roard a part of RoarAudio, |
---|
| 7 | * a cross-platform sound system for both, home and professional use. |
---|
| 8 | * See README for details. |
---|
| 9 | * |
---|
| 10 | * This file is free software; you can redistribute it and/or modify |
---|
| 11 | * it under the terms of the GNU General Public License version 3 |
---|
| 12 | * as published by the Free Software Foundation. |
---|
| 13 | * |
---|
| 14 | * RoarAudio is distributed in the hope that it will be useful, |
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 17 | * GNU General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with this software; see the file COPYING. If not, write to |
---|
| 21 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
| 22 | * |
---|
| 23 | */ |
---|
| 24 | |
---|
| 25 | #include "roard.h" |
---|
| 26 | |
---|
[2718] | 27 | #ifndef ROAR_WITHOUT_DCOMP_RDTCS |
---|
| 28 | |
---|
| 29 | int rdtcs_init (void) { |
---|
| 30 | return 0; |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | int rdtcs_free (void) { |
---|
| 34 | return 0; |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | int rdtcs_init_config (void) { |
---|
[2719] | 38 | memset(&g_rdtcs, 0, sizeof(g_rdtcs)); |
---|
| 39 | |
---|
| 40 | strncpy(g_rdtcs.rds.ps, RDTCS_RDS_PS_DEFAULT, RDTCS_RDS_PS_LEN); |
---|
| 41 | g_rdtcs.rds.ps[RDTCS_RDS_PS_LEN] = 0; |
---|
| 42 | |
---|
| 43 | g_rdtcs.rds.pty = RDTCS_RDS_PTY_DEFAULT; |
---|
| 44 | g_rdtcs.rds.pi = RDTCS_RDS_PI_DEFAULT; |
---|
| 45 | |
---|
[2718] | 46 | return 0; |
---|
| 47 | } |
---|
| 48 | |
---|
[2721] | 49 | int rdtcs_check_stream (int id) { |
---|
| 50 | return -1; |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | int rdtcs_send_stream (int id) { |
---|
[2722] | 54 | struct roar_stream * s; |
---|
| 55 | struct roar_stream_server * ss; |
---|
| 56 | |
---|
| 57 | if ( g_streams[id] == NULL ) |
---|
| 58 | return -1; |
---|
| 59 | |
---|
| 60 | ROAR_DBG("rdtcs_send_stream(id=%i) = ?", id); |
---|
| 61 | |
---|
| 62 | s = ROAR_STREAM(ss = g_streams[id]); |
---|
| 63 | |
---|
| 64 | switch (s->info.codec) { |
---|
| 65 | case ROAR_CODEC_RDS: |
---|
| 66 | return rdtcs_send_stream_rds(id, ss); |
---|
| 67 | break; |
---|
| 68 | default: |
---|
| 69 | streams_delete(id); |
---|
| 70 | return -1; |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | return 0; |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | int rdtcs_send_stream_rds (int id, struct roar_stream_server * ss) { |
---|
| 77 | struct roar_stream * s; |
---|
| 78 | |
---|
| 79 | s = ROAR_STREAM(ss); |
---|
| 80 | |
---|
| 81 | |
---|
| 82 | return rdtcs_send_stream_rds_group(id, ss); |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | int rdtcs_send_stream_rds_group (int id, struct roar_stream_server * ss) { |
---|
| 86 | char out[RDTCS_RDS_GROUP_LEN]; |
---|
| 87 | char * c; |
---|
[2724] | 88 | int block[4] = {RDTCS_RDS_BLOCK_A, RDTCS_RDS_BLOCK_B, RDTCS_RDS_BLOCK_C0, RDTCS_RDS_BLOCK_D}; |
---|
[2722] | 89 | uint16_t data[4]; |
---|
| 90 | uint16_t crc; |
---|
| 91 | register uint32_t s; |
---|
| 92 | int i, fill; |
---|
| 93 | |
---|
| 94 | // TODO: think about byte order! |
---|
| 95 | |
---|
| 96 | for (i = 0; i < 4; i++) data[i] = 0; |
---|
| 97 | |
---|
| 98 | data[0] = g_rdtcs.rds.pi; |
---|
| 99 | |
---|
| 100 | memset(out, 0, sizeof(out)); |
---|
| 101 | |
---|
| 102 | c = out; |
---|
| 103 | s = 0; |
---|
| 104 | fill = 0; |
---|
| 105 | for (i = 0; i < 4; i++) { |
---|
[2724] | 106 | // data is 16 bit long |
---|
| 107 | s |= data[i] << (fill & 0xFFFF); |
---|
[2722] | 108 | fill += 16; |
---|
| 109 | |
---|
[2724] | 110 | crc = rdtcs_rds_crc_calc(data[i], block[i]); |
---|
[2722] | 111 | |
---|
[2724] | 112 | // CRC is 10 bit long |
---|
| 113 | s |= crc << (fill & 0x03FF); |
---|
[2722] | 114 | fill += 10; |
---|
| 115 | |
---|
[2724] | 116 | // shift all complet bytes we allready have out |
---|
[2722] | 117 | while (fill >= 8) { |
---|
| 118 | *c = s & 0xFF; |
---|
| 119 | c++; |
---|
| 120 | s >>= 8; |
---|
| 121 | fill -= 8; |
---|
| 122 | } |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | return stream_vio_s_write(ss, out, RDTCS_RDS_GROUP_LEN) == RDTCS_RDS_GROUP_LEN ? 0 : -1; |
---|
| 126 | } |
---|
| 127 | |
---|
[2724] | 128 | uint16_t rdtcs_rds_crc_calc (uint16_t data, int block) { |
---|
[2722] | 129 | return 0xAAAA; |
---|
[2721] | 130 | } |
---|
| 131 | |
---|
[2718] | 132 | #endif |
---|
| 133 | |
---|
[2717] | 134 | //ll |
---|