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 | |
---|
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) { |
---|
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 | |
---|
46 | return 0; |
---|
47 | } |
---|
48 | |
---|
49 | int rdtcs_check_stream (int id) { |
---|
50 | return -1; |
---|
51 | } |
---|
52 | |
---|
53 | int rdtcs_send_stream (int id) { |
---|
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; |
---|
88 | uint16_t data[4]; |
---|
89 | uint16_t crc; |
---|
90 | register uint32_t s; |
---|
91 | int i, fill; |
---|
92 | |
---|
93 | // TODO: think about byte order! |
---|
94 | |
---|
95 | for (i = 0; i < 4; i++) data[i] = 0; |
---|
96 | |
---|
97 | data[0] = g_rdtcs.rds.pi; |
---|
98 | |
---|
99 | memset(out, 0, sizeof(out)); |
---|
100 | |
---|
101 | c = out; |
---|
102 | s = 0; |
---|
103 | fill = 0; |
---|
104 | for (i = 0; i < 4; i++) { |
---|
105 | s |= data[i] << fill; |
---|
106 | fill += 16; |
---|
107 | |
---|
108 | crc = rdtcs_rds_crc_calc(data[i]); |
---|
109 | |
---|
110 | s |= crc << fill; |
---|
111 | fill += 10; |
---|
112 | |
---|
113 | while (fill >= 8) { |
---|
114 | *c = s & 0xFF; |
---|
115 | c++; |
---|
116 | s >>= 8; |
---|
117 | fill -= 8; |
---|
118 | } |
---|
119 | } |
---|
120 | |
---|
121 | return stream_vio_s_write(ss, out, RDTCS_RDS_GROUP_LEN) == RDTCS_RDS_GROUP_LEN ? 0 : -1; |
---|
122 | } |
---|
123 | |
---|
124 | uint16_t rdtcs_rds_crc_calc (uint16_t data) { |
---|
125 | return 0xAAAA; |
---|
126 | } |
---|
127 | |
---|
128 | #endif |
---|
129 | |
---|
130 | //ll |
---|