1 | //hwmixer_dstr.c: |
---|
2 | |
---|
3 | /* |
---|
4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010-2011 |
---|
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, 51 Franklin Street, Fifth Floor, |
---|
22 | * Boston, MA 02110-1301, USA. |
---|
23 | * |
---|
24 | */ |
---|
25 | |
---|
26 | #include "roard.h" |
---|
27 | |
---|
28 | //#define TEST_HWMIXER_SUBSTREAMS |
---|
29 | |
---|
30 | int hwmixer_dstr_open(struct hwmixer_stream * stream, char * drv, char * dev, int fh, char * basename, struct roar_keyval * subnames, size_t subnamelen) { |
---|
31 | struct roar_vio_calls * vio = roar_mm_malloc(sizeof(struct roar_vio_calls)); |
---|
32 | struct roar_vio_defaults def; |
---|
33 | struct roar_stream_server * ss; |
---|
34 | |
---|
35 | if ( vio == NULL ) |
---|
36 | return -1; |
---|
37 | |
---|
38 | if ( fh == -1 ) { |
---|
39 | if ( dev == NULL ) { |
---|
40 | roar_mm_free(vio); |
---|
41 | return -1; |
---|
42 | } |
---|
43 | |
---|
44 | if ( roar_vio_dstr_init_defaults(&def, ROAR_VIO_DEF_TYPE_NONE, O_WRONLY|O_CREAT|O_TRUNC, 0644) == -1 ) { |
---|
45 | roar_mm_free(vio); |
---|
46 | return -1; |
---|
47 | } |
---|
48 | |
---|
49 | if ( roar_vio_open_dstr(vio, dev, &def, 1) == -1 ) { |
---|
50 | roar_mm_free(vio); |
---|
51 | return -1; |
---|
52 | } |
---|
53 | } else { |
---|
54 | if ( roar_vio_open_fh(vio, fh) == -1 ) { |
---|
55 | roar_mm_free(vio); |
---|
56 | return -1; |
---|
57 | } |
---|
58 | } |
---|
59 | |
---|
60 | stream->baseud = vio; |
---|
61 | |
---|
62 | roar_vio_printf(vio, "No data yet.\n"); |
---|
63 | roar_vio_lseek(vio, 0, SEEK_SET); |
---|
64 | roar_vio_sync(vio); |
---|
65 | |
---|
66 | if (streams_get(stream->basestream, &ss) != -1) { |
---|
67 | ROAR_STREAM(ss)->info.channels = 2; |
---|
68 | } else { |
---|
69 | ROAR_WARN("hwmixer_dstr_open(*): can not get object for basestream %i", stream->basestream); |
---|
70 | } |
---|
71 | |
---|
72 | #ifdef TEST_HWMIXER_SUBSTREAMS |
---|
73 | stream = hwmixer_substream_new(stream); |
---|
74 | if ( stream == NULL ) { |
---|
75 | ROAR_WARN("hwmixer_dstr_open(*): can not create substream"); |
---|
76 | } else { |
---|
77 | if (streams_get(stream->stream, &ss) != -1) { |
---|
78 | ROAR_STREAM(ss)->info.channels = 2; |
---|
79 | } else { |
---|
80 | ROAR_WARN("hwmixer_dstr_open(*): can not get object for stream %i", stream->stream); |
---|
81 | } |
---|
82 | } |
---|
83 | #endif |
---|
84 | |
---|
85 | return 0; |
---|
86 | } |
---|
87 | |
---|
88 | int hwmixer_dstr_close(struct hwmixer_stream * stream) { |
---|
89 | // are we a substream? if yes we do not clean up anything. |
---|
90 | // streams_delete() will do all our work. |
---|
91 | if ( stream->stream != stream->basestream ) |
---|
92 | return 0; |
---|
93 | |
---|
94 | roar_vio_close(stream->baseud); |
---|
95 | roar_mm_free(stream->baseud); |
---|
96 | return 0; |
---|
97 | } |
---|
98 | |
---|
99 | int hwmixer_dstr_set_vol(struct hwmixer_stream * stream, int channels, int mode, struct roar_mixer_settings * settings) { |
---|
100 | struct roar_vio_calls * vio = stream->baseud; |
---|
101 | int i; |
---|
102 | |
---|
103 | roar_vio_printf(vio, "[Stream %2i of basestream %2i]\n", stream->stream, stream->basestream); |
---|
104 | roar_vio_printf(vio, "Channels: %2i\n", channels); |
---|
105 | roar_vio_printf(vio, "Mode: %1i\n", mode); |
---|
106 | roar_vio_printf(vio, "Scale: %5i\n", (int)settings->scale); |
---|
107 | roar_vio_printf(vio, "RPG: %5i/%5i\n", (int)settings->rpg_mul, (int)settings->rpg_div); |
---|
108 | |
---|
109 | for (i = 0; i < channels; i++) { |
---|
110 | roar_vio_printf(vio, "Channel[%2i]: %5i\n", i, (int)settings->mixer[i]); |
---|
111 | } |
---|
112 | |
---|
113 | roar_vio_lseek(vio, 0, SEEK_SET); |
---|
114 | roar_vio_sync(vio); |
---|
115 | return 0; |
---|
116 | } |
---|
117 | |
---|
118 | //ll |
---|