source: roaraudio/roard/hwmixer_dstr.c @ 5961:06e7fd9e4c25

Last change on this file since 5961:06e7fd9e4c25 was 5961:06e7fd9e4c25, checked in by phi, 10 years ago

Updates of copyright and license headers

File size: 3.7 KB
Line 
1//hwmixer_dstr.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010-2014
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#ifndef ROAR_WITHOUT_DCOMP_MIXER
29
30/*
31 * This driver ignores errors on seeks:
32 * The writes ensure that if the seek back to begin of file
33 * does not work the records keep seperate and parsable.
34 * So it basically enters some kind of streaming mode.
35 */
36
37//#define TEST_HWMIXER_SUBSTREAMS
38
39int hwmixer_dstr_open(struct hwmixer_stream * stream, char * drv, char * dev, int fh, char * basename, struct roar_keyval * subnames, size_t subnamelen) {
40 struct roar_vio_calls * vio = roar_mm_malloc(sizeof(struct roar_vio_calls));
41 struct roar_vio_defaults def;
42 struct roar_stream_server * ss;
43
44 if ( vio == NULL )
45  return -1;
46
47 if ( fh == -1 ) {
48  if ( dev == NULL ) {
49   roar_mm_free(vio);
50   return -1;
51  }
52
53  if ( roar_vio_dstr_init_defaults(&def, ROAR_VIO_DEF_TYPE_NONE, O_WRONLY|O_CREAT|O_TRUNC, 0644) == -1 ) {
54   roar_mm_free(vio);
55   return -1;
56  }
57
58  if ( roar_vio_open_dstr(vio, dev, &def, 1) == -1 ) {
59   roar_mm_free(vio);
60   return -1;
61  }
62 } else {
63  if ( roar_vio_open_fh(vio, fh) == -1 ) {
64   roar_mm_free(vio);
65   return -1;
66  }
67 }
68
69 stream->baseud = vio;
70
71 roar_vio_printf(vio, "No data yet.\n");
72 _LIBROAR_IGNORE_RET(roar_vio_lseek(vio, 0, SEEK_SET));
73 roar_vio_sync(vio);
74
75 if (streams_get(stream->basestream, &ss) != -1) {
76  ROAR_STREAM(ss)->info.channels = 2;
77 } else {
78  ROAR_WARN("hwmixer_dstr_open(*): can not get object for basestream %i", stream->basestream);
79 }
80
81#ifdef TEST_HWMIXER_SUBSTREAMS
82 stream = hwmixer_substream_new(stream);
83 if ( stream == NULL ) {
84  ROAR_WARN("hwmixer_dstr_open(*): can not create substream");
85 } else {
86  if (streams_get(stream->stream, &ss) != -1) {
87   ROAR_STREAM(ss)->info.channels = 2;
88  } else {
89   ROAR_WARN("hwmixer_dstr_open(*): can not get object for stream %i", stream->stream);
90  }
91 }
92#endif
93
94 return 0;
95}
96
97int hwmixer_dstr_close(struct hwmixer_stream * stream) {
98 // are we a substream? if yes we do not clean up anything.
99 // streams_delete() will do all our work.
100 if ( stream->stream != stream->basestream )
101  return 0;
102
103 roar_vio_close(stream->baseud);
104 roar_mm_free(stream->baseud);
105 return 0;
106}
107
108int hwmixer_dstr_set_vol(struct hwmixer_stream * stream, int channels, int mode, struct roar_mixer_settings * settings) {
109 struct roar_vio_calls * vio = stream->baseud;
110 int i;
111
112 roar_vio_printf(vio, "[Stream %2i of basestream %2i]\n", stream->stream, stream->basestream);
113 roar_vio_printf(vio, "Channels: %2i\n", channels);
114 roar_vio_printf(vio, "Mode: %1i\n", mode);
115 roar_vio_printf(vio, "Scale: %5i\n", (int)settings->scale);
116 roar_vio_printf(vio, "RPG: %5i/%5i\n", (int)settings->rpg_mul, (int)settings->rpg_div);
117
118 for (i = 0; i < channels; i++) {
119  roar_vio_printf(vio, "Channel[%2i]: %5i\n", i, (int)settings->mixer[i]);
120 }
121
122 _LIBROAR_IGNORE_RET(roar_vio_lseek(vio, 0, SEEK_SET));
123 roar_vio_sync(vio);
124 return 0;
125}
126
127#endif
128
129//ll
Note: See TracBrowser for help on using the repository browser.